Skip to content

[Bug] try_mod falls back to Spark because CometRemainder rejects EvalMode.TRY #4484

@andygrove

Description

@andygrove

Describe the bug

try_mod (Spark 4.0+) is RuntimeReplaceable and rewrites to Remainder(left, right, EvalMode.TRY). Comet's CometRemainder serde explicitly rejects EvalMode.TRY with withInfo(expr, "Eval mode TRY is not supported") and returns None, so the enclosing plan falls back to Spark.

The sibling arithmetic serdes (CometAdd, CometSubtract, CometMultiply, CometDivide, CometIntegralDivide) all accept EvalMode.TRY by propagating the mode through evalModeToProto, and the Rust spark_modulo UDF already takes a fail_on_error: bool flag, so there is no semantic obstacle to letting EvalMode.TRY through.

Surfaced by the math-expressions audit (collection PR queue).

Steps to reproduce

SELECT try_mod(10, 0); -- Spark 4.0+ returns NULL; Comet falls back

Expected behavior

CometRemainder should accept EvalMode.TRY the same way the other arithmetic serdes do (TRY currently behaves identically to LEGACY at the Rust layer, returning NULL on divide-by-zero).

Additional context

  • Comet serde: CometRemainder in spark/src/main/scala/org/apache/comet/serde/arithmetic.scala
  • Rust impl: native/spark-expr/src/math_funcs/modulo_expr.rs::spark_modulo
  • Spark reference: TryMod in org.apache.spark.sql.catalyst.expressions.tryArithmetic.scala

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions