To optimize warehouse query costs, you must write a pipeline that reads transactional CSV logs, filters out negative amount lines, and saves the cleaned logs as columnar Parquet files.
The processing pipeline will ingest the following local mock file structures (e.g. simulated as `dataset.csv`):
| txn_id | account_id | amount |
|---|---|---|
| 3001 | 1001 | 150.0 |
| 3002 | 1002 | -50.0 |
| 3003 | 1003 | 300.0 |
| 3004 | 1004 | 0.0 |
| 3005 | 1005 | 450.0 |
txn_id,account_id,amount 3001,1001,150.0 3002,1002,-50.0 3003,1003,300.0 3004,1004,0.0 3005,1005,450.0
Copy this starter template to write the data transformation logic:
# starter.py - Convert CSV to Parquet
from pyspark.sql import SparkSession
from pyspark.sql.functions import col
def process_formats():
spark = SparkSession.builder.appName("FormatConversion").getOrCreate()
# TODO: Read dataset.csv, filter amounts > 0, write parquet
pass
if __name__ == "__main__":
process_formats()amount <= 0 to isolate valid transactions.
df.write.mode("overwrite").parquet("path") which automatically writes files using columnar partitioning.
spark.read.parquet() to verify it matches.