Read Primitives — Array of Struct
Read Primitives benchmark · all Read Primitives queries
Create array of structs from grouped data
Representative SQL
Rendered for DataFusion with default parameters.
SELECT o_orderkey, ARRAY_AGG( STRUCT(l_linenumber, l_partkey, l_quantity, l_extendedprice) ORDER BY l_linenumber ) AS line_itemsFROM orders AS oJOIN lineitem AS l ON o.o_orderkey = l.l_orderkeyWHERE o_orderdate = CAST('1995-03-15' AS DATE)GROUP BY o_orderkeyORDER BY o_orderkeyLIMIT 50Representative DataFrame
Expression family (Polars, PySpark, DataFusion), default parameters.
def array_of_struct_expression_impl(ctx: DataFrameContext) -> Any: orders, lineitem = _tables(ctx, "orders", "lineitem") col = ctx.col lit = ctx.lit struct = ctx.struct
filtered_orders = orders.filter(col("o_orderdate") == lit(date(1995, 3, 15))) joined = lineitem.join(filtered_orders, col("l_orderkey") == col("o_orderkey")).sort("l_linenumber")
return ( joined.group_by("o_orderkey") .agg( struct(col("l_linenumber"), col("l_partkey"), col("l_quantity"), col("l_extendedprice")) .list() .alias("line_items") ) .sort("o_orderkey") .limit(50) )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 factorqueries = bench.get_queries(dialect="datafusion") # your platform's dialect; drop dialect= for native SQLprint(queries['array_of_struct'])For the DataFrame form:
from benchbox.core.query_catalog import get_dataframe_render
print(get_dataframe_render('read_primitives', 'array_of_struct', family="expression").source) # or family="pandas"Source
Query text: benchbox/core/read_primitives/queries.py