refactor: move array expression support checks to getSupportLevel#4677
Merged
Conversation
Static support decisions for several array expressions are moved out of the serde convert methods and into getSupportLevel: - ArrayRemove, Flatten, ArrayPosition: unsupported input data types (via a shared ArraysBase.childTypesSupportLevel helper) - ArrayPosition: all-foldable args fall back so Spark can constant-fold - SortArray: ascendingOrder must be a boolean literal - ElementAt: input must be an array Behavior is unchanged: each case that previously fell back to Spark now reports Unsupported with the same reason. The remaining withFallbackReason calls are child-reason rollups. ArrayExcept and ArrayReverse are intentionally left for a follow-up: their type checks interact with the codegen-dispatch routing for Incompatible expressions, so moving them is not behavior-preserving in isolation.
comphead
reviewed
Jun 18, 2026
| "Input must be an array. `Map` inputs are not supported.") | ||
|
|
||
| override def getSupportLevel(expr: ElementAt): SupportLevel = { | ||
| if (expr.left.dataType.isInstanceOf[ArrayType]) { |
Contributor
There was a problem hiding this comment.
in Apache Spark, the ElementAt supports Map, and Comet gates for Array only, we should support Map
override def inputTypes: Seq[AbstractDataType] = {
(left.dataType, right.dataType) match {
case (arr: ArrayType, e2: IntegralType) if (e2 != LongType) =>
Seq(arr, IntegerType)
case (MapType(keyType, valueType, hasNull), e2) =>
TypeCoercion.findTightestCommonType(keyType, e2) match {
case Some(dt) => Seq(MapType(dt, valueType, hasNull), dt)
case _ => Seq.empty
}
case (l, r) => Seq.empty
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Part of #4673.
Rationale for this change
The serde framework intends that an expression declares whether it can be accelerated through
getSupportLevel, with the central dispatcher inQueryPlanSerdetranslatingIncompatible/Unsupportedinto the appropriate fallback. Several array serdes instead made these decisions insideconvertby callingwithFallbackReasondirectly, even though the decisions are statically determinable from the expression.What changes are included in this PR?
Move static support decisions out of
convertand intogetSupportLevelfor the array expressions:ArrayRemove,Flatten,ArrayPosition: unsupported input data types, via a sharedArraysBase.childTypesSupportLevelhelper.ArrayPosition: all-foldable arguments fall back so Spark'sConstantFoldingcan handle them.SortArray:ascendingOrdermust be a boolean literal (folded into the existinggetSupportLevel).ElementAt: the input must be an array (Mapinputs fall back).This is behavior-preserving: every case that previously fell back to Spark continues to fall back with the same reason. The remaining
withFallbackReasoncalls in this file are child-reason rollups, which are the intended use insideconvert.ArrayExceptandArrayReverseare intentionally left for a follow-up. TheirisTypeSupportedchecks interact with the codegen-dispatch routing used forIncompatibleexpressions (a binary-arrayreverse, for example, stays native via the codegen dispatcher), so reclassifying those checks asUnsupportedwould change routing and is not behavior-preserving in isolation.How are these changes tested?
Covered by existing tests in
CometArrayExpressionSuite(41 tests), which exercise both the supported and fallback paths for these expressions.