Skip to content

Read Primitives — JSON Extract Nested

Read Primitives benchmark · all Read Primitives queries

Extract from JSON with complex path expressions

Representative SQL

Rendered in the benchmark’s native SQL with default parameters (no dialect translation available).

SELECT
c_custkey,
JSON_EXTRACT(c_comment, '$.profile.segment') AS customer_segment,
JSON_EXTRACT(c_comment, '$.profile.preferences[0]') AS primary_preference,
JSON_EXTRACT(c_comment, '$.history.last_order.date') AS last_order_date
FROM customer
WHERE
JSON_VALID(c_comment)
LIMIT 500

Representative DataFrame

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

def json_extract_nested_expression_impl(ctx: DataFrameContext) -> Any:
col, lit = ctx.col, ctx.lit
return (
ctx.get_table("customer")
.filter(col("c_comment").str.starts_with("{"))
.select(
"c_custkey",
lit(None).alias("customer_segment"),
lit(None).alias("primary_preference"),
lit(None).alias("last_order_date"),
)
.limit(500)
)

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

For the DataFrame form:

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

Source

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