Main Content

keyBy

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

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

Syntax

result = keyBy(obj,func)

Description

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.

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);

%% 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

|