fix: reject untyped null in array_contains #401
All Vouch review confidence checks passed
Residual risk 0.27 = Change Risk (0.50) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 574 lines diff across 7 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.380
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #401"
general
weight: 0.35
andygrove
<!--
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
In Apache Spark,
array_containsrejects untypedNULLinputs during query analysis / planning with error class[DATATYPE_MISMATCH.NULL_TYPE]:Previously,
datafusion-sparkconfiguredSparkArrayContainswith DataFusion's genericSignature::array_and_element, which bypassed analysis-time validation for untypedNULLand returnedNULLat runtime (annotated asxfail sparkincrates/sqllogictest/test_files/array/array_contains.slt).Typed NULL expressions, such as
CAST(NULL AS ARRAY<INT>)orCAST(NULL AS INT), are valid in Spark and returnNULLat runtime.Furthermore, Spark's
ArrayContains.inputTypesreplaces generic coercion withTypeCoercion.findWiderTypeWithoutStringPromotionForTwoto find the wider type of array elements and the search needle (supporting decimal widening), while rejecting unorderable types and mismatched types without implicit string promotion.What changes are included in this PR?
1. Configured
SparkArrayContainswithSignature::user_defined(Volatility::Immutable).2. Implemented
ScalarUDFImpl::coerce_typesforSparkArrayContainsaligning with Spark'sArrayContains.checkInputDataTypes:- Symmetrically rejects untyped
DataType::Nullarguments at planning time with[DATATYPE_MISMATCH.NULL_TYPE] Null typed values cannot be used as arguments of \array_contains\. SQLSTATE: 42K09.- Validates array types (
List,LargeList,FixedSizeList), raising[DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE]if the first argument is not an array.- Replaces generic element coercion with Spark's decimal-compatible
type_coercion::wider_type(TypeCoercion.findWiderTypeWithoutStringPromotionForTwo) andstruct_field_types_match, raising[DATATYPE_MISMATCH.ARRAY_FUNCTION_DIFF_TYPES]on type mismatch or unsupported promotion (e.g., strings vs numbers).- Checks
is_orderable(&common), raising[DATATYPE_MISMATCH.INVALID_ORDERING_TYPE]for unorderable types (e.g. Map, Interval).3. Preserves typed NULL expressions (
CAST(NULL AS ...)), which pass analysis and evaluate toNULLat execution time.4. Added 12 Rust unit tests in
crates/spark/src/function/array/array_contains.rscovering untyped NULL rejection, same-type coercion, decimal widening, nested decimal widening, type mismatch, non-array input, invalid ordering types, and arity validation.5. Updated
crates/sqllogictest/test_files/array/array_contains.sltto:- Remove the two
# xfail sparkmarkers and assertDATATYPE_MISMATCH.NULL_TYPEerrors for untyped NULLs.- Assert
NULLfor typed NULL arguments.- Add a comprehensive "Type coercion" section covering numeric widening, decimal widening, nested arrays, floats, dictionaries, structs, and error cases (strings vs numbers, unorderable map elements, non-array first argument).
Are these changes tested?
crates/spark/src/function/array/array_contains.rsverifying all error and coercion branches.crates/sqllogictest/test_files/array/array_contains.sltand verified withcargo test -p datafusion-spark-sqllogictest -- array_containsacross bothsimplifyandevaluatepasses (2 of 2 passed).cargo fmt --checkandcargo clippy -p datafusion-spark --all-targets -- -D warnings.Are there any user-facing changes?
array_containsnow rejects untypedNULLarguments at query planning time with[DATATYPE_MISMATCH.NULL_TYPE] ... SQLSTATE: 42K09, matching Apache Spark behavior.findWiderTypeWithoutStringPromotionForTwosemantics: arguments that do not widen under Spark rules (such as strings paired with numeric types) are rejected at planning time with[DATATYPE_MISMATCH.ARRAY_FUNCTION_DIFF_TYPES], while decimals widen correctly (e.g., integer with decimal, decimal with decimal, decimal with float).