Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL and PySpark Basics
00:00
5 left

SQL and PySpark Basics

HardSQL · PostgreSQL

Problem

Explain how you would use SQL and PySpark to transform raw data into an analysis-ready dataset.

Use the supplied raw event and customer tables. Prepare valid, deduplicated customer activity metrics, excluding inactive customers, malformed contact values, unsupported event types, and unmatched customer records. The SQL result should represent the type of analysis-ready output you would also produce with PySpark.

Output

  1. One row per active customer and activity date
  2. Columns: customer_id, customer_name, activity_date, total_events, transaction_events, net_revenue
  3. Include only dates with valid events, ordered by customer_id, then activity_date

Schema

raw_events
ColumnTypeDescription
event_idINTBusiness identifier for an event, which may be duplicated across ingestions
customer_idINTCustomer associated with the event
emailVARCHAR(255)Raw customer email value
event_typeVARCHAR(30)Raw event category
event_timestampTIMESTAMPTime when the event occurred
amountNUMERIC(12,2)Event amount
ingested_atTIMESTAMPTime when the record was ingested
source_systemVARCHAR(40)System that supplied the raw record
customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(120)Customer display name
is_activeBOOLEANWhether the customer is currently active
segmentVARCHAR(40)Customer segment
Tablesraw_eventscustomers
Interviewer

Your question is SQL and PySpark Basics. Start with the requirements and the two tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.