Main Content

map

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

Return a new RDD by applying a function to each element of an input RDD

Syntax

result = map(obj,func,varargin)

Description

result = map(obj,func,varargin) returns a new RDD result by first applying a function func to all elements of obj. varargin represents a variable-length input argument list for the inputs to the function being applied.

Input Arguments

expand all

An input RDD, specified as a RDD object.

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

Data Types: function_handle

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

Output Arguments

expand all

A pipelined RDD containing mapped elements of the input 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);

%% map
inputRDD = sc.parallelize({'A','B','C','A','B'},2);
redRDD= inputRDD.map(@(x)({x,1})).collect();

Version History

Introduced in R2016b