Skip to content

H2ODB — Sum by Year and Hour

H2ODB benchmark · all H2ODB queries

SUM(fare_amount) GROUP BY EXTRACT(YEAR), EXTRACT(HOUR)

Representative SQL

Rendered for DataFusion with default parameters.

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

Representative DataFrame

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

def q8_expression_impl(ctx: DataFrameContext) -> Any:
trips = ctx.get_table("trips")
col = ctx.col
return (
trips.with_columns(
col("pickup_datetime").dt.year().alias("year"),
col("pickup_datetime").dt.hour().alias("hour"),
)
.group_by("year", "hour")
.agg(col("fare_amount").sum().alias("sum_fare_amount"))
.sort(["year", "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['Q8'])

For the DataFrame form:

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

Source

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