Main Content

sortByKey

Class: matlab.compiler.mlspark.RDD
Namespace: matlab.compiler.mlspark

Sort RDD consisting of key-value pairs by key

Syntax

result = sortByKey(obj,numPartitions)

Description

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.

Examples

expand all

%% Connect to Spark
sparkProp = containers.Map({'spark.executor.cores'}, {'1'});
conf = matlab.compiler.mlspark.SparkConf('AppName','myApp', ...
                        'Master','local[1]','SparkProperties',sparkProp);
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}}

Version History

Introduced in R2016b