Skip to content

Read Primitives — JSON Aggregates

Read Primitives benchmark · all Read Primitives queries

Create JSON arrays and objects from aggregations

Representative SQL

Rendered in the benchmark’s native SQL with default parameters (no dialect translation available).

SELECT
p_brand,
JSON_ARRAYAGG(p_name) AS part_names,
JSON_OBJECTAGG(p_partkey: p_retailprice) AS part_prices,
COUNT(*) AS part_count
FROM part
WHERE
p_type LIKE '%STEEL%'
GROUP BY
p_brand
ORDER BY
p_brand
LIMIT 100

Representative DataFrame

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

def json_aggregates_expression_impl(ctx: DataFrameContext) -> Any:
part = ctx.get_table("part")
col = ctx.col
return (
part.filter(col("p_type").str.contains("STEEL"))
.group_by("p_brand")
.agg(
col("p_name").list().alias("part_names"),
col("p_retailprice").list().alias("part_prices"),
col("p_partkey").count().alias("part_count"),
)
.limit(100)
)

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 ReadPrimitives
bench = ReadPrimitives(scale_factor=0.01) # your scale factor
queries = bench.get_queries(dialect="datafusion") # your platform's dialect; drop dialect= for native SQL
print(queries['json_aggregates'])

For the DataFrame form:

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

Source

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