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

zhztheplayer 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 5c2c44835d [GLUTEN-11912][VL] Translate Velox getbit position errors 
to Spark's exception (#13782)
5c2c44835d is described below

commit 5c2c44835d9c7e5d2678123956f1a5cfd3761597
Author: Pedrum Jalali <[email protected]>
AuthorDate: Mon Nov 30 02:06:24 2026 -0800

    [GLUTEN-11912][VL] Translate Velox getbit position errors to Spark's 
exception (#13782)
---
 .../vectorized/ColumnarBatchOutIterator.java       |  30 ++
 .../backends-velox/sql-tests/inputs/bitwise.sql    |  77 ------
 .../sql-tests/results/bitwise.sql.out              | 306 ---------------------
 .../utils/velox/VeloxSQLQueryTestSettings.scala    |   3 +-
 4 files changed, 31 insertions(+), 385 deletions(-)

diff --git 
a/gluten-arrow/src/main/java/org/apache/gluten/vectorized/ColumnarBatchOutIterator.java
 
b/gluten-arrow/src/main/java/org/apache/gluten/vectorized/ColumnarBatchOutIterator.java
index 8bb9ef5e75..6c8d553843 100644
--- 
a/gluten-arrow/src/main/java/org/apache/gluten/vectorized/ColumnarBatchOutIterator.java
+++ 
b/gluten-arrow/src/main/java/org/apache/gluten/vectorized/ColumnarBatchOutIterator.java
@@ -143,6 +143,13 @@ public class ColumnarBatchOutIterator extends 
ClosableIterator<ColumnarBatch>
   private static final Pattern CHAR_VARCHAR_LENGTH_EXCEEDED =
       Pattern.compile("Exceeds allowed length limitation: (\\d+)");
 
+  // Velox's messages when getbit's position is negative or not below the bit 
width of its input,
+  // e.g. "(-1 vs. 0) The value of 'pos' argument must be greater than or 
equal to zero.".
+  private static final Pattern INVALID_BIT_POSITION =
+      Pattern.compile(
+          "\\((-?\\d+) vs\\. -?\\d+\\) The value of 'pos' argument must "
+              + "(be greater than or equal to zero|not exceed the number of 
bits in 'x' - 1)\\.");
+
   // Velox's message when assert_not_null finds a null in a non-nullable field.
   private static final Pattern NOT_NULL_ASSERT_VIOLATED =
       Pattern.compile("^Reason: Null value appeared in non-nullable field$", 
Pattern.MULTILINE);
@@ -178,6 +185,25 @@ public class ColumnarBatchOutIterator extends 
ClosableIterator<ColumnarBatch>
         "EXCEED_LIMIT_LENGTH", new Map.Map1<>("limit", limit), e, new 
QueryContext[0], "");
   }
 
