शुरू करेंमुफ़्त में शुरू करें

SortByKey और Collect

अक्सर pair RDD को key के आधार पर sort करना उपयोगी होता है (जैसे word count, जिसे आप इस अध्याय में आगे देखेंगे). इस अभ्यास में, आप पिछले अभ्यास में बनाए गए pair RDD Rdd_Reduced को descending order में sort करेंगे और अंतिम आउटपुट प्रिंट करेंगे.

ध्यान रखें, आपके वर्कस्पेस में SparkContext sc और Rdd_Reduced पहले से उपलब्ध हैं.

यह अभ्यास पाठ्यक्रम का हिस्सा है

PySpark के साथ Big Data Fundamentals

पाठ्यक्रम देखें

अभ्यास निर्देश

  • Rdd_Reduced RDD को key के आधार पर descending order में sort करें.
  • कंटेंट को collect करें और आउटपुट प्रिंट करने के लिए iterate करें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Sort the reduced RDD with the key by descending order
Rdd_Reduced_Sort = Rdd_Reduced.____(ascending=False)

# Iterate over the result and retrieve all the elements of the RDD
for num in Rdd_Reduced_Sort.____():
  print("Key {} has {} Counts".format(____, num[1]))
कोड संपादित करें और चलाएँ