Main Content

flatMap

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

Return a new RDD by first applying a function to all elements of an existing RDD, and then flattening the results

Syntax

result = flatMap(obj,func,varargin)

Description

result = flatMap(obj,func,varargin) returns a new RDD result by first applying a function func to all elements of obj, and then flattening the results.

Input Arguments

expand all

An input RDD on which a 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

A variable-length input argument list representing inputs to the function that is being applied.

Output Arguments

expand all

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

%% flatMap
inRDD = sc.parallelize({'A','B'});
flatRDD = inRDD.flatMap(@(x)({x,1}));
viewRes = flatRDD.collect()

Version History

Introduced in R2016b