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, 2019 in Apache Spark by SHeen
1,322 views

1 answer to this question.

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, 2019 by Arun

Related Questions In Apache Spark

0 votes
2 answers

Difference between createOrReplaceTempView and registerTempTable

I am pretty sure createOrReplaceTempView just replaced ...READ MORE

answered Sep 18, 2020 in Apache Spark by Nathan Mott
10,837 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
• 11,380 points
27,538 views
0 votes
1 answer

What is the difference between persist() and cache() in apache spark?

Hi, persist () allows the user to specify ...READ MORE

answered Jul 3, 2019 in Apache Spark by Gitika
• 65,890 points
2,846 views
0 votes
1 answer

Difference between cogroup and full outer join in spark

Please go through the below explanation : Full ...READ MORE

answered Jul 14, 2019 in Apache Spark by Kiran
8,029 views
+1 vote
2 answers
+1 vote
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
• 11,380 points
9,088 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
• 11,380 points
1,636 views
+2 votes
11 answers

hadoop fs -put command?

Hi, You can create one directory in HDFS ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by nitinrawat895
• 11,380 points
82,805 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 28, 2018 in Apache Spark by shams
• 3,660 points
40,176 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP