Skip to content

Read Primitives — Map Access

Read Primitives benchmark · all Read Primitives queries

Access map values by key

Representative SQL

Rendered for DataFusion with default parameters.

WITH supplier_costs AS (
SELECT
ps_suppkey,
MAP(ARRAY_AGG(CAST(ps_partkey AS VARCHAR)), ARRAY_AGG(ps_supplycost)) AS part_costs
FROM partsupp
WHERE
ps_suppkey <= 10
GROUP BY
ps_suppkey
)
SELECT
ps_suppkey,
MAP_EXTRACT(part_costs, '1')[1] AS cost_for_part_1,
MAP_EXTRACT(part_costs, '5')[1] AS cost_for_part_5
FROM supplier_costs
ORDER BY
ps_suppkey
LIMIT 10

Representative DataFrame

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

def map_access_expression_impl(ctx: DataFrameContext) -> Any:
col = ctx.col
lit = ctx.lit
return (
_partsupp_map_expression(ctx, 10)
.select(
"ps_suppkey",
col("part_costs").map.get(lit("1")).alias("cost_for_part_1"),
col("part_costs").map.get(lit("5")).alias("cost_for_part_5"),
)
.limit(10)
)

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['map_access'])

For the DataFrame form:

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

Source

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