nookcreed commented on code in PR #13796:
URL: https://github.com/apache/gluten/pull/13796#discussion_r4735551325


##########
backends-velox/src/main/scala/org/apache/gluten/expression/ExpressionTransformer.scala:
##########
@@ -41,6 +41,30 @@ case class VeloxAliasTransformer(
   }
 }
 
+case class VeloxToJsonInputTransformer(child: ExpressionTransformer)
+  extends UnaryExpressionTransformer {
+  override def substraitExprName: String = "cast"
+  override def original: Expression = child.original
+
+  override def doTransform(context: SubstraitContext): ExpressionNode = {
+    // Spark's struct field names are JSON keys, not case-insensitive column 
references.
+    // Restore them by position without changing the field types or the rest 
of the plan.
+    val inputType = ConverterUtils.getTypeNode(dataType, nullable, 
preserveStructFieldNames = true)
+    ExpressionBuilder.makeCast(inputType, child.doTransform(context), 
CastNode.CastMode.LEGACY)

Review Comment:
   Added a regression in 69df41c2. On the same Parquet input, the lowercase-key 
timestamp struct still runs in Velox, while the mixed-case version falls back 
to Spark and returns matching JSON. I kept cast validation unchanged to keep 
this PR scoped to `to_json`. All 18 tests in `JsonFunctionsValidateSuite` 
passed on Spark 3.5.5 with Velox.



##########
backends-velox/src/test/scala/org/apache/gluten/functions/JsonFunctionsValidateSuite.scala:
##########
@@ -425,12 +425,35 @@ class JsonFunctionsValidateSuite extends 
FunctionsValidateSuite {
       }
 
       runQueryAndCompare("select to_json(e) from t") {
+        checkGlutenPlan[ProjectExecTransformer]
+      }
+
+      runQueryAndCompare("select to_json(array(named_struct('aA', a))) from 
t") {
+        checkGlutenPlan[ProjectExecTransformer]
+      }
+
+      runQueryAndCompare(
+        "select to_json(named_struct('outer', named_struct('UserId', a, 
'userid', b))) from t") {
+        checkGlutenPlan[ProjectExecTransformer]
+      }
+
+      runQueryAndCompare("select to_json(map('key', named_struct('UserId', 
a))) from t") {
+        checkGlutenPlan[ProjectExecTransformer]
+      }
+
+      runQueryAndCompare("select to_json(e, map('ignoreNullFields', 'false')) 
from t") {
         checkSparkPlan[ProjectExec]
       }
 
-      runQueryAndCompare("select to_json(Array(named_struct('aA', a))) from 
t") {
+      runQueryAndCompare("""select to_json(named_struct('A"B', a)) from t""") {

Review Comment:
   Added `a"b` alongside `A"B` in 69df41c2. Both cases now check that the 
projection uses Spark and returns the same escaped JSON as vanilla Spark. The 
lowercase case exercises the path that does not need a field rename. All 18 
tests in `JsonFunctionsValidateSuite` passed.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to