Scala: when to use x(2) and x._2?

0 votes
Could you please explain when to use x(2) and x._2? As functionality is the same for both, but sometimes it fails one or other.
Jul 22 in Apache Spark by Esha
62 views

1 answer to this question.

0 votes

image

In the above statement, x(2) is specifying an array and hence it cannot be compared with a string. It represents the second element of the rdd and if you didn't specify the second element, how can it be compared. If you still want to execute this statement then you will have to use split function.

The below statement is the same as the above statement after using split function. x._2 represents the value of the second element of the rdd.

image

answered Jul 22 by Yogi

Related Questions In Apache Spark

0 votes
1 answer

When not to use foreachPartition and mapPartition?

With mapPartion() or foreachPartition(), you can only ...READ MORE

answered Apr 30, 2018 in Apache Spark by Data_Nerd
• 2,360 points
2,521 views
0 votes
0 answers
0 votes
1 answer

How to use yield keyword in scala and why it is used instead of println?

Hi, The yield keyword is used because the ...READ MORE

answered Jul 5 in Apache Spark by Gitika
• 25,340 points
73 views
0 votes
1 answer
0 votes
1 answer
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
• 10,710 points
3,343 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,710 points
399 views
0 votes
10 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
16,553 views
0 votes
1 answer

How can we optimize and minimize the memory when work with scala use case?

Hi, There is a term in Scala that is ...READ MORE

answered Jul 5 in Apache Spark by Gitika
• 25,340 points
46 views
0 votes
1 answer

How to use Scala anonymous functions and why do we use it?

Hi, Anonymous functions in Scala is the lightweight ...READ MORE

answered Jul 26 in Apache Spark by Gitika
• 25,340 points
70 views