Join in RDD using keys

0 votes
Hi Team,

How can I join two rdd without converting into dataframe?

rdd_x=(k1, V_x)
rdd_y=(k1, V_y)

Result should be like this: (k1(V_x, V_y)
Aug 2, 2019 in Apache Spark by Jishan
8,330 views

1 answer to this question.

0 votes

Suppose you have two dataset results( id, result) and student(name, id). Now, you can join the RDD by using the below commands in Spark on the basis of the common key id.​

case class results (roll_id: Int, result: String)

case class students (name: String, roll_id: Int)

val a = sc.textFile("file:///home/edureka/Desktop/all-files/datsets/f1").map(_.split("\t" ))  // mention complete path for input dataset

val b = sc.textFile("file:///home/edureka/Desktop/all-files/datsets/f2").map(_.split("\t"))


val class_a = a.map( z => (z(0).toInt , results(z(0).toInt , z(1))))

val class_b = b.map( z => (z(1).toInt , students (z(0), z(1).toInt)))


val v_join = class_a.join(class_b) 

v_join.foreach(println)

​
answered Aug 2, 2019 by Trisha

Related Questions In Apache Spark

0 votes
1 answer

Which query to use for better performance, join in SQL or using Dataset API?

DataFrames and SparkSQL performed almost about the ...READ MORE

answered Apr 19, 2018 in Apache Spark by kurt_cobain
• 9,350 points
1,855 views
0 votes
1 answer

How to create paired RDD using subString method in Spark?

Hi, If you have a file with id ...READ MORE

answered Aug 2, 2019 in Apache Spark by Gitika
• 65,770 points
2,726 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
11,074 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
2,572 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
109,061 views
+1 vote
8 answers

How to print the contents of RDD in Apache Spark?

Save it to a text file: line.saveAsTextFile("alicia.txt") Print contains ...READ MORE

answered Dec 10, 2018 in Apache Spark by Akshay
61,863 views
0 votes
1 answer

How is RDD in Spark different from Distributed Storage Management? Can anyone help me with this ?

Some of the key differences between an RDD and ...READ MORE

answered Jul 26, 2018 in Apache Spark by zombie
• 3,790 points
1,563 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP