Skip to content

refactor: gate CometUnaryMinus input types in getSupportLevel#4759

Merged
andygrove merged 2 commits into
apache:mainfrom
andygrove:fix-4500-unary-minus-support-level
Jun 30, 2026
Merged

refactor: gate CometUnaryMinus input types in getSupportLevel#4759
andygrove merged 2 commits into
apache:mainfrom
andygrove:fix-4500-unary-minus-support-level

Conversation

@andygrove

Copy link
Copy Markdown
Member

Which issue does this PR close?

Relates to #4500 (item 1: lift convert-time fallbacks in arithmetic.scala into getSupportLevel).

Rationale for this change

PR #4674 moved the arithmetic and math support checks into getSupportLevel so that unsupported input types are reported at planning time, where the reason surfaces in EXPLAIN output and is picked up by the generated compatibility docs. CometUnaryMinus was the only arithmetic serde left relying on a convert-time fallback for unsupported input types: an interval input would serialize its child, fail, and fall back with a generic child-level reason rather than a clear datatype reason.

This change completes that pattern for UnaryMinus.

What changes are included in this PR?

  • CometUnaryMinus now mixes in MathBase and overrides getSupportLevel with mathDataTypeSupportLevel(expr.child.dataType), matching the other arithmetic serdes. Every Spark NumericType (including decimal) stays native; interval types are reported as Unsupported with a datatype reason and fall back to Spark.
  • Added a CometExpressionSuite regression test covering unary minus over byte, short, int, long, float, double, and decimal.

How are these changes tested?

New test unary minus across numeric types in CometExpressionSuite, passing on Spark 3.5 and 4.0. Behavior was validated with the audit-comet-expression skill: numeric types (including decimal) run natively and match Spark, while day-time and year-month interval inputs fall back to Spark.

UnaryMinus was the only arithmetic serde still relying on a convert-time
fallback for unsupported input types after apache#4674. Add a getSupportLevel
override mirroring the other math expressions (via mathDataTypeSupportLevel)
so the unsupported-datatype reason surfaces in EXPLAIN and the generated
compatibility docs, and interval inputs fall back with a clear reason.

Numeric types (including decimal) are verified to stay native; interval
types fall back to Spark.
// must stay native; interval types are unsupported and fall back to Spark.
withParquetTable(
(1 to 5).map(i =>
(i.toByte, i.toShort, i, i.toLong, i.toFloat, i.toDouble, BigDecimal(i * 3, 2))),

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.

perhaps its covered with sql tests, but maybe we can test also extreme cases? min/max, nans, nulls, inf. feel free to ignore it if such tests already exist

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.

Added unary minus on float/double special values and nulls covering NaN, ±Infinity, signed zero (0.0/-0.0), the float/double range limits, and null, with dictionary on and off — all match Spark, since negation is an IEEE sign flip.

Integer Max/MinValue and the ANSI overflow behavior are already covered by the existing unary negative integer overflow test, so I left those out to avoid duplication.

@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 44b0eb6 into apache:main Jun 30, 2026
69 checks passed
@andygrove andygrove deleted the fix-4500-unary-minus-support-level branch June 30, 2026 13:16
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