Main Content

saveAsKeyValueDatastore

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

Save key-value RDD as a binary file that can be read back using the datastore function

Syntax

saveAsKeyValueDatastore(obj,path)

Description

saveAsKeyValueDatastore(obj,path) saves a key-value input RDD obj as a binary file that can be read back using the datastore function.

Input Arguments

expand all

An input RDD, specified as a RDD object.

Directory location where binary file must be saved, specified as a character vector enclosed in ''.

Data Types: char

Examples

expand all

Save a key-value RDD as a binary file that can be read back using the datastore function.

%% 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);

%% saveAsKeyValueDatastore

% May require setting HADOOP_PREFIX or HADOOP_HOME environment variables to a
% valid Hadoop installation folder even if running locally.
% For example:
% setenv('HADOOP_PREFIX','/share/hadoop/hadoop-2.5.2')

inRDD = sc.parallelize({1,2,3,4,5});
redRDD= inputRDD.map(@(x)({x,1})).reduceByKey(@(x,y)(x+y))
% Store RDD in a key-value binary file that can be read back into MATLAB using datastore
redRdd.saveAsKeyValueDatastore('myKVdir')

Version History

Introduced in R2016b