Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What needs to be added to the code to return a new RDD with all keys where the absolute difference between their keys and values

What needs to be added to the code to return a new RDD with all keys where the absolute difference between their keys and values is greater than 2?
rdd = sc.parallelize([(1,2),(2,4),(3,6),(4,1)])
# The results need to be a list of keys. In this case result =[3,4]
A.
rdd1= rdd.map(lambda x: (x, abs(x[0]- x[1]))).filter(lambda x: x[1]>2).map(lambda x: x[0])
B.
rdd1= rdd.map(lambda x: (x[0]- x[1], x)).filter(lambda x: x[0]>2).map(lambda x: x[1])
C.
rdd1= rdd.flatMap(lambda x: [(x[0], i) for i in x[1]]).filter(lambda x: abs(x[0]- x[1])>2).map(lambda x: (x[0],[x[1]])).reduceByKey(lambda x, y: x + y).flatMap(lambda x: [(x[0], i) for i in x[1]])
D.
rdd1= rdd.map(lambda x: (x, x[0]- x[1])).filter(lambda x: x[1]>2).map(lambda x: x[0])

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 19th International Conference Dexa 2008 Turin Italy September 2008 Proceedings Lncs 5181

Authors: Sourav S. Bhowmick ,Josef Kung ,Roland Wagner

2008th Edition

3540856536, 978-3540856535

More Books

Students also viewed these Databases questions

Question

Factors Affecting Conflict

Answered: 1 week ago

Question

Describe the factors that lead to productive conflict

Answered: 1 week ago

Question

Understanding Conflict Conflict Triggers

Answered: 1 week ago