Difference between RDD as val and var

0 votes

RDD is considered immutable. I tried to create an RDD with val and var like given below. I can see I was able to change RDD definition created using var. If it"s immutable why was I able to use var to create an RDD?

scala> var df = sc.textFile("/user/saifu/problem5/text")
df: org.apache.spark.rdd.RDD[String] = /user/saifu/problem5/text MapPartitionsRDD[13] at textFile at :27

scala> val db = sc.textFile("/user/saifu/problem5/text")
db: org.apache.spark.rdd.RDD[String] = /user/saifu/problem5/text MapPartitionsRDD[15] at textFile at :27

scala> df = sc.textFile("/user/sarfu/problem5/text-uncompress")
df: org.apache.spark.rdd.RDD[String] = /user/sarfu/problem5/text-uncompress MapPartitionsRDD[17] at textFile at :29
May 23 in Apache Spark by SHeen
36 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Variable declaration can be done in two ways

1. val --> immutable variable

Refer to the screenshot below:

image

2. var --> mutable variable

Refer to the screenshot below:

image

I hope this helps.

answered May 23 by Arun

Related Questions In Apache Spark

0 votes
1 answer

Difference between createOrReplaceTempView and registerTempTable

createOrReplaceTempView() creates/replaces a local temp view with the dataframe provided. Lifetime of this ...READ MORE

answered Apr 25, 2018 in Apache Spark by kurt_cobain
• 9,240 points
1,023 views
0 votes
1 answer

What's the difference between 'filter' and 'where' in Spark SQL?

Both 'filter' and 'where' in Spark SQL ...READ MORE

answered May 23, 2018 in Apache Spark by nitinrawat895
• 9,670 points
3,644 views
0 votes
1 answer

What is the difference between Apache Spark SQLContext vs HiveContext?

Spark 2.0+ Spark 2.0 provides native window functions ...READ MORE

answered May 25, 2018 in Apache Spark by nitinrawat895
• 9,670 points
1,583 views
0 votes
1 answer

How to save and retrieve the Spark RDD from HDFS?

You can save the RDD using saveAsObjectFile and saveAsTextFile method. ...READ MORE

answered May 29, 2018 in Apache Spark by Shubham
• 12,890 points
1,274 views
0 votes
0 answers
0 votes
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 9,670 points
1,882 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 9,670 points
168 views
0 votes
10 answers

hadoop fs -put command?

copy command can be used to copy files ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Sujay
9,411 views
+1 vote
3 answers

What is the difference between rdd and dataframes in Apache Spark ?

Comparison between Spark RDD vs DataFrame 1. Release ...READ MORE

answered Aug 27, 2018 in Apache Spark by shams
• 3,580 points
9,087 views
0 votes
2 answers

map() and flatmap()

map(): Return a new distributed dataset formed by ...READ MORE

answered Jul 3, 2018 in Apache Spark by zombie
• 3,690 points
44 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.