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
227 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
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,290 points
3,008 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
• 10,840 points
9,620 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
• 25,460 points
763 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 13, 2019 in Apache Spark by Kiran
1,846 views
+1 vote
1 answer
+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
• 10,840 points
3,937 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
• 10,840 points
544 views
+1 vote
11 answers

hadoop fs -put command?

put syntax: put <localSrc> <dest> copy syntax: copyFr ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Aditya
21,008 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
19,743 views
0 votes
1 answer