Main Content

flatMapValues

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

Pass each value in the key-value pair RDD through a flatMap method without changing the keys

Syntax

result = flatMapValues(obj,func)

Description

result = flatMapValues(obj,func) passes each value in a key-value pair RDD obj through the flatMap method without changing the keys. func represents the function to be applied by the flatMap method.

Input Arguments

expand all

An input RDD on which a transformation function is applied, specified as a RDD object.

Function to be applied to each element in the input RDD, specified as a function handle.

Example:

Data Types: function_handle

Output Arguments

expand all

An output pipelined 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);

%% flatMapValues
inRDD = sc.parallelize({ {'AA', {1,2,3}}, {'BB',3}, {'CC', {'cc',4}} });
f = @(x)(x);
out = inRDD.flatMapValues(f).collect();
% out : {{'AA',1},{'AA',2},{'AA',3},{'BB',3},{'CC','cc'},{'CC',4}}
Introduced in R2016b