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

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


The following commit(s) were added to refs/heads/main by this push:
     new dbaeda3c3c update (#8957)
dbaeda3c3c is described below

commit dbaeda3c3c412a68e4138c5cb313640737d0f8f9
Author: Arnav Balyan <[email protected]>
AuthorDate: Fri Mar 21 07:57:45 2025 +0530

    update (#8957)
    
    offload Binary to string convert to velox
---
 .../sql/catalyst/expressions/VeloxCastSuite.scala      | 18 ++++++++++++++++--
 cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc   |  6 +++++-
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git 
a/backends-velox/src/test/scala/org/apache/spark/sql/catalyst/expressions/VeloxCastSuite.scala
 
b/backends-velox/src/test/scala/org/apache/spark/sql/catalyst/expressions/VeloxCastSuite.scala
index 9e40832f75..9a7a1413c5 100644
--- 
a/backends-velox/src/test/scala/org/apache/spark/sql/catalyst/expressions/VeloxCastSuite.scala
+++ 
b/backends-velox/src/test/scala/org/apache/spark/sql/catalyst/expressions/VeloxCastSuite.scala
@@ -28,15 +28,28 @@ class VeloxCastSuite extends 
VeloxWholeStageTransformerSuite with ExpressionEval
   def cast(v: Any, targetType: DataType, timeZoneId: Option[String] = None): 
Cast = {
     v match {
       case lit: Expression =>
-        logDebug(s"Cast from: ${lit.dataType.typeName}, to: 
${targetType.typeName}")
         Cast(lit, targetType, timeZoneId)
       case _ =>
         val lit = Literal(v)
-        logDebug(s"Cast from: ${lit.dataType.typeName}, to: 
${targetType.typeName}")
         Cast(lit, targetType, timeZoneId)
     }
   }
 
+  test("cast binary to string type") {
+
+    val testCases = Seq(
+      ("Hello, World!".getBytes, "Hello, World!"),
+      ("12345".getBytes, "12345"),
+      ("".getBytes, ""),
+      ("Some special characters: !@#$%^&*()".getBytes, "Some special 
characters: !@#$%^&*()"),
+      ("Line\nbreak".getBytes, "Line\nbreak")
+    )
+
+    for ((binaryValue, expectedString) <- testCases) {
+      checkEvaluation(cast(cast(binaryValue, BinaryType), StringType), 
expectedString)
+    }
+  }
+
   test("cast from double to timestamp format") {
     val originalDefaultTz = TimeZone.getDefault
     try {
@@ -65,6 +78,7 @@ class VeloxCastSuite extends VeloxWholeStageTransformerSuite 
with ExpressionEval
       TimeZone.setDefault(originalDefaultTz)
     }
   }
+
   override protected val resourcePath: String = "N/A"
   override protected val fileFormat: String = "N/A"
 }
diff --git a/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc 
b/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
index 21e43a7c7b..177cb8fcee 100644
--- a/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
+++ b/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
@@ -241,6 +241,9 @@ bool SubstraitToVeloxPlanValidator::isAllowedCast(const 
TypePtr& fromType, const
   // 2. Date to most categories except few supported types is not allowed.
   // 3. Timestamp to most categories except few supported types is not allowed.
   // 4. Certain complex types are not allowed.
+
+  auto toKind = toType->kind();
+
   // Don't support isIntervalYearMonth.
   if (fromType->isIntervalYearMonth() || toType->isIntervalYearMonth()) {
     LOG_VALIDATION_MSG("Casting involving INTERVAL_YEAR_MONTH is not 
supported.");
@@ -282,7 +285,8 @@ bool SubstraitToVeloxPlanValidator::isAllowedCast(const 
TypePtr& fromType, const
   }
 
   // Limited support for Complex types.
-  if (fromType->isArray() || fromType->isMap() || fromType->isRow() || 
fromType->isVarbinary()) {
+  if (fromType->isArray() || fromType->isMap() || fromType->isRow() ||
+      (fromType->isVarbinary() && toKind != TypeKind::VARCHAR)) {
     LOG_VALIDATION_MSG("Casting from " + fromType->toString() + " is not 
currently supported.");
     return false;
   }


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

Reply via email to