Skip to content

3. Distinct User Actions

Difficulty: Easy · Topics: Filtering & Selection

The logs table records every action a user performs, so the same (user_id, action) pair can appear many times.

Return each distinct (user_id, action) pair exactly once.

Row order does not matter; column names must match. Your code is graded on 3 test cases, including hidden edge cases.

Sample data

logs

user_idactionts
1login2024-01-01 09:00
1login2024-01-02 09:00
1view2024-01-02 09:05
2login2024-01-01 10:00
2login2024-01-03 10:00
2purchase2024-01-03 10:30

Expected output

user_idaction
1login
1view
2login
2purchase

Hints

Hint 1Select the two columns first, then call .distinct().
Hint 2dropDuplicates(["user_id", "action"]) does the same without a separate select, but keeps all columns.

Learn the concepts

PySpark functions you'll practise

Related problems

Browse

Topics: Window Functions · Joins · Aggregations · Pivot, Unpivot & Rollup · Arrays · Null Handling · Conditional Logic · Dates · Filtering & Selection · Strings · Data Lake · Lakehouse · Streaming · Data Prep for AI · Spark Performance

Difficulty: Easy · Medium · Hard · Learn · All problems · dbt practice