Skip to content

H2ODB — Sum and Mean by Passenger Count

H2ODB benchmark · all H2ODB queries

SUM and AVG of fare_amount GROUP BY passenger_count

Representative SQL

Rendered for DataFusion with default parameters.

SELECT
passenger_count,
SUM(fare_amount) AS sum_fare_amount,
AVG(fare_amount) AS mean_fare_amount
FROM trips
GROUP BY
passenger_count
ORDER BY
passenger_count

Representative DataFrame

Expression family (Polars, PySpark, DataFusion), default parameters.

def q4_expression_impl(ctx: DataFrameContext) -> Any:
trips = ctx.get_table("trips")
col = ctx.col
return (
trips.group_by("passenger_count")
.agg(
col("fare_amount").sum().alias("sum_fare_amount"),
col("fare_amount").mean().alias("mean_fare_amount"),
)
.sort("passenger_count")
)

Get the exact query for your run

The blocks above are representative. To get the precise statement a specific platform runs at a specific scale, substitute your own values:

from benchbox import H2ODB
bench = H2ODB(scale_factor=0.01) # your scale factor
queries = bench.get_queries(dialect="datafusion") # your platform's dialect; drop dialect= for native SQL
print(queries['Q4'])

For the DataFrame form:

from benchbox.core.query_catalog import get_dataframe_render
print(get_dataframe_render('h2odb', 'Q4', family="expression").source) # or family="pandas"

Source

Query text: benchbox/core/h2odb/queries.py