zml1206 commented on code in PR #12048:
URL: https://github.com/apache/gluten/pull/12048#discussion_r3205615687


##########
gluten-substrait/src/main/scala/org/apache/gluten/expression/ExpressionConverter.scala:
##########
@@ -467,6 +467,34 @@ object ExpressionConverter extends SQLConfHelper with 
Logging {
       case s: ScalarSubquery =>
         ScalarSubqueryTransformer(substraitExprName, s)
       case c: Cast =>
+        // Gluten uses session-level timezone for cast. If the per-expression 
timezone
+        // differs from session timezone and the cast involves timestamp type, 
we must
+        // fall back to Spark native execution to ensure correctness.
+        // Note: Spark Cast applies zoneId recursively to array/map/struct 
elements,
+        // so we must check nested types as well.
+        c.timeZoneId.foreach {
+          tz =>
+            val sessionTz = SQLConf.get.sessionLocalTimeZone
+            if (tz != sessionTz) {
+              def containsTimestamp(dataType: DataType): Boolean = dataType 
match {
+                case TimestampType => true
+                case a: ArrayType => containsTimestamp(a.elementType)
+                case m: MapType =>
+                  containsTimestamp(m.keyType) || 
containsTimestamp(m.valueType)
+                case s: StructType => s.exists(f => 
containsTimestamp(f.dataType))
+                case udt: UserDefinedType[_] =>
+                  containsTimestamp(udt.sqlType)
+                case _ => false
+              }

Review Comment:
   Could we move `containsTimestamp` out of the `Cast` branch as a private 
helper method?
   The recursive type check is independent from the local `Cast` state, and 
keeping it as a small private helper would make the `Cast` branch easier to 
read. It also avoids redefining the local function on every visit and makes the 
logic easier to reuse if another timezone-sensitive expression needs the same 
nested timestamp check later.



-- 
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