Skip to content

H2ODB — Sum by Hour

H2ODB benchmark · all H2ODB queries

SUM(fare_amount) GROUP BY EXTRACT(HOUR FROM pickup_datetime)

Representative SQL

Rendered for DataFusion with default parameters.

SELECT
EXTRACT(HOUR FROM pickup_datetime) AS hour,
SUM(fare_amount) AS sum_fare_amount
FROM trips
GROUP BY
EXTRACT(HOUR FROM pickup_datetime)
ORDER BY
hour

Representative DataFrame

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

def q7_expression_impl(ctx: DataFrameContext) -> Any:
trips = ctx.get_table("trips")
col = ctx.col
return (
trips.with_columns(col("pickup_datetime").dt.hour().alias("hour"))
.group_by("hour")
.agg(col("fare_amount").sum().alias("sum_fare_amount"))
.sort("hour")
)

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['Q7'])

For the DataFrame form:

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

Source

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