peter-toth commented on code in PR #52493:
URL: https://github.com/apache/spark/pull/52493#discussion_r2393862620


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -1142,6 +1142,52 @@ object SimplifyCaseConversionExpressions extends 
Rule[LogicalPlan] {
   }
 }
 
+/**
+ * Removes date and time related functions that are unnecessary.
+ */
+object SimplifyDateTimeConversions extends Rule[LogicalPlan] {
+  def apply(plan: LogicalPlan): LogicalPlan = plan.transformWithPruning(
+    _.containsPattern(DATETIME), ruleId) {
+    case q: LogicalPlan => q.transformExpressionsUpWithPruning(
+      _.containsPattern(DATETIME), ruleId) {
+      case DateFormatClass(
+          GetTimestamp(
+            e @ DateFormatClass(
+              _,
+              pattern,
+              timeZoneId),
+            pattern2,
+            TimestampType,
+            _,
+            timeZoneId2,
+            _),
+          pattern3,
+          timeZoneId3)
+          if pattern.semanticEquals(pattern2) && 
pattern.semanticEquals(pattern3)
+            && timeZoneId == timeZoneId2 && timeZoneId == timeZoneId3 =>
+        e
+      case GetTimestamp(
+          DateFormatClass(
+            e @ GetTimestamp(
+              _,
+              pattern,
+              TimestampType,
+              _,
+              timeZoneId,
+              _),
+            pattern2,
+            timeZoneId2),
+          pattern3,
+          TimestampType,

Review Comment:
   Yeah, looks nicer. Fixed in 
https://github.com/apache/spark/commit/dcf49a839962c1aa6e6bc46ea0f61aed8f7f627a



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -1142,6 +1142,52 @@ object SimplifyCaseConversionExpressions extends 
Rule[LogicalPlan] {
   }
 }
 
+/**
+ * Removes date and time related functions that are unnecessary.
+ */
+object SimplifyDateTimeConversions extends Rule[LogicalPlan] {
+  def apply(plan: LogicalPlan): LogicalPlan = plan.transformWithPruning(
+    _.containsPattern(DATETIME), ruleId) {
+    case q: LogicalPlan => q.transformExpressionsUpWithPruning(
+      _.containsPattern(DATETIME), ruleId) {
+      case DateFormatClass(
+          GetTimestamp(
+            e @ DateFormatClass(
+              _,
+              pattern,
+              timeZoneId),
+            pattern2,
+            TimestampType,
+            _,
+            timeZoneId2,
+            _),

Review Comment:
   Done in 
https://github.com/apache/spark/commit/dcf49a839962c1aa6e6bc46ea0f61aed8f7f627a



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