Skip to content

Read Primitives — Array Sort

Read Primitives benchmark · all Read Primitives queries

Sort array elements

Representative SQL

Rendered for DataFusion with default parameters.

WITH part_sizes AS (
SELECT
p_brand,
ARRAY_AGG(p_size) AS sizes
FROM part
GROUP BY
p_brand
)
SELECT
p_brand,
ARRAY_SORT(sizes) AS sorted_sizes
FROM part_sizes
ORDER BY
p_brand
LIMIT 50

Representative DataFrame

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

def array_sort_expression_impl(ctx: DataFrameContext) -> Any:
col = ctx.col
return (
_expr_grouped_list(ctx, "part", "p_brand", "p_size", "sizes")
.with_columns(col("sizes").list.sort().alias("sorted_sizes"))
.select("p_brand", "sorted_sizes")
.sort("p_brand")
.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 factor
queries = bench.get_queries(dialect="datafusion") # your platform's dialect; drop dialect= for native SQL
print(queries['array_sort'])

For the DataFrame form:

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

Source

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