This is an automated email from the ASF dual-hosted git repository.

wForget pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gluten.git


The following commit(s) were added to refs/heads/main by this push:
     new b14060d7c0 [GLUTEN-13655][VL] Fix posexplode ordinality type for 
partial projection (#13657)
b14060d7c0 is described below

commit b14060d7c0c0f114a4b65576cb004d6055722911
Author: schumiyi <[email protected]>
AuthorDate: Fri Nov 27 15:19:43 2026 +0800

    [GLUTEN-13655][VL] Fix posexplode ordinality type for partial projection 
(#13657)
---
 .../gluten/execution/GenerateExecTransformer.scala    | 11 +++++++----
 .../gluten/expression/UDFPartialProjectSuite.scala    | 19 ++++++++++++++++++-
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git 
a/backends-velox/src/main/scala/org/apache/gluten/execution/GenerateExecTransformer.scala
 
b/backends-velox/src/main/scala/org/apache/gluten/execution/GenerateExecTransformer.scala
index 5b43396181..79c0fac30e 100644
--- 
a/backends-velox/src/main/scala/org/apache/gluten/execution/GenerateExecTransformer.scala
+++ 
b/backends-velox/src/main/scala/org/apache/gluten/execution/GenerateExecTransformer.scala
@@ -27,7 +27,7 @@ import org.apache.gluten.utils.PullOutProjectHelper
 
 import org.apache.spark.sql.catalyst.expressions._
 import org.apache.spark.sql.execution.{GenerateExec, ProjectExec, SparkPlan}
-import org.apache.spark.sql.types.{BooleanType, IntegerType}
+import org.apache.spark.sql.types.{BooleanType, IntegerType, LongType}
 
 import com.google.protobuf.StringValue
 
@@ -273,8 +273,11 @@ object PullOutGenerateProjectHelper extends 
PullOutProjectHelper {
       generate.generator match {
         case PosExplode(_) =>
           val originalOrdinal = generate.generatorOutput.head
+          // Velox Unnest emits a one-based BIGINT ordinality. Give it its own 
attribute;
+          // the post projection restores Spark's zero-based INT position and 
exprId.
+          val nativeOrdinal = 
originalOrdinal.newInstance().withDataType(LongType)
           val ordinal = {
-            val subtract = Subtract(Cast(originalOrdinal, IntegerType), 
Literal(1))
+            val subtract = Subtract(Cast(nativeOrdinal, IntegerType), 
Literal(1))
             Alias(subtract, generatePostAliasName)(
               originalOrdinal.exprId,
               originalOrdinal.qualifier)
@@ -295,12 +298,12 @@ object PullOutGenerateProjectHelper extends 
PullOutProjectHelper {
 
             // Reorder the generatorOutput to match the output from the Unnest 
operator in Velox.
             val newGenerate = generate.copy(generatorOutput =
-              generate.generatorOutput.tail :+ originalOrdinal :+ isPresent)
+              generate.generatorOutput.tail :+ nativeOrdinal :+ isPresent)
 
             ProjectExec(generate.requiredChildOutput ++ newOutput, newGenerate)
           } else {
             val newGenerate =
-              generate.copy(generatorOutput = generate.generatorOutput.tail :+ 
originalOrdinal)
+              generate.copy(generatorOutput = generate.generatorOutput.tail :+ 
nativeOrdinal)
             ProjectExec(
               (generate.requiredChildOutput :+ ordinal) ++ 
generate.generatorOutput.tail,
               newGenerate)
diff --git 
a/backends-velox/src/test/scala/org/apache/gluten/expression/UDFPartialProjectSuite.scala
 
b/backends-velox/src/test/scala/org/apache/gluten/expression/UDFPartialProjectSuite.scala
index 1fd47bcef5..4ede25d57a 100644
--- 
a/backends-velox/src/test/scala/org/apache/gluten/expression/UDFPartialProjectSuite.scala
+++ 
b/backends-velox/src/test/scala/org/apache/gluten/expression/UDFPartialProjectSuite.scala
@@ -17,7 +17,7 @@
 package org.apache.gluten.expression
 
 import org.apache.gluten.config.GlutenConfig
-import org.apache.gluten.execution.{ColumnarPartialProjectExec, 
SortExecTransformer, WholeStageTransformerSuite}
+import org.apache.gluten.execution.{ColumnarPartialProjectExec, 
GenerateExecTransformer, SortExecTransformer, WholeStageTransformerSuite}
 
 import org.apache.spark.SparkConf
 import org.apache.spark.sql.catalyst.optimizer.{ConstantFolding, 
NullPropagation}
@@ -231,6 +231,23 @@ class UDFPartialProjectSuite extends 
WholeStageTransformerSuite {
       checkGlutenPlan[ColumnarPartialProjectExec]
     }
   }
+
+  test("GLUTEN-13655: posexplode ordinality with partial project") {
+    withSQLConf(
+      "spark.sql.ansi.enabled" -> "false",
+      GlutenConfig.EXPRESSION_BLACK_LIST.key -> "cast",
+      GlutenConfig.ENABLE_COLUMNAR_PARTIAL_PROJECT.key -> "true",
+      GlutenConfig.COLUMNAR_GENERATE_ENABLED.key -> "true"
+    ) {
+      // Blacklisting cast makes the JVM partial project read the native 
ordinality.
+      runQueryAndCompare("SELECT posexplode(array(l_orderkey, l_partkey)) FROM 
lineitem") {
+        df =>
+          checkGlutenPlan[GenerateExecTransformer](df)
+          checkGlutenPlan[ColumnarPartialProjectExec](df)
+      }
+    }
+  }
+
   // only SparkVersion >= 3.4 support columnar native writer
   testWithSpecifiedSparkVersion(
     "only the child and parent of the project both support Columnar," +


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to