LoslegenKostenlos loslegen

Unique 5-tuples in sorted order

A previous lesson taught an operation that eliminates duplicates, fetching unique records. In a previous exercise you obtained common 5-tuples. We will combine these two capabilities to find the unique 5-tuples, sorted alphabetically in descending order.

The table text contains the first four chapters of the Sherlock Holmes text. It has the following columns: word, id, and part.

Diese Übung ist Teil des Kurses

Introduction to Spark SQL in Python

Kurs anzeigen

Anleitung zur Übung

  • Retrieve the last ten unique 5-tuples sorted alphabetically in descending order.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Unique 5-tuples sorted in descending order
query = """
SELECT ____ w1, w2, w3, w4, w5 FROM (
   SELECT word AS w1,
   ____(word,____) OVER(PARTITION BY ____ ORDER BY ____ ) AS w2,
   ____(word,____) OVER(PARTITION BY ____ ORDER BY ____ ) AS w3,
   ____(word,____) OVER(PARTITION BY ____ ORDER BY ____ ) AS w4,
   ____(word,____) OVER(PARTITION BY ____ ORDER BY ____ ) AS w5
   FROM text
)
ORDER BY w1 DESC, w2 DESC, ____ DESC, w4 ____, ____ ____ 
LIMIT 10
"""
df = spark.sql(query)
df.show()
Code bearbeiten und ausführen