Read Primitives — MAX_BY with Ties
Read Primitives benchmark · all Read Primitives queries
Find the supplier with the highest supply cost for each part
Representative SQL
Rendered for DataFusion with default parameters.
WITH ranked AS ( SELECT p.p_partkey, p.p_name, s.s_name, ps.ps_supplycost, ROW_NUMBER() OVER (PARTITION BY p.p_partkey, p.p_name ORDER BY ps.ps_supplycost DESC, s.s_name) AS rn FROM partsupp AS ps JOIN part AS p ON ps.ps_partkey = p.p_partkey JOIN supplier AS s ON ps.ps_suppkey = s.s_suppkey)SELECT p_partkey, p_name, s_name AS supplier_name, ps_supplycost AS max_supply_costFROM rankedWHERE rn = 1ORDER BY max_supply_cost DESC, p_partkey, p_nameLIMIT 100Representative DataFrame
Expression family (Polars, PySpark, DataFusion), default parameters.
def max_by_with_ties_expression_impl(ctx: DataFrameContext) -> Any: return _supply_cost_extreme_expr(ctx, descending=True, value_alias="max_supply_cost", 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 factorqueries = bench.get_queries(dialect="datafusion") # your platform's dialect; drop dialect= for native SQLprint(queries['max_by_with_ties'])For the DataFrame form:
from benchbox.core.query_catalog import get_dataframe_render
print(get_dataframe_render('read_primitives', 'max_by_with_ties', family="expression").source) # or family="pandas"Source
Query text: benchbox/core/read_primitives/queries.py