Main Content


Class: matlab.compiler.mlspark.RDD
Package: matlab.compiler.mlspark

Sort RDD consisting of key-value pairs by key


result = sortByKey(obj,numPartitions)


result = sortByKey(obj,numPartitions) sorts a key-value obj by key. numPartitions specifies the number of partitions to create in the resulting RDD.

Input Arguments

expand all

An input RDD, specified as a RDD object.

Number of partitions to create, specified as a scalar value.

Data Types: double

Output Arguments

expand all

A pipelined RDD containing elements sorted by key, returned as a RDD object.


expand all

%% Connect to Spark
sparkProp = containers.Map({'spark.executor.cores'}, {'1'});
conf = matlab.compiler.mlspark.SparkConf('AppName','myApp', ...
sc = matlab.compiler.mlspark.SparkContext(conf);

%% sortByKey
x = sc.parallelize({ {'a',1}, {'d',3}, {'f', 3} , {'b', 2}, {'e', 9}}, 3);
z = x.sortByKey();
viewRes = z.collect() % {{'a',1},{'b',2},{'d',3},{'e',9},{'f',3}}
Introduced in R2016b