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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/intervalExpressions.scala:
##########
@@ -733,10 +733,18 @@ 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 
has a query context
+ * in every mode, unlike `Divide`, whose context is set only under ANSI. It 
keeps it as a
+ * `SupportQueryContext` field rather than reading `origin` when it evaluates: 
`origin` is not
+ * serialized, so a copy of the expression deserialized on an executor, where 
an interpreted or a
+ * non-whole-stage projection is built, has an empty one.
  */
-trait IntervalDivide extends BinaryExpression {
+trait IntervalDivide extends BinaryExpression with SupportQueryContext {
+  override def initQueryContext(): Option[QueryContext] = Some(origin.context)

Review Comment:
   Confirmed by running your example: with ANSI on, (2) reports the fragment 
`CAST(d AS INTERVAL YEAR TO MONTH)` of (1), with whole-stage codegen on and 
off. Agreed that the fix belongs in `copyTagsFrom`, for every 
`SupportQueryContext` expression, not in this PR. I opened SPARK-61467 for it 
and linked it in the PR description.



##########
sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionAnsiErrorsSuite.scala:
##########
@@ -115,6 +116,36 @@ class QueryExecutionAnsiErrorsSuite extends 
SharedSparkSession {
       context = ExpectedContext(fragment = "interval 1 day / 0", start = 7, 
stop = 24))
   }
 
+  test("SPARK-61352: an interval division error keeps its query context") {

Review Comment:
   Added in c446a316109: `spark.range(1).select(expr("CAST(id + 1 AS INTERVAL 
DAY)") / $"id".cast("int"))` with whole-stage codegen on and off, checking 
`fragment = "div"` and `callSitePattern = getCurrentClassCallSitePattern`.



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