Main Content

reduceByKeyLocally

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

Merge the values for each key using an associative reduce function, but return the results immediately to the driver

Syntax

result = reduceByKeyLocally(obj,func)

Description

result = reduceByKeyLocally(obj,func) merges the values for each key using an associative reduce function func, and returns the results immediately to the driver.

Input Arguments

expand all

An input RDD, specified as a RDD object.

Associative function to be applied to the elements of the input RDD, specified as a function handle.

Data Types: function_handle

Output Arguments

expand all

A list of key-value pairs, returned in a containers.Map 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);

%% reduceByKeyLocally
x = sc.parallelize({ {'a',10}, {'b',20}, {'a',30}, {'b',30 } }, 2);
m = x.reduceByKeyLocally(@(x,y)(x+y)); 

Version History

Introduced in R2016b