Main Content


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

Merge the values for each key using an associative reduce function


result = reduceByKey(obj,func,numPartitions)


result = reduceByKey(obj,func,numPartitions) merges the values for each key in obj using an associative reduce function func. numPartitions specifies the number of partitions to create in the resulting RDD.

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

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

Data Types: double

Output Arguments

expand all

A pipelined RDD containing values reduced 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);

%% reduceByKey
inputRDD = sc.parallelize({'A','B','C','A','B'},2);

Version History

Introduced in R2016b