matvei-zamiatin-db commented on code in PR #58119:
URL: https://github.com/apache/spark/pull/58119#discussion_r3814855087


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/finishAnalysis.scala:
##########
@@ -112,106 +112,128 @@ object EvalInlineTables extends Rule[LogicalPlan] with 
CastSupport {
  */
 object ComputeCurrentTime extends Rule[LogicalPlan] {
   def apply(plan: LogicalPlan): LogicalPlan = {
-    val instant = Instant.now()
-    val currentTimestampMicros = instantToMicros(instant)
-    val currentTime = Literal.create(currentTimestampMicros, TimestampType)
-    val currentTimeOfDayNanos = instantToNanosOfDay(instant, 
conf.sessionLocalTimeZone)
-    val timezone = Literal.create(conf.sessionLocalTimeZone, StringType)
+    val snapshot = new TimeSnapshot(Instant.now())
+    plan.transformDownWithSubqueriesAndPruning(transformCondition) {
+      case subQuery =>
+        subQuery.transformAllExpressionsWithPruning(transformCondition)(
+          expressionTransform(snapshot))
+    }
+  }
+
+  /** Rewrites the current date/time functions in a single expression tree. */
+  def applyForExpression(expression: Expression): Expression =
+    applyForExpression(expression, Instant.now())
+
+  /**
+   * Rewrites the current date/time functions in a single expression tree 
using `instant`. Callers
+   * reducing several expressions that must observe the same wall clock pass 
one shared instant.
+   */
+  def applyForExpression(expression: Expression, instant: Instant): Expression 
= {
+    val snapshot = new TimeSnapshot(instant)
+    
expression.transformWithPruning(transformCondition)(expressionTransform(snapshot))

Review Comment:
   Added comment for every `applyForExpression`:
   ```
   Does not descend into subquery plans (e.g. `ScalarSubquery`). A caller whose 
expression
   may contain a subquery must rewrite those plans separately.
   ```
   
   Since we want to use it only for procedure's arguments reducing, where 
ScalarSubquery is prohibited, it should work fine



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