fix: reject null-typed columns in stack #402
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.46) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 467 lines diff across 5 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.368
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #402"
general
weight: 0.35
andygrove
Which issue does this PR close?
Closes #361.
Rationale for this change
In Apache Spark,
stack(n, expr1, ..., exprk)permits literalNULLvalues in a column by coercing them to the data type of that column (viaStackCoercion). However, when a table column itself hasNullType(Spark type"VOID"), Spark does not coerce the column and instead fails validation during query analysis with:Prior to this PR,
datafusion-sparkchecked!actual.is_null()when comparing argument types incolumn_types(). This inadvertently bypassed allDataType::Nullarguments regardless of whether they were literal NULL expressions or NULL-typed table columns, causing queries likestack(2, a, b)withbof typeNullto incorrectly succeed instead of raisingDATATYPE_MISMATCH.STACK_COLUMN_DIFF_TYPES.What changes are included in this PR?
1. Distinguish literal NULL from NULL-typed columns: In
crates/spark/src/function/generator/stack.rs:column_types, differentiate between literal NULLs (which havescalar_arguments.get(i).copied().flatten().is_some()) and table columns ofDataType::Null.2. Order-independent column type resolution:
- For each column, if the initial entry is a literal NULL, resolve the target column type as the first non-null-literal expression in that column (or
DataType::Nullif all entries are literal NULLs). If the initial entry is a column (typed or NULL-typed), use its data type directly.- Validate all non-null-literal arguments in the column against this expected type.
3. Spark-compatible error diagnostics:
- Use error class
[DATATYPE_MISMATCH.STACK_COLUMN_DIFF_TYPES].- Format expected and actual types using
spark_sql_type(e.g."VOID","INT","BIGINT","SMALLINT","STRING").- Use 1-based indices for the parameter positions matching Spark Catalyst error messages.
4. SLT & Unit Test Coverage:
- In
crates/spark/src/function/generator/stack.rs:- Added
test_column_types_rejects_null_typed_columnverifying rejection of NULL-typed columns in both forward and reverse orders.- Added
test_column_types_literal_null_coerciontesting literal NULL before/after typed columns, all-literal NULL columns, and all-NULL-typed table columns.- Updated
test_column_types_widen_only_bigint_literalsto verify new error class and SQL type format.- In
crates/sqllogictest/test_files/generator/stack.slt:- Removed
# xfail sparkon line 54.- Added positive test cases for literal NULL before and after columns (
stack(2, NULL, a),stack(2, a, NULL)).- Added negative test cases verifying
[DATATYPE_MISMATCH.STACK_COLUMN_DIFF_TYPES]for column paired with NULL-typed column in forward, reverse, and multi-column positions (stack(2, a, b),stack(2, b, a),stack(2, 1, a, 2, b)).- Updated existing mismatch error expectations to match Spark error class and types.
Are these changes tested?
Yes:
cargo test -p datafusion-spark --lib generator::stack::tests(8 passed, 0 failed).cargo test -p datafusion-spark-sqllogictest --test sqllogictests -- stack(PASS [simplify], PASS [evaluate]).cargo fmt --all -- --checkandcargo clippy -p datafusion-spark --all-targets -- -D warnings.Are there any user-facing changes?
No public API changes. Queries using
stack()with table columns ofNulltype now correctly fail query analysis with Spark-compatible[DATATYPE_MISMATCH.STACK_COLUMN_DIFF_TYPES], matching Apache Spark behavior.