Main Content


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

Group the values for each key in the RDD into a single sequence


result = groupByKey(obj,numPartitions)


result = groupByKey(obj,numPartitions) groups the values for each key in obj into a single sequence. numPartitions specifies the number of partitions to create in the resulting RDD.

Input Arguments

expand all

An input RDD to group, 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 of the input RDD grouped 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);

%% groupByKey
inRDD = sc.parallelize({{'a',1},{'b',2}, {'a','3'}, {'b',4}});
outRDD = inRDD.groupByKey().collect(); % {{'a',{1,'3'}},{'b',{2,4}}}'

Version History

Introduced in R2016b