Skip to content

fix: make native pow implementation compatible with Spark#5033

Open
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:feat/native-pow-compatible
Open

fix: make native pow implementation compatible with Spark#5033
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:feat/native-pow-compatible

Conversation

@andygrove

Copy link
Copy Markdown
Member

Which issue does this PR close?

There is no dedicated tracking issue. The native path's incompatibility stems from the upstream DataFusion behavior in apache/datafusion#22598.

Closes #.

Rationale for this change

Spark's Pow expression delegates to Java's Math.pow, which returns Infinity for a zero base raised to a negative exponent (pow(0, -1)). Comet's native path routed pow to DataFusion's PowerFunc, whose float64_power_checked instead errors on that input (apache/datafusion#22598). Because of that single edge case, CometPow was marked Unsupported, so any query using pow/power fell back to Spark for that part of the plan.

Rust's f64::powf follows the same IEEE-754 pow semantics as Java's Math.pow (including 0^-1 = Infinity, (-0)^-1 = -Infinity, and the NaN/Infinity cases), so a thin native kernel over powf matches Spark exactly and lets pow run natively by default instead of falling back.

What changes are included in this PR?

  • Add a spark_pow native kernel (native/spark-expr/src/math_funcs/pow.rs) that computes base.powf(exp) element-wise with null propagation, covering all Array/Scalar argument combinations.
  • Register "pow" to spark_pow in create_comet_physical_fun_with_eval_mode, so it no longer falls through to DataFusion's checked power, plus the module/re-export wiring.
  • Simplify CometPow to a plain Compatible serde (drop the Unsupported/"Power has correctness issues" reporting).

How are these changes tested?

  • Rust unit tests in pow.rs covering the basic cases, pow(0, -1) == Infinity, null propagation, and the scalar-base path.
  • The expressions/math/pow.sql SQL file test (run via CometSqlFileTestSuite) now asserts native execution matches Spark across zero-base-negative-exponent, NaN, Infinity, null, and column/literal argument combinations, replacing the previous expect_fallback assertions.

@andygrove andygrove changed the title feat: native pow implementation compatible with Spark fix: make native pow implementation compatible with Spark Jul 24, 2026
CREATE TABLE test_pow(base double, exp double) USING parquet

statement
INSERT INTO test_pow VALUES (0.0, -1), (2.0, 3.0), (0.0, 0.0), (-1.0, 2.0), (-1.0, 0.5), (2.0, -1.0), (NULL, 2.0), (2.0, NULL), (cast('NaN' as double), 2.0), (cast('Infinity' as double), 2.0), (2.0, cast('Infinity' as double))

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.

What about negative zero cases? and subnormal numbers?

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.

negative infinity can be interesting too. we probably need a bit more combinations.

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