feat: port Spark findWiderCommonType and use it in if and array #420
All Vouch review confidence checks passed
Residual risk 0.26 = Change Risk (0.45) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 404 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.359
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #420"
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
ifandarraycoerced their arguments with DataFusion's rules rather than Spark's, sothey resolved mixed-type arguments differently from Spark. For example,
array(1::INT, 'a')is
ARRAY<STRING>in Spark, and with ANSI mode onarray(1::INT, '2')isARRAY<BIGINT>,because ANSI casts the string to the other type. Neither function followed
enable_ansi_mode, and a mismatch such asif(true, 1::INT, array(1::INT))did not raiseSpark's
DATA_DIFF_TYPESerror.What changes are included in this PR?
type_coercion.rs: ports Spark'sfindWiderCommonType,findWiderTypeForTwo(with boththe
TypeCoercionandAnsiTypeCoercionstring promotion) andfindWiderTypeWithoutStringPromotion.merge_arg_types: computes the common type of a range of arguments, casts themto it and raises
DATA_DIFF_TYPESif there is none. It writes the type list in the formatof the Spark expression:
["INT", "ARRAY<INT>"]forIf,("INT" or "ARRAY<INT>")forCreateArray(TypeUtils.checkForSameTypeInputExpr).ifandarrayuse the helper and followdatafusion.execution.enable_ansi_mode.greatest/leastcall the portedfindWiderTypeWithoutStringPromotioninstead of theirown fold. Behavior is unchanged.
type, and
force_nullablemarks a string cast to a non-string, non-binary type (which ANSIpromotion produces) as nullable, like Spark's
Cast.forceNullable.Are these changes tested?
Yes:
type_coercion.rs: string promotion with and without ANSI, argument order,nested types and map keys, dictionaries, decimals, empty/NULL inputs, and both error formats.
.sltcases inconditional/if.sltandarray/array.slt, with ANSI mode on and off.The new cases fail before this change and pass after it.
The rules and error messages were checked against the Spark v4.2.0 source:
TypeCoercion,AnsiTypeCoercion,AnsiStringPromotionTypeCoercion,TypeCoercionHelper,TypeUtils,If,CreateArray,Cast.forceNullableanderror-conditions.json. I wrote the expectedresults by hand from those rules and then ran them. I did not run them against a real Spark
with the PySpark runner.
cargo fmt --all,cargo clippy --all-targets --all-features -- -D warnings,cargo test -p datafusion-sparkandcargo test -p datafusion-spark-sqllogictestall pass.Are there any user-facing changes?
Yes, in how
ifandarraycoerce mixed-type arguments: they now follow Spark's rules,which depend on ANSI mode, and report Spark's
DATA_DIFF_TYPESerror when there is no commontype. The new helper functions are
pub(crate);SparkIfandSparkArraygain a privatefield and keep their public constructors, so there are no breaking changes to the public API.