Skip to content

chore: fix spark ansi sum incompatibility message#4111

Open
coderfender wants to merge 3 commits intoapache:mainfrom
coderfender:fix_comet_sum_compatbility_level
Open

chore: fix spark ansi sum incompatibility message#4111
coderfender wants to merge 3 commits intoapache:mainfrom
coderfender:fix_comet_sum_compatbility_level

Conversation

@coderfender
Copy link
Copy Markdown
Contributor

@coderfender coderfender commented Apr 27, 2026

Which issue does this PR close?

Closes #4074

Rationale for this change

What changes are included in this PR?

How are these changes tested?

case Literal(count, _) if isNegativeNumber(count) =>
withInfo(expr, "Negative repeat count is not supported")
return None
case _ =>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This will guard against negative repeat character but still goes through for positive counts with an error message . getIncompatibleReasons() is to add the right error message on documentation

Incompatible(None)
} else {
Unsupported(None)
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried to leverage the right reason to fallback based on the pattern here

@coderfender coderfender force-pushed the fix_comet_sum_compatbility_level branch from 0d481f4 to 2fdb835 Compare April 29, 2026 07:43
object CometSum extends CometAggregateExpressionSerde[Sum] {

override def getIncompatibleReasons(): Seq[String] = Seq("Falls back to Spark in ANSI mode.")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we support ansi mode so no need to fallback to spark

case i: Int => i < 0
case l: Long => l < 0
case _ => false
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added this method to be utilized later but can remove it if it is not needed

val defaultPattern = TimestampFormatter.defaultPattern
if (formatStr == defaultPattern) {
Incompatible(None)
} else {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fallback based on specific pattern


query expect_fallback(not fully compatible with Spark)
query expect_fallback(Datetime pattern format: yyyy-MM-dd is unsupported)
SELECT from_unixtime(t, 'yyyy-MM-dd') FROM test_from_unix_time
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

error / fallback reason is more actionable

Copy link
Copy Markdown
Contributor Author

@coderfender coderfender left a comment

Choose a reason for hiding this comment

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

added some comments to help with review

object CometStringRepeat extends CometExpressionSerde[StringRepeat] {

override def getCompatibleNotes(): Seq[String] = Seq(
override def getIncompatibleReasons(): Seq[String] = Seq(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is an approved PR to fix the behavior here

#4017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This PR has now been merged

override def getSupportLevel(expr: FromUnixTime): SupportLevel = {
expr.format match {
case Literal(fmt, _) =>
val formatStr = fmt.toString
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Possible NPE if fmt is null

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.

Fix issues found when documenting current expression incompatibilities

2 participants