Main Content


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

Create tuples of the elements in an RDD by applying a function


result = keyBy(obj,func)


result = keyBy(obj,func) takes a function func that returns a key for any given element in obj. The keyBy method applies this function to all the elements in obj and returns an output RDD result of key-value pairs.

Input Arguments

expand all

An input RDD, specified as a RDD object.

Function to be applied, specified as a function handle.

Data Types: function_handle

Output Arguments

expand all

A pipelined RDD containing tuples of the elements in the input RDD, 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);

%% keyBy
x = sc.parallelize({1,2,3});
c = x.keyBy(@(x)(x*x)).collect(); % {{1,1},{4,2},{9,3}}

Version History

Introduced in R2016b

See Also