dongjoon-hyun commented on code in PR #60392:
URL: https://github.com/apache/spark/pull/60392#discussion_r4620211120
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala:
##########
@@ -1039,8 +1039,25 @@ trait CheckAnalysis extends LookupCatalog with
QueryErrorsBase with PlanToString
varName,
c.defaultExpr.originalSQL)
- case c: Call if c.resolved && c.bound && c.checkArgTypes().isFailure
=>
+ case c: Call if c.resolved =>
Review Comment:
**[17] The PR description no longer matches this branch, and it leaves out
two user-facing changes.**
GitHub cannot take an inline comment on the description, so I put this on
the code that it describes.
- The third bullet under "Now:" says that CheckAnalysis fails a resolved
`Call` that is not bound with `INTERNAL_ERROR`. Since ff86e7b, a CALL with a
`window(...)` or `session_window(...)` argument fails here with
`UNSUPPORTED_EXPR_FOR_OPERATOR`, and `INTERNAL_ERROR` is left for plans that an
extension builds.
- The user-facing section does not mention that `CALL
cat.ns.p(window(TIMESTAMP '2026-01-01 00:00:00', '1 hour'))` now fails analysis
with `UNSUPPORTED_EXPR_FOR_OPERATOR`. On master, `sql()` returns without
invoking the procedure, `EXPLAIN` prints a plan, and `collect()` throws
`UnsupportedOperationException`.
- It also does not mention a nondeterministic argument whose type cannot be
implicitly cast to the parameter type, as in the new test `CALL
cat.ns.simple_date(rand())`. It now fails with
`DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE`. On master, `InvokeProcedures` skips
it because the type check fails. Then `PullOutNondeterministic` puts a
`Project` under the `Call`, so `bound` is false and CheckAnalysis skips the
type check. The statement passes analysis without invoking the procedure, and
`collect()` throws `UnsupportedOperationException`.
- "Seven new tests" is now eight, and the list of the others leaves out
`SPARK-61506: a CALL with a time window argument fails analysis`.
Both changes are fixes, so a few lines in the description would cover them.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala:
##########
@@ -1039,8 +1039,25 @@ trait CheckAnalysis extends LookupCatalog with
QueryErrorsBase with PlanToString
varName,
c.defaultExpr.originalSQL)
- case c: Call if c.resolved && c.bound && c.checkArgTypes().isFailure
=>
+ case c: Call if c.resolved =>
+ if (!c.bound) {
+ val invalidExprSqls = c.args.map {
+ case NamedArgumentExpression(_, value) => value
+ case arg => arg
+ }.filter(_.references.nonEmpty).map(toSQLExpr)
Review Comment:
**[18] Nit: with a time window argument, this list leaves out the other
unsupported arguments.**
This branch lists only the arguments that read the operator under the
`Call`, and it fails before the generic check (`CheckAnalysis.scala:1222-1229`)
can list aggregate and window functions. For example:
```sql
CALL cat.ns.sum(window(TIMESTAMP '2026-01-01 00:00:00', '1 hour'), IF(true
OR max(1) > 0, 1, 2))
```
On master this fails with `UNSUPPORTED_EXPR_FOR_OPERATOR` and lists
`"max(1)"`, which is what the SPARK-61889 test on master expects for the same
`IF(...)` argument. Here it lists only `"window"`, because `max(1)` has no
references. The error class does not change, only the list. Appending
`PlanHelper.specialExpressionsInUnsupportedOperator(c).map(toSQLExpr)` to
`invalidExprSqls` would keep both.
##########
sql/core/src/test/scala/org/apache/spark/sql/connector/ProcedureSuite.scala:
##########
@@ -1098,6 +1234,59 @@ class ProcedureSuite extends SharedSparkSession with
BeforeAndAfter {
override def description: String = "simple sum integers"
}
+ abstract class TimestampProcedure extends BoundProcedure {
+ override def description: String = "returns a timestamp and an optional
label"
+
+ override def isDeterministic: Boolean = true
+
+ override def parameters: Array[ProcedureParameter] = Array(
+ ProcedureParameter.in("ts", DataTypes.TimestampType).build(),
+ ProcedureParameter.in("label",
DataTypes.StringType).defaultValue("'none'").build())
+
+ def outputType: StructType = new StructType()
+ .add("ts", DataTypes.TimestampType)
+ .add("label", DataTypes.StringType)
+
+ override def call(input: InternalRow): java.util.Iterator[Scan] = {
+ val result = Result(outputType, Array(InternalRow(input.getLong(0),
input.getUTF8String(1))))
+ Collections.singleton[Scan](result).iterator()
+ }
+ }
+
+ object SimpleTimestampProcedure extends TimestampProcedure with
SimpleProcedure {
+ override def name: String = "simple_ts"
+ }
+
+ class RebindingTimestampProcedure(binds: AtomicInteger, isBound: Boolean)
+ extends TimestampProcedure with UnboundProcedure {
+
+ override def name: String = "rebinding_ts"
+
+ override def bind(inputType: StructType): BoundProcedure = {
+ binds.incrementAndGet()
+ new RebindingTimestampProcedure(binds, isBound = true)
+ }
+
+ override def parameters: Array[ProcedureParameter] = {
+ assert(isBound, "only the procedure returned by bind can be used")
+ super.parameters
+ }
+
+ override def call(input: InternalRow): java.util.Iterator[Scan] = {
+ assert(isBound, "only the procedure returned by bind can be used")
+ super.call(input)
+ }
+ }
+
+ object SimpleDateProcedure extends SimpleProcedure {
Review Comment:
**[19] Nit (optional): `SimpleTimestampProcedure` could replace this
fixture.**
`SimpleDateProcedure` is used only by `SPARK-61506: CALL with a
nondeterministic argument of the wrong type`. There is no implicit cast from
DOUBLE to TIMESTAMP either, in ANSI or non-ANSI mode, so this checks the same
thing:
```scala
catalog.createProcedure(Identifier.of(Array("ns"), "simple_ts"),
SimpleTimestampProcedure)
val call = "CALL cat.ns.simple_ts(rand(), 'x')"
```
with `"requiredType" -> toSQLType("TIMESTAMP")`. The `'x'` matters: without
it, master fails earlier on `require(args.length == params.length)` and does
not reach the case this test is about. Keeping DATE is fine too, since DOUBLE
cannot be cast to DATE even explicitly.
--
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]