Main Content

saveAsTextFile

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

Save RDD as a text file

Syntax

saveAsTextFile(obj,path)

Description

saveAsTextFile(obj,path) saves obj as a text file in a location specified by path.

Input Arguments

expand all

An input RDD, specified as a RDD object.

Directory location in which to save the text file, specified as a character vector enclosed in ''.

Data Types: char

Examples

expand all

Save an RDD as a text file by converting each RDD element to its string representation and storing it as a line of text.

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

%% saveAsTextFile 

% 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','/mathworks/AH/hub/apps_PCT/LS_Hadoop_hadoop01glnxa64/hadoop-2.5.2')

inRDD = sc.parallelize({1,2,3,4,5});
inRDD.saveAsTextFile('myFile.txt'); 
Introduced in R2016b