Main Content


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

Pass each value in a key-value pair RDD through a map function without modifying the keys


result = mapValues(obj,func)


result = mapValues(obj,func) passes each value in a key-value pair RDD obj through a map function func without modifying the keys.

Input Arguments

expand all

An input RDD, specified as a RDD object.

Function to be applied to each element, specified as a function handle.

Data Types: function_handle

Output Arguments

expand all

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

%% mapValues
x = sc.parallelize({'A','B','A'});

% reduce by key the above keys and square each of the values, 
% so {'A',1} -> {'A',1*1}, {'B', 2} -> {'B', 2*2}

y ={x,1})).reduceByKey(@(x,y)(x+y)).mapValues(@(x)(x*x))
z = y.collect() % {{'A',4},{'B',1}}
Introduced in R2016b