feat(spark): support map/array input and an options argument in to_json #395
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.42) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 334 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.348
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #395"
general
weight: 0.35
cj-zhukov
<!--
SPDX-License-Identifier: Apache-2.0
SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
-->
Which issue does this PR close?
Rationale for this change
Spark's
to_jsonaccepts a map or an array as the value to serialize, and an optionalmap(...)of options as a second argument. Both were rejected at planning time:to_json(map('a', 1))failed with "expects a struct argument", and a second argument failed with "but received 2".What changes are included in this PR?
to_jsonaccepts a struct, a map, any Arrow list type, or an untyped NULL. The encoder already serialized maps and lists when nested, so only the planning check changed; the root type gets the same validation as nested types.to_json(expr, options): the second argument is a constant map of strings, read as Spark'sJSONOptionsdoes (case-insensitive names,true/falsein any case).ToJsonOption, named after Spark's JSON data source options(https://spark.apache.org/docs/latest/sql-data-sources-json.html#data-source-option). This PR implements one,
ignoreNullFields. Any other option is an error that lists the supported ones.struct_to_jsonis renamedto_json, matching apache/datafusion#27518.Are these changes tested?
Yes.
to_json.rsfor the planning check, map/list input as a column and as a scalar (NULL rows, sliced input,LargeList,FixedSizeList), option parsing, andignoreNullFields.json/to_json.slt, written without[...]literals so that Spark can parse them.crates/sqllogictest/scripts. It found one difference,to_json(NULL), which Spark answers with NULL; this PR matches that.Known differences from Spark, marked
# xfail spark: intendedin the SLT:Are there any user-facing changes?
to_jsonaccepts map and array input and theignoreNullFieldsoption.to_json(NULL)returns NULL instead of a planning error.argument".
No change to the public API:
expr_fn::to_json(input)still takes one argument.