MaxGekk commented on code in PR #60285:
URL: https://github.com/apache/spark/pull/60285#discussion_r4535263534


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala:
##########
@@ -699,14 +699,23 @@ trait SupportQueryContext extends Expression with 
Serializable {
   //       empty "Origin" during rule transforms since "Origin"s are not 
serialized to executors
   //       for better performance. Thus, we need to copy the original query 
context during
   //       transforms. The query context string is considered as a "tag" on 
the expression here.
+  //       Like the tags of `TreeNode.copyTagsFrom`, it is copied only when 
this expression has
+  //       no context of its own: `None`, or one regenerated from an empty 
"Origin". A rule that
+  //       replaces a node with an existing expression, such as a child, then 
keeps the context
+  //       of the expression that raises the error instead of taking the 
context of the node.
   override def copyTagsFrom(other: Expression): Unit = {
     other match {
-      case s: SupportQueryContext =>
+      case s: SupportQueryContext if !hasOwnQueryContext =>
         queryContext = s.queryContext
       case _ =>
     }
     super.copyTagsFrom(other)
   }
+
+  private def hasOwnQueryContext: Boolean = queryContext.exists {
+    case c: SQLQueryContext => c.isValid

Review Comment:
   The check is gone in b43ba62096e. `copyTagsFrom` now tests only 
`s.queryContext.isDefined`, which is O(1).



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala:
##########
@@ -699,14 +699,23 @@ trait SupportQueryContext extends Expression with 
Serializable {
   //       empty "Origin" during rule transforms since "Origin"s are not 
serialized to executors
   //       for better performance. Thus, we need to copy the original query 
context during
   //       transforms. The query context string is considered as a "tag" on 
the expression here.
+  //       Like the tags of `TreeNode.copyTagsFrom`, it is copied only when 
this expression has
+  //       no context of its own: `None`, or one regenerated from an empty 
"Origin". A rule that
+  //       replaces a node with an existing expression, such as a child, then 
keeps the context
+  //       of the expression that raises the error instead of taking the 
context of the node.
   override def copyTagsFrom(other: Expression): Unit = {
     other match {
-      case s: SupportQueryContext =>
+      case s: SupportQueryContext if !hasOwnQueryContext =>

Review Comment:
   Not intended. With b43ba62096e the `Cast` of the function call gives its 
context to the body as before, since it has one, so the error keeps the 
`foo(c)` fragment of the user query.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala:
##########
@@ -699,14 +699,23 @@ trait SupportQueryContext extends Expression with 
Serializable {
   //       empty "Origin" during rule transforms since "Origin"s are not 
serialized to executors
   //       for better performance. Thus, we need to copy the original query 
context during
   //       transforms. The query context string is considered as a "tag" on 
the expression here.
+  //       Like the tags of `TreeNode.copyTagsFrom`, it is copied only when 
this expression has
+  //       no context of its own: `None`, or one regenerated from an empty 
"Origin". A rule that
+  //       replaces a node with an existing expression, such as a child, then 
keeps the context
+  //       of the expression that raises the error instead of taking the 
context of the node.
   override def copyTagsFrom(other: Expression): Unit = {
     other match {
-      case s: SupportQueryContext =>
+      case s: SupportQueryContext if !hasOwnQueryContext =>
         queryContext = s.queryContext
       case _ =>
     }
     super.copyTagsFrom(other)
   }
+
+  private def hasOwnQueryContext: Boolean = queryContext.exists {
+    case c: SQLQueryContext => c.isValid
+    case _ => true

Review Comment:
   With b43ba62096e the rule no longer changes these: the replaced `CAST(...)` 
and the DataFrame `cast` both have a context, which the replacement takes as 
before. The only new case is a replaced node without a context, where the 
replacement used to get `None`. The tests check both directions for the 
interval expressions: under an ANSI cast the expression takes the cast's 
context, and under a non-ANSI cast it keeps its own.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/intervalExpressions.scala:
##########
@@ -733,10 +733,17 @@ case class MultiplyDTInterval(
  * The division of an interval by a number. The interpreted path and the 
generated code both call
  * the `IntervalMathUtils.divide` overload for the interval type and the kind 
of the divisor, which
  * holds the checks and the error, so that the two paths cannot drift apart.
+ *
+ * The division raises on overflow and on a zero divisor in every mode, so it 
always keeps the

Review Comment:
   Reworded in b43ba62096e: the division has a query context in every mode, 
unlike `Divide`. With the narrowed rule, `copyTagsFrom` no longer copies 
`None`, so a division whose own context is empty keeps that one, and the 
exception has one empty `SQLQueryContext` as before.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala:
##########
@@ -699,14 +699,23 @@ trait SupportQueryContext extends Expression with 
Serializable {
   //       empty "Origin" during rule transforms since "Origin"s are not 
serialized to executors
   //       for better performance. Thus, we need to copy the original query 
context during
   //       transforms. The query context string is considered as a "tag" on 
the expression here.
+  //       Like the tags of `TreeNode.copyTagsFrom`, it is copied only when 
this expression has
+  //       no context of its own: `None`, or one regenerated from an empty 
"Origin". A rule that
+  //       replaces a node with an existing expression, such as a child, then 
keeps the context
+  //       of the expression that raises the error instead of taking the 
context of the node.
   override def copyTagsFrom(other: Expression): Unit = {
     other match {
-      case s: SupportQueryContext =>
+      case s: SupportQueryContext if !hasOwnQueryContext =>
         queryContext = s.queryContext
       case _ =>
     }
     super.copyTagsFrom(other)
   }
+
+  private def hasOwnQueryContext: Boolean = queryContext.exists {

Review Comment:
   Gone in b43ba62096e with the validity check.



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