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

richox pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/auron.git


The following commit(s) were added to refs/heads/master by this push:
     new a0d94d40 [AURON #1688] Fix type mismatch: cast lpad/rpad len (2nd arg) 
to LongType (#1689)
a0d94d40 is described below

commit a0d94d4066c8d7406695584550dc2f9b969acae0
Author: Thomas <[email protected]>
AuthorDate: Thu Dec 11 17:25:18 2025 +0800

    [AURON #1688] Fix type mismatch: cast lpad/rpad len (2nd arg) to LongType 
(#1689)
    
    # Which issue does this PR close?
    
    Closes #1688 .
    
     # Rationale for this change
    Current lpad/rpad functions use the DataFusion implementation. Native
    execution panics when the len (2nd arg) is INT (Int32), because
    DataFusion expects len to be Int64, leading to a cast failure.
    ```
    Caused by: java.lang.RuntimeException: java.lang.RuntimeException: poll 
record batch error:
    Execution error: native execution panics: Execution error: Execution error: 
output_with_sender[Project] error:
    Execution error: output_with_sender[Project]: output() returns error:
    Internal error: could not cast array of type Int32 to
    
arrow_array::array::primitive_array::PrimitiveArray<arrow_array::types::Int64Type>
    ```
    
    # What changes are included in this PR?
    - cast len (2nd arg) to LongType in NativeConverters for lpad/rpad.
    
    # Are there any user-facing changes?
    
    # How was this patch tested?
    unit tests.
    
    ---------
    
    Co-authored-by: Shreyesh <[email protected]>
---
 .../scala/org.apache.auron/AuronQuerySuite.scala   | 32 ++++++++++++----------
 .../apache/spark/sql/auron/NativeConverters.scala  | 14 +++++++---
 2 files changed, 28 insertions(+), 18 deletions(-)

diff --git 
a/spark-extension-shims-spark/src/test/scala/org.apache.auron/AuronQuerySuite.scala
 
b/spark-extension-shims-spark/src/test/scala/org.apache.auron/AuronQuerySuite.scala
index ccd9f0e5..eeb24975 100644
--- 
a/spark-extension-shims-spark/src/test/scala/org.apache.auron/AuronQuerySuite.scala
+++ 
b/spark-extension-shims-spark/src/test/scala/org.apache.auron/AuronQuerySuite.scala
@@ -281,20 +281,24 @@ class AuronQuerySuite extends AuronQueryTest with 
BaseAuronSQLSuite with AuronSQ
   }
 
   test("lpad/rpad basic") {
-    Seq(
-      ("select lpad('abc', 5, '*')", Row("**abc")),
-      ("select rpad('abc', 5, '*')", Row("abc**")),
-      ("select lpad('spark', 2, '0')", Row("sp")),
-      ("select rpad('spark', 2, '0')", Row("sp")),
-      ("select lpad('9', 5, 'ab')", Row("abab9")),
-      ("select rpad('9', 5, 'ab')", Row("9abab")),
-      ("select lpad('hi', 5, '')", Row("hi")),
-      ("select rpad('hi', 5, '')", Row("hi")),
-      ("select lpad('x', 0, 'a')", Row("")),
-      ("select rpad('x', -1, 'a')", Row("")),
-      ("select lpad('Z', 3, '++')", Row("++Z")),
-      ("select rpad('Z', 3, 'AB')", Row("ZAB"))).foreach { case (q, expected) 
=>
-      checkAnswer(sql(q), Seq(expected))
+    withTable("pad_tbl") {
+      sql(s"CREATE TABLE pad_tbl(id INT, txt STRING, len INT, pad STRING) 
USING parquet")
+      sql(s"""
+             |INSERT INTO pad_tbl VALUES
+             | (1, 'abc', 5, ''),
+             | (2, 'abc', 5, ' '),
+             | (3, 'spark', 2, '0'),
+             | (4, 'spark', 2, '0'),
+             | (5, '9', 5, 'ab'),
+             | (6, '9', 5, 'ab'),
+             | (7, 'hi', 5, ''),
+             | (8, 'hi', 5, ''),
+             | (9, 'x', 0, 'a'),
+             | (10,'x', -1, 'a'),
+             | (11,'Z', 3, '++'),
+             | (12,'Z', 3, 'AB')
+      """.stripMargin)
+      checkSparkAnswerAndOperator("SELECT LPAD(txt, len, pad), RPAD(txt, len, 
pad) FROM pad_tbl")
     }
   }
 
diff --git 
a/spark-extension/src/main/scala/org/apache/spark/sql/auron/NativeConverters.scala
 
b/spark-extension/src/main/scala/org/apache/spark/sql/auron/NativeConverters.scala
index 677de319..153e2b8e 100644
--- 
a/spark-extension/src/main/scala/org/apache/spark/sql/auron/NativeConverters.scala
+++ 
b/spark-extension/src/main/scala/org/apache/spark/sql/auron/NativeConverters.scala
@@ -984,10 +984,16 @@ object NativeConverters extends Logging {
         val children = e.children.map(Cast(_, e.dataType))
         buildScalarFunction(pb.ScalarFunction.Coalesce, children, e.dataType)
 
-      case e: StringLPad =>
-        buildScalarFunction(pb.ScalarFunction.Lpad, e.children, StringType)
-      case e: StringRPad =>
-        buildScalarFunction(pb.ScalarFunction.Rpad, e.children, StringType)
+      case e @ StringLPad(str, len, pad) =>
+        buildScalarFunction(
+          pb.ScalarFunction.Lpad,
+          Seq(str, castIfNecessary(len, LongType), pad),
+          StringType)
+      case e @ StringRPad(str, len, pad) =>
+        buildScalarFunction(
+          pb.ScalarFunction.Rpad,
+          Seq(str, castIfNecessary(len, LongType), pad),
+          StringType)
 
       case e @ If(predicate, trueValue, falseValue) =>
         val castedTrueValue = trueValue match {

Reply via email to