You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gluten.apache.org by "ReemaAlzaid (via GitHub)" <gi...@apache.org> on 2026/10/17 23:52:19 UTC

[PR] [GLUTEN-10134][VL] Support decimal pmod with ANSI semantics [gluten]

ReemaAlzaid opened a new pull request, #13351:
URL: https://github.com/apache/gluten/pull/13351

   ## What changes are proposed in this pull request?
   
   Related to #10134.
   
   This PR adds the Gluten integration for facebookincubator/velox#19522 and is waiting for that change to be merged and included in Gluten's Velox build. Until then, decimal `pmod` falls back to Spark.
   
   It enables decimal `pmod` in the Velox backend while preserving Spark's result type and behavior in both ANSI and legacy modes. Division by zero and decimal overflow raise errors in ANSI mode and return null in legacy mode.
   
   Support is currently limited to decimal columns and literals. Computed operands still fall back to Spark to preserve evaluation order, including when partial projection is enabled. Queries also fall back if native validation is disabled or the required Velox functions are unavailable.
   
   ## How was this patch tested?
   
   Added tests in `DecimalPmodValidateSuite` and the Spark 4.1 `GlutenDecimalPrecisionSuite` covering mixed precision and scale, nulls, negative values, division by zero, and overflow.
   
   Test results: [will be added after velox gets merged]
   
   ## Was this patch authored or co-authored using generative AI tooling?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-10134][VL] Support decimal pmod with ANSI semantics [gluten]

Posted by "github-actions[bot] (via GitHub) via commits" <co...@gluten.apache.org>.
github-actions[bot] commented on PR #13351:
URL: https://github.com/apache/gluten/pull/13351#issuecomment-6832243141

   Run Gluten Clickhouse CI on x86


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-10134][VL] Support decimal pmod with ANSI semantics [gluten]

Posted by "ReemaAlzaid (via GitHub) via commits" <co...@gluten.apache.org>.
ReemaAlzaid commented on code in PR #13351:
URL: https://github.com/apache/gluten/pull/13351#discussion_r4552593091


##########
ep/build-velox/src/get-velox.sh:
##########
@@ -25,7 +25,7 @@ RUN_SETUP_SCRIPT=ON
 ENABLE_ENHANCED_FEATURES=OFF
 
 # Developer use only for testing Velox PR.
-UPSTREAM_VELOX_PR_ID=""

Review Comment:
   yeah I just wanted to run the CI to check before merging



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-10134][VL] Support decimal pmod with ANSI semantics [gluten]

Posted by "github-actions[bot] (via GitHub) via commits" <co...@gluten.apache.org>.
github-actions[bot] commented on PR #13351:
URL: https://github.com/apache/gluten/pull/13351#issuecomment-6894190387

   Run Gluten Clickhouse CI on x86


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-10134][VL] Support decimal pmod with ANSI semantics [gluten]

Posted by "github-actions[bot] (via GitHub) via commits" <co...@gluten.apache.org>.
github-actions[bot] commented on PR #13351:
URL: https://github.com/apache/gluten/pull/13351#issuecomment-6839039770

   Run Gluten Clickhouse CI on x86


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-10134][VL] Support decimal pmod with ANSI semantics [gluten]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #13351:
URL: https://github.com/apache/gluten/pull/13351#issuecomment-6243379499

   Run Gluten Clickhouse CI on x86


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-10134][VL] Support decimal pmod with ANSI semantics [gluten]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #13351:
URL: https://github.com/apache/gluten/pull/13351#issuecomment-6443009165

   Run Gluten Clickhouse CI on x86


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-10134][VL] Support decimal pmod with ANSI semantics [gluten]

Posted by "github-actions[bot] (via GitHub) via commits" <co...@gluten.apache.org>.
github-actions[bot] commented on PR #13351:
URL: https://github.com/apache/gluten/pull/13351#issuecomment-6920216682

   Run Gluten Clickhouse CI on x86


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-10134][VL] Support decimal pmod with ANSI semantics [gluten]

Posted by "rdtr (via GitHub) via commits" <co...@gluten.apache.org>.
rdtr commented on code in PR #13351:
URL: https://github.com/apache/gluten/pull/13351#discussion_r4544374184


##########
backends-velox/src/main/scala/org/apache/gluten/backendsapi/velox/VeloxSparkPlanExecApi.scala:
##########
@@ -189,6 +189,59 @@ class VeloxSparkPlanExecApi extends SparkPlanExecApi with Logging {
     else { name }
   }
 
