Implement Election Report and Banking Pipeline
Point72Data Engineer · Online AssessmentLast updated
This multipart question evaluates data engineering competencies including SQL report design for complex aggregation and ranking, plus PySpark-based ETL and transaction-level analytics.
You are given two independent data engineering coding tasks.
Task 1: SQL Election Exit Poll by State Report
An election analytics team needs a report showing, for each candidate, the top three vote totals by state and the states where those totals occurred.
Tables
candidates
| Column | Type | Description |
|---|---|---|
id | SMALLINT | Candidate ID |
first_name | VARCHAR(64) | Candidate first name |
last_name | VARCHAR(64) | Candidate last name |
results
| Column | Type | Description |
|---|---|---|
candidate_id | SMALLINT | Candidate ID |
state | VARCHAR(19) | U.S. state where a vote was recorded |
Each row in results represents one vote for a candidate in a state.
Output
Return one row per candidate with the following columns:
| Column | Description |
|---|---|
candidate_name | Candidate first and last name concatenated with a single space. |
1st_place | State names and vote totals for the highest vote count. |
2nd_place | State names and vote totals for the second-highest distinct vote count. |
3rd_place | State names and vote totals for the third-highest distinct vote count. |
Each place column should contain one or more values formatted as:
State Name (votes)
If multiple states have the same vote count for the same place, sort those states alphabetically and join them with , .
For example:
Alabama (23), New York (23)
The top three places are based on distinct vote totals, not on individual states. For example, if a candidate has state vote counts 3, 3, 2, 1, then the first place contains both states with 3, the second place contains the state with 2, and the third place contains the state with 1.
Sample Data
candidates
| id | first_name | last_name |
|---|---|---|
| 1 | Davide | Kentish |
| 2 | Thorstein | Bridge |
results
| candidate_id | state |
|---|---|
| 1 | Alabama |
| 1 | Alabama |
| 1 | California |
| 1 | California |
| 1 | California |
| 1 | California |
| 1 | California |
| 1 | Texas |
| 1 | Texas |
| 1 | Texas |
| 2 | Alabama |
| 2 | California |
| 2 | California |
| 2 | California |
| 2 | New York |
| 2 | New York |
| 2 | Texas |
| 2 | Texas |
| 2 | Texas |
Expected Output
| candidate_name | 1st_place | 2nd_place | 3rd_place |
|---|---|---|---|
| Davide Kentish | California (5) | Texas (3) | Alabama (2) |
| Thorstein Bridge | California (3), Texas (3) | New York (2) | Alabama (1) |
Write a SQL query that produces this report.
Task 2: PySpark Banking Data Mining
Implement a PySpark job that reads account and transaction CSV files, filters valid transactions, and computes account-level transaction statistics.
Input Files
accounts.csv
One row per account.
| Column | Description |
|---|---|
accountNumber | Account identifier |
balance | Account balance |
transactions.csv
One row per transfer transaction.
| Column | Description |
|---|---|
fromAccountNumber | Source account number |
toAccountNumber | Destination account number |
transferAmount | Amount transferred |
Rules
A transaction is valid if all of the following are true:
fromAccountNumberexists inaccounts.csv.toAccountNumberexists inaccounts.csv.transferAmountis less than or equal to thebalanceof the source account.
Methods to Implement
You are given a partially completed class main.job.pipeline.PySparkJob. Implement the following methods:
class PySparkJob:
def init_spark_session(self) -> SparkSession:
"""Create and return a SparkSession with master 'local' and app name 'Banking Data Mining'."""
pass
def extract_valid_transactions(self, accounts: DataFrame, transactions: DataFrame) -> DataFrame:
"""Return only valid transactions according to the validation rules above."""
pass
def distinct_transactions(self, transactions: DataFrame) -> int:
"""Return the number of distinct source accounts, based on fromAccountNumber."""
pass
def transactions_per_account(self, transactions: DataFrame) -> dict:
"""Return the top 10 fromAccountNumber values by transaction count as a dictionary."""
pass
The helper method read_csv(file_path) reads CSV files with headers. Unit tests are provided and must pass.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.