Skip to content

refactor: move string expression support checks to getSupportLevel#4676

Merged
andygrove merged 1 commit into
apache:mainfrom
andygrove:refactor-strings-support-level
Jun 18, 2026
Merged

refactor: move string expression support checks to getSupportLevel#4676
andygrove merged 1 commit into
apache:mainfrom
andygrove:refactor-strings-support-level

Conversation

@andygrove

Copy link
Copy Markdown
Member

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 in QueryPlanSerde translating Incompatible/Unsupported into the appropriate fallback. Several string serdes instead made these decisions inside convert by calling withFallbackReason directly, even though the decisions are statically determinable from the expression.

What changes are included in this PR?

Move static support decisions out of convert and into getSupportLevel for the string expressions:

  • Substring: pos and len must be literals.
  • Left, Right: the length argument must be a literal (folded into the existing getSupportLevel).
  • ConcatWs: all-foldable arguments fall back so Spark's ConstantFolding can handle them. The NULL-separator case still converts directly to a NULL result, so the precedence is preserved in getSupportLevel.
  • Like: a custom escape character is unsupported.

This is behavior-preserving: every case that previously fell back to Spark continues to fall back with the same reason. The remaining withFallbackReason calls in this file are child-reason rollups, which are the intended use inside convert.

How are these changes tested?

Covered by existing tests: CometStringExpressionSuite (33 tests, including concat_ws, left, right) and CometExpressionSuite (like with custom escape, string type and substring, substring with start < 1), which exercise both the supported and fallback paths.

Static support decisions for the string expressions are moved out of the
serde convert methods and into getSupportLevel:

- Substring: pos and len must be literals
- Left, Right: length argument must be a literal
- ConcatWs: all-foldable args fall back so Spark can constant-fold (the
  NULL-separator case still converts directly to a NULL result)
- Like: custom escape character is unsupported

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.

object CometSubstring extends CometExpressionSerde[Substring] {

override def getSupportLevel(expr: Substring): SupportLevel = (expr.pos, expr.len) match {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would be fixed after DF54, #4161

}
}

override def convert(expr: Like, inputs: Seq[Attribute], binding: Boolean): Option[Expr] = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe one day we should rename this method,it confuses me sometimes what is this conversion, is it expression rewrite, simplification, etc

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to consider doing all the renames we want to do before we release 1.0.0

@comphead comphead left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @andygrove

@andygrove andygrove merged commit b26a8df into apache:main Jun 18, 2026
70 checks passed
@andygrove andygrove deleted the refactor-strings-support-level branch June 18, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants