Read ORC Revenue by Payment Method

Medium
File I/O
ORC
Aggregation

Read ORC Revenue by Payment Method

The file datasets/orc/orders.orc holds one row per order in the ORC format. Which payment method brings in the most money?

What to do

  1. Read the ORC file from disk. Its local path is handed to you as paths['orders'].
  2. Keep only the orders with order_status == 'Completed'.
  3. Group the rows by payment_method and collect the number of orders and the total total_amount (rounded to two decimals).
  4. Sort by revenue descending, then by payment_method ascending.
  5. Return exactly these columns: payment_method, order_count, revenue.

Signature

File questions receive the path as a third argument:

from pyspark.sql import functions as F

def solve(spark, dfs, paths):
    orders = spark.read.orc(paths['orders'])
    # TODO: filter, aggregate and sort
    return orders

The same data is also preloaded as dfs['orders'] if you prefer to skip the file read.

This question runs in your browser - no sign-in needed. Press Run for the sample data and Submit for the hidden data.

Browser Engine: Evaluates PySpark DataFrame & SQL logic locally in Pyodide WebAssembly.

Input files

1 File
Loaded automatically

These files are loaded into this browser when you run. Their paths are handed to your code as the third argument: solve(spark, dfs, paths). Read one with spark.read.csv(paths['users'], header=True), or skip the read and use dfs['users'].

paths[orders]
orc
600 rows
datasets/orc/orders.orc
order_id(int)
user_id(int)
order_date(timestamp)
total_amount(double)
shipping_fee(double)
payment_method(string)
order_status(string)

Return these columns

payment_method(string)
order_count(bigint)
revenue(double)

Column names and order must match. Sort order is specified in the question.

Browser engine
Local files
Loading Python editor…
Click Run to try the sample cases, or Submit to check the hidden cases. First run caches the browser Python engine (~8–15s once); all code stays on your device.