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


##########
sql/core/src/test/scala/org/apache/spark/sql/connector/ProcedureSuite.scala:
##########
@@ -494,6 +494,17 @@ class ProcedureSuite extends SharedSparkSession with 
BeforeAndAfter {
     assert(explain.contains("Call cat.ns.sum(5, 5)"), explain)
   }
 
+  test("SPARK-61889: CALL with an aggregate or window function in an 
argument") {
+    // The optimizer folds these arguments away, so the procedure must not be 
invoked.
+    catalog.createProcedure(Identifier.of(Array("ns"), "sum"), 
UnboundNonExecutableSum)
+    val call = "CALL cat.ns.sum(IF(true OR max(1) > 0, 1, 2), 2)"
+    checkError(
+      exception = intercept[AnalysisException](sql(call)),
+      condition = "UNSUPPORTED_EXPR_FOR_OPERATOR",
+      parameters = Map("operator" -> "Call", "invalidExprSqls" -> 
"\"max(1)\""),
+      context = ExpectedContext(fragment = call, start = 0, stop = call.length 
- 1))
+  }

Review Comment:
   **Finding 2.** The test name and the PR title mention window and generator 
expressions, but only the aggregate is checked. With 
`spark.sql.planChangeValidation=false`, both of the other shapes invoke the 
procedure on base. The generator also fails with a different error. It gets 
`UNSUPPORTED_GENERATOR.OUTSIDE_SELECT`, the same as `EXPLAIN CALL`. These lines 
pass on this head, and each statement fails on base with 
`PLAN_VALIDATION_FAILED_RULE_EXECUTOR`:
   
   ```suggestion
       val windowCall = "CALL cat.ns.sum(IF(true OR row_number() OVER (ORDER BY 
1) > 0, 1, 2), 2)"
       checkError(
         exception = intercept[AnalysisException](sql(windowCall)),
         condition = "UNSUPPORTED_EXPR_FOR_OPERATOR",
         parameters = Map(
           "operator" -> "Call",
           "invalidExprSqls" -> ("\"row_number() OVER (ORDER BY 1 ASC NULLS 
FIRST " +
             "ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)\"")),
         context = ExpectedContext(fragment = windowCall, start = 0, stop = 
windowCall.length - 1))
       checkError(
         exception = intercept[AnalysisException] {
           sql("CALL cat.ns.sum(IF(true OR size(explode(array(1))) > 0, 1, 2), 
2)")
         },
         condition = "UNSUPPORTED_GENERATOR.OUTSIDE_SELECT",
         parameters = Map("plan" -> "(?s)Call cat.ns.sum.*"),
         matchPVals = true)
     }
   ```
   
   With the generator in, the test name could say "aggregate, window or 
generator expression".
   



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