+  override def genDecimalArithmeticTransformer(
+      substraitExprName: String,
+      left: ExpressionTransformer,
+      right: ExpressionTransformer,
+      original: BinaryArithmetic): ExpressionTransformer = {
+    original match {
+      case p: Pmod =>
+        if (p.evalMode != EvalMode.ANSI && p.evalMode != EvalMode.LEGACY) {
+          throw new GlutenNotSupportException(
+            s"Decimal pmod with evaluation mode ${p.evalMode} is not supported.")
+        }
+        // Spark evaluates the divisor first and can skip the dividend for a null/zero divisor.
+        // An eager native function is equivalent only when neither child can raise an error.
+        // Restrict this initial implementation to values whose evaluation cannot throw.
+        if (
+          !p.children.forall {
+            case _: AttributeReference | _: BoundReference | _: Literal => true
+            case _ => false
+          }
+        ) {
+          throw new GlutenNotSupportException(
+            "Decimal pmod with computed operands is not supported.")
+        }
+        // Checked decimal pmod is not present in older Velox builds. Validation must resolve its
+        // signature before offloading; otherwise preserve Spark execution even when validation
+        // was explicitly disabled.
+        if (!GlutenConfig.get.enableNativeValidation) {
+          throw new GlutenNotSupportException("Decimal pmod requires native validation.")
+        }
+        // Use Spark's resolved decimal type, including the precision check needed after
+        // adjusting a negative remainder. The checked function has fixed ANSI semantics,
+        // preserving the expression's captured mode even if the session changes after planning.
+        val checked = DecimalArithmeticExpressionTransformer(
+          "checked_" + substraitExprName,

Review Comment:
   With the config-reading `pmod` from facebookincubator/velox#19522, this becomes `substraitExprName` for both modes, without the `try` wrapper at line 234.



##########
backends-velox/src/main/scala/org/apache/gluten/backendsapi/velox/VeloxSparkPlanExecApi.scala:
##########
@@ -189,6 +189,59 @@ class VeloxSparkPlanExecApi extends SparkPlanExecApi with Logging {
     else { name }
   }
 
+  override def genDecimalArithmeticTransformer(
+      substraitExprName: String,
+      left: ExpressionTransformer,
+      right: ExpressionTransformer,
+      original: BinaryArithmetic): ExpressionTransformer = {
+    original match {
+      case p: Pmod =>
+        if (p.evalMode != EvalMode.ANSI && p.evalMode != EvalMode.LEGACY) {
+          throw new GlutenNotSupportException(
+            s"Decimal pmod with evaluation mode ${p.evalMode} is not supported.")
+        }
+        // Spark evaluates the divisor first and can skip the dividend for a null/zero divisor.
+        // An eager native function is equivalent only when neither child can raise an error.
+        // Restrict this initial implementation to values whose evaluation cannot throw.
+        if (
+          !p.children.forall {
+            case _: AttributeReference | _: BoundReference | _: Literal => true
+            case _ => false
+          }
+        ) {
+          throw new GlutenNotSupportException(
+            "Decimal pmod with computed operands is not supported.")
+        }
+        // Checked decimal pmod is not present in older Velox builds. Validation must resolve its
+        // signature before offloading; otherwise preserve Spark execution even when validation
+        // was explicitly disabled.
+        if (!GlutenConfig.get.enableNativeValidation) {

Review Comment:
    This check exists because `checked_pmod` may be missing from older Velox builds. Once the pin includes the decimal `pmod`, the regular signature check covers it.



##########
ep/build-velox/src/get-velox.sh:
##########
@@ -25,7 +25,7 @@ RUN_SETUP_SCRIPT=ON
 ENABLE_ENHANCED_FEATURES=OFF
 
 # Developer use only for testing Velox PR.
-UPSTREAM_VELOX_PR_ID=""

Review Comment:
   Shouldn't you revert this to `""` before merging this PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-10134][VL] Support decimal pmod with ANSI semantics [gluten]

Posted by "rdtr (via GitHub) via commits" <co...@gluten.apache.org>.
rdtr commented on PR #13351:
URL: https://github.com/apache/gluten/pull/13351#issuecomment-6809708718

   @ReemaAlzaid Following up on my comment in https://github.com/facebookincubator/velox/pull/19522#issuecomment-6808781493: if decimal `pmod` reads `spark.ansi_enabled` like primitive `pmod` (https://github.com/facebookincubator/velox/pull/19231), this PR gets simpler. Gluten maps `Pmod` to `pmod` / `pmod_deny_precision_loss` in both modes, and the `checked_` name, the `try` wrapper for LEGACY and the `enableNativeValidation` check can go. A session mode that differs from the captured one is handled by https://github.com/apache/gluten/pull/13529, which falls back for `Pmod` when its `evalMode` differs from the session. The test `decimal pmod preserves captured ANSI mode after physical planning` would then expect a fallback, and the docs paragraph can drop the captured-mode sentence.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-10134][VL] Support decimal pmod with ANSI semantics [gluten]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #13351:
URL: https://github.com/apache/gluten/pull/13351#issuecomment-6442782734

   Run Gluten Clickhouse CI on x86


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-10134][VL] Support decimal pmod with ANSI semantics [gluten]

Posted by "github-actions[bot] (via GitHub) via commits" <co...@gluten.apache.org>.
github-actions[bot] commented on PR #13351:
URL: https://github.com/apache/gluten/pull/13351#issuecomment-6895614728

   Run Gluten Clickhouse CI on x86


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-10134][VL] Support decimal pmod with ANSI semantics [gluten]

Posted by "github-actions[bot] (via GitHub) via commits" <co...@gluten.apache.org>.
github-actions[bot] commented on PR #13351:
URL: https://github.com/apache/gluten/pull/13351#issuecomment-6951220071

   Run Gluten Clickhouse CI on x86


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-10134][VL] Support decimal pmod with ANSI semantics [gluten]

Posted by "github-actions[bot] (via GitHub) via commits" <co...@gluten.apache.org>.
github-actions[bot] commented on PR #13351:
URL: https://github.com/apache/gluten/pull/13351#issuecomment-6919955618

   Run Gluten Clickhouse CI on x86


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-10134][VL] Support decimal pmod with ANSI semantics [gluten]

Posted by "github-actions[bot] (via GitHub) via commits" <co...@gluten.apache.org>.
github-actions[bot] commented on PR #13351:
URL: https://github.com/apache/gluten/pull/13351#issuecomment-6838924913

   Run Gluten Clickhouse CI on x86


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org