+  /**
+   * Translates a Velox getbit position check failure into the exception Spark 
3.x throws for a
+   * position outside the bits of its input. Returns null if the message does 
not indicate one.
+   */
+  private static RuntimeException 
translateToInvalidBitPositionException(String msg, Exception e) {
+    // Spark 4.x names the function, getbit or bit_get, in this error, and 
Velox's message does not.
+    if (SparkVersionUtil.gteSpark40()) {
+      return null;
+    }
+    Matcher matcher = INVALID_BIT_POSITION.matcher(msg);
+    if (!matcher.find()) {
+      return null;
+    }
+    String reason =
+        matcher.group(2).startsWith("be") ? "is less than zero" : "exceeds the 
bit upper limit";
+    return new IllegalArgumentException(
+        "Invalid bit position: " + matcher.group(1) + " " + reason, e);
+  }
+
   /**
    * Translates a Velox assert_not_null failure into the exception Spark 
throws for a null in a
    * non-nullable field. Returns null if the message does not indicate one.
@@ -210,6 +236,10 @@ public class ColumnarBatchOutIterator extends 
ClosableIterator<ColumnarBatch>
       if (lengthEx != null) {
         return lengthEx;
       }
+      RuntimeException bitPositionEx = 
translateToInvalidBitPositionException(msg, e);
+      if (bitPositionEx != null) {
+        return bitPositionEx;
+      }
       RuntimeException notNullEx = translateToNotNullAssertViolation(msg, e);
       if (notNullEx != null) {
         return notNullEx;
diff --git 
a/gluten-ut/spark35/src/test/resources/backends-velox/sql-tests/inputs/bitwise.sql
 
b/gluten-ut/spark35/src/test/resources/backends-velox/sql-tests/inputs/bitwise.sql
deleted file mode 100644
index f9dfd161d0..0000000000
--- 
a/gluten-ut/spark35/src/test/resources/backends-velox/sql-tests/inputs/bitwise.sql
+++ /dev/null
@@ -1,77 +0,0 @@
--- test cases for bitwise functions
-
--- null
-select bit_count(null);
-
--- boolean
-select bit_count(true);
-select bit_count(false);
-
--- byte/tinyint
-select bit_count(cast(1 as tinyint));
-select bit_count(cast(2 as tinyint));
-select bit_count(cast(3 as tinyint));
-
--- short/smallint
-select bit_count(1S);
-select bit_count(2S);
-select bit_count(3S);
-
--- int
-select bit_count(1);
-select bit_count(2);
-select bit_count(3);
-
--- long/bigint
-select bit_count(1L);
-select bit_count(2L);
-select bit_count(3L);
-
--- negative num
-select bit_count(-1L);
-
--- edge value
-select bit_count(9223372036854775807L);
-select bit_count(-9223372036854775808L);
-
--- other illegal arguments
-select bit_count("bit count");
-select bit_count('a');
-
--- test for bit_xor
---
-CREATE OR REPLACE TEMPORARY VIEW bitwise_test AS SELECT * FROM VALUES
-  (1, 1, 1, 1L),
-  (2, 3, 4, null),
-  (7, 7, 7, 3L) AS bitwise_test(b1, b2, b3, b4);
-
--- empty case
-SELECT BIT_XOR(b3) AS n1 FROM bitwise_test where 1 = 0;
-
--- null case
-SELECT BIT_XOR(b4) AS n1 FROM bitwise_test where b4 is null;
-
--- the suffix numbers show the expected answer
-SELECT
- BIT_XOR(cast(b1 as tinyint))  AS a4,
- BIT_XOR(cast(b2 as smallint))  AS b5,
- BIT_XOR(b3)  AS c2,
- BIT_XOR(b4)  AS d2,
- BIT_XOR(distinct b4) AS e2
-FROM bitwise_test;
-
--- group by
-SELECT bit_xor(b3) FROM bitwise_test GROUP BY b1 & 1;
-
---having
-SELECT b1, bit_xor(b2) FROM bitwise_test GROUP BY b1 HAVING bit_and(b2) < 7;
-
--- window
-SELECT b1, b2, bit_xor(b2) OVER (PARTITION BY b1 ORDER BY b2) FROM 
bitwise_test;
-
--- getbit
-select getbit(11L, 3), getbit(11L, 2), getbit(11L, 1), getbit(11L, 0);
-select getbit(11L, 2 + 1), getbit(11L, 3 - 1), getbit(10L + 1, 1 * 1), 
getbit(cast(11L / 1 AS long), 1 - 1);
-select getbit(11L, 63);
-select getbit(11L, -1);
-select getbit(11L, 64);
diff --git 
a/gluten-ut/spark35/src/test/resources/backends-velox/sql-tests/results/bitwise.sql.out
 
b/gluten-ut/spark35/src/test/resources/backends-velox/sql-tests/results/bitwise.sql.out
deleted file mode 100644
index 852e50f17b..0000000000
--- 
a/gluten-ut/spark35/src/test/resources/backends-velox/sql-tests/results/bitwise.sql.out
+++ /dev/null
@@ -1,306 +0,0 @@
--- Automatically generated by SQLQueryTestSuite
--- !query
-select bit_count(null)
--- !query schema
-struct<bit_count(NULL):int>
--- !query output
-NULL
-
-
--- !query
-select bit_count(true)
--- !query schema
-struct<bit_count(true):int>
--- !query output
-1
-
-
--- !query
-select bit_count(false)
--- !query schema
-struct<bit_count(false):int>
--- !query output
-0
-
-
--- !query
-select bit_count(cast(1 as tinyint))
--- !query schema
-struct<bit_count(CAST(1 AS TINYINT)):int>
--- !query output
-1
-
-
--- !query
-select bit_count(cast(2 as tinyint))
--- !query schema
-struct<bit_count(CAST(2 AS TINYINT)):int>
--- !query output
-1
-
-
--- !query
-select bit_count(cast(3 as tinyint))
--- !query schema
-struct<bit_count(CAST(3 AS TINYINT)):int>
--- !query output
-2
-
-
--- !query
-select bit_count(1S)
--- !query schema
-struct<bit_count(1):int>
--- !query output
-1
-
-
--- !query
-select bit_count(2S)
--- !query schema
-struct<bit_count(2):int>
--- !query output
-1
-
-
--- !query
-select bit_count(3S)
--- !query schema
-struct<bit_count(3):int>
--- !query output
-2
-
-
--- !query
-select bit_count(1)
--- !query schema
-struct<bit_count(1):int>
--- !query output
-1
-
-
--- !query
-select bit_count(2)
--- !query schema
-struct<bit_count(2):int>
--- !query output
-1
-
-
--- !query
-select bit_count(3)
--- !query schema
-struct<bit_count(3):int>
--- !query output
-2
-
-
--- !query
-select bit_count(1L)
--- !query schema
-struct<bit_count(1):int>
--- !query output
-1
-
-
--- !query
-select bit_count(2L)
--- !query schema
-struct<bit_count(2):int>
--- !query output
-1
-
-
--- !query
-select bit_count(3L)
--- !query schema
-struct<bit_count(3):int>
--- !query output
-2
-
-
--- !query
-select bit_count(-1L)
--- !query schema
-struct<bit_count(-1):int>
--- !query output
-64
-
-
--- !query
-select bit_count(9223372036854775807L)
--- !query schema
-struct<bit_count(9223372036854775807):int>
--- !query output
-63
-
-
--- !query
-select bit_count(-9223372036854775808L)
--- !query schema
-struct<bit_count(-9223372036854775808):int>
--- !query output
-1
-
-
--- !query
-select bit_count("bit count")
--- !query schema
-struct<>
--- !query output
-org.apache.spark.sql.catalyst.ExtendedAnalysisException
-{
-  "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE",
-  "sqlState" : "42K09",
-  "messageParameters" : {
-    "inputSql" : "\"bit count\"",
-    "inputType" : "\"STRING\"",
-    "paramIndex" : "1",
-    "requiredType" : "(\"INTEGRAL\" or \"BOOLEAN\")",
-    "sqlExpr" : "\"bit_count(bit count)\""
-  },
-  "queryContext" : [ {
-    "objectType" : "",
-    "objectName" : "",
-    "startIndex" : 8,
-    "stopIndex" : 29,
-    "fragment" : "bit_count(\"bit count\")"
-  } ]
-}
-
-
--- !query
-select bit_count('a')
--- !query schema
-struct<>
--- !query output
-org.apache.spark.sql.catalyst.ExtendedAnalysisException
-{
-  "errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE",
-  "sqlState" : "42K09",
-  "messageParameters" : {
-    "inputSql" : "\"a\"",
-    "inputType" : "\"STRING\"",
-    "paramIndex" : "1",
-    "requiredType" : "(\"INTEGRAL\" or \"BOOLEAN\")",
-    "sqlExpr" : "\"bit_count(a)\""
-  },
-  "queryContext" : [ {
-    "objectType" : "",
-    "objectName" : "",
-    "startIndex" : 8,
-    "stopIndex" : 21,
-    "fragment" : "bit_count('a')"
-  } ]
-}
-
-
--- !query
-CREATE OR REPLACE TEMPORARY VIEW bitwise_test AS SELECT * FROM VALUES
-  (1, 1, 1, 1L),
-  (2, 3, 4, null),
-  (7, 7, 7, 3L) AS bitwise_test(b1, b2, b3, b4)
--- !query schema
-struct<>
--- !query output
-
-
-
--- !query
-SELECT BIT_XOR(b3) AS n1 FROM bitwise_test where 1 = 0
--- !query schema
-struct<n1:int>
--- !query output
-NULL
-
-
--- !query
-SELECT BIT_XOR(b4) AS n1 FROM bitwise_test where b4 is null
--- !query schema
-struct<n1:bigint>
--- !query output
-NULL
-
-
--- !query
-SELECT
- BIT_XOR(cast(b1 as tinyint))  AS a4,
- BIT_XOR(cast(b2 as smallint))  AS b5,
- BIT_XOR(b3)  AS c2,
- BIT_XOR(b4)  AS d2,
- BIT_XOR(distinct b4) AS e2
-FROM bitwise_test
--- !query schema
-struct<a4:tinyint,b5:smallint,c2:int,d2:bigint,e2:bigint>
--- !query output
-4      5       2       2       2
-
-
--- !query
-SELECT bit_xor(b3) FROM bitwise_test GROUP BY b1 & 1
--- !query schema
-struct<bit_xor(b3):int>
--- !query output
-4
-6
-
-
--- !query
-SELECT b1, bit_xor(b2) FROM bitwise_test GROUP BY b1 HAVING bit_and(b2) < 7
--- !query schema
-struct<b1:int,bit_xor(b2):int>
--- !query output
-1      1
-2      3
-
-
--- !query
-SELECT b1, b2, bit_xor(b2) OVER (PARTITION BY b1 ORDER BY b2) FROM bitwise_test
--- !query schema
-struct<b1:int,b2:int,bit_xor(b2) OVER (PARTITION BY b1 ORDER BY b2 ASC NULLS 
FIRST RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW):int>
--- !query output
-1      1       1
-2      3       3
-7      7       7
-
-
--- !query
-select getbit(11L, 3), getbit(11L, 2), getbit(11L, 1), getbit(11L, 0)
--- !query schema
-struct<getbit(11, 3):tinyint,getbit(11, 2):tinyint,getbit(11, 
1):tinyint,getbit(11, 0):tinyint>
--- !query output
-1      0       1       1
-
-
--- !query
-select getbit(11L, 2 + 1), getbit(11L, 3 - 1), getbit(10L + 1, 1 * 1), 
getbit(cast(11L / 1 AS long), 1 - 1)
--- !query schema
-struct<getbit(11, (2 + 1)):tinyint,getbit(11, (3 - 1)):tinyint,getbit((10 + 
1), (1 * 1)):tinyint,getbit(CAST((11 / 1) AS BIGINT), (1 - 1)):tinyint>
--- !query output
-1      0       1       1
-
-
--- !query
-select getbit(11L, 63)
--- !query schema
-struct<getbit(11, 63):tinyint>
--- !query output
-0
-
-
--- !query
-select getbit(11L, -1)
--- !query schema
-struct<>
--- !query output
-org.apache.gluten.exception.GlutenException
-(-1 vs. 0) The value of 'pos' argument must be greater than or equal to zero.
-
-
--- !query
-select getbit(11L, 64)
--- !query schema
-struct<>
--- !query output
-org.apache.gluten.exception.GlutenException
-(64 vs. 64) The value of 'pos' argument must not exceed the number of bits in 
'x' - 1.
diff --git 
a/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/velox/VeloxSQLQueryTestSettings.scala
 
b/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/velox/VeloxSQLQueryTestSettings.scala
index c1bc6599cb..9a2875f96b 100644
--- 
a/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/velox/VeloxSQLQueryTestSettings.scala
+++ 
b/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/velox/VeloxSQLQueryTestSettings.scala
@@ -32,6 +32,7 @@ object VeloxSQLQueryTestSettings extends SQLQueryTestSettings 
{
   val SUPPORTED_SQL_QUERY_LIST: Set[String] = Set(
     "ansi/conditional-functions.sql",
     "ansi/decimalArithmeticOperations.sql",
+    "bitwise.sql",
     "cast.sql",
     "change-column.sql",
     "ceil-floor-with-scale-param.sql",
@@ -235,8 +236,6 @@ object VeloxSQLQueryTestSettings extends 
SQLQueryTestSettings {
     "linear-regression.sql",
     // Overwrite exception message.
     "array.sql",
-    // Overwrite exception message.
-    "bitwise.sql",
     // Enable NullPropagation rule for
     // "legacy behavior: allow calling function count without parameters".
     "count.sql",


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

Reply via email to