Read Primitives — Map Keys/Values
Read Primitives benchmark · all Read Primitives queries
Extract keys and values from map
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 <= 5 GROUP BY ps_suppkey)SELECT ps_suppkey, MAP_KEYS(part_costs) AS part_ids, MAP_VALUES(part_costs) AS costsFROM supplier_costsORDER BY ps_suppkeyRepresentative DataFrame
Expression family (Polars, PySpark, DataFusion), default parameters.
def map_keys_values_expression_impl(ctx: DataFrameContext) -> Any: col = ctx.col
return _partsupp_map_expression(ctx, 5).select( "ps_suppkey", col("part_costs").map.keys().alias("part_ids"), col("part_costs").map.values().alias("costs"), )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['map_keys_values'])For the DataFrame form:
from benchbox.core.query_catalog import get_dataframe_render
print(get_dataframe_render('read_primitives', 'map_keys_values', family="expression").source) # or family="pandas"Source
Query text: benchbox/core/read_primitives/queries.py