LukaZdravic commented on code in PR #58657:
URL: https://github.com/apache/spark/pull/58657#discussion_r4016599525
##########
sql/core/src/test/scala/org/apache/spark/sql/AsOfJoinSQLSuite.scala:
##########
@@ -242,6 +260,27 @@ class AsOfJoinSQLSuite extends QueryTest with
SharedSparkSession {
assert(asOfJoin.asOfCondition.resolved)
}
+ test("MATCH_CONDITION with two literal operands passes analysis") {
+ setupTradeQuoteViews()
+ val sqlText =
+ """
+ |SELECT count(*)
+ |FROM trades t ASOF JOIN quotes q
+ | MATCH_CONDITION (TIMESTAMP '2026-06-29 10:00:00' >= TIMESTAMP
'2026-06-29 09:00:00')
+ | ON t.symbol = q.symbol
+ |""".stripMargin
+ // Both operands are literals with no column refs, so each takes its
syntactic side
+ // (expr1 = left, expr2 = right) and the MATCH_CONDITION materializes.
+ val asOfJoin = sql(sqlText).queryExecution.analyzed.collectFirst {
+ case j: AsOfJoin => j
+ }.get
+ // Populated sort keys prove the operands were assigned to opposite sides
and the condition
Review Comment:
These nonEmpty checks can't fail here; for two literals the sort keys are
always populated, and .get already guarantees the join materialized. The real
proof is that analysis didn't throw ASOF_JOIN_MATCH_CONDITION_TABLE_REFERENCE.
Assert matchLeftOperand.isEmpty like the sibling at line 104, or drop these
two asserts.
##########
sql/core/src/test/scala/org/apache/spark/sql/AsOfJoinSQLSuite.scala:
##########
@@ -336,6 +375,22 @@ class AsOfJoinSQLSuite extends QueryTest with
SharedSparkSession {
assert(asOfJoin.rightSortExprs.nonEmpty)
}
+ test("ARRAY<STRUCT> MATCH_CONDITION with mismatched element names and types
is rejected") {
+ // Element structs differ in name (x vs y) and type (INT vs BIGINT).
+ // Widening differing types requires matching field names, so the query
fails.
+ val sqlText =
+ """
+ |SELECT r.a
+ |FROM VALUES (ARRAY(named_struct('x', CAST(5 AS INT)))) AS t(a)
+ |ASOF JOIN (
+ | SELECT * FROM VALUES (ARRAY(named_struct('y', CAST(5 AS BIGINT))))
AS r(a)
+ |) r
+ | MATCH_CONDITION (t.a >= r.a)
+ |""".stripMargin
+ val e = intercept[AnalysisException](sql(sqlText))
+ assert(e.getCondition == "DATATYPE_MISMATCH.BINARY_OP_DIFF_TYPES")
Review Comment:
Other reject tests use checkError, which also pins the two mismatched types;
this bare == passes even if the wrong types are reported. Prefer checkError, or
at least use ===.
##########
sql/core/src/test/scala/org/apache/spark/sql/AsOfJoinSQLSuite.scala:
##########
@@ -336,6 +375,22 @@ class AsOfJoinSQLSuite extends QueryTest with
SharedSparkSession {
assert(asOfJoin.rightSortExprs.nonEmpty)
}
+ test("ARRAY<STRUCT> MATCH_CONDITION with mismatched element names and types
is rejected") {
+ // Element structs differ in name (x vs y) and type (INT vs BIGINT).
Review Comment:
Nit
The ASOF operand check accepts these ARRAY<STRUCT> operands (it compares
struct fields positionally and ignores names). But ASOF re-aligns names only
for struct tuples, not inside arrays, so the query fails on the generic
name-sensitive comparison check (BINARY_OP_DIFF_TYPES), not on ASOF validation.
Worth a one-line note so a reader doesn't read this as ASOF-specific.
--
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]