LukaZdravic commented on code in PR #59102:
URL: https://github.com/apache/spark/pull/59102#discussion_r4142657548
##########
sql/core/src/test/scala/org/apache/spark/sql/AsOfJoinSortMergeSQLSuite.scala:
##########
@@ -728,6 +748,111 @@ class AsOfJoinSortMergeSQLSuite extends QueryTest
Row(Seq(1, 6)) :: Nil)
}
+ test("forward MATCH_CONDITION with NULL array elements picks the smallest
right row") {
+ // NULL elements sort first: [null] < [null, null] < [5].
+ val nullInt = "CAST(NULL AS INT)"
+ for {
+ (left, rights) <- Seq(
+ s"ARRAY($nullInt)" -> s"(ARRAY($nullInt, $nullInt), 'nn'), (ARRAY(5),
'five')")
+ op <- Seq("<=", "<")
+ } {
+ checkSortMergeAsOf(
+ sql(
+ s"""
+ |SELECT r.tag
+ |FROM VALUES ($left) AS t(a)
+ |ASOF JOIN VALUES $rights AS r(a, tag)
+ | MATCH_CONDITION (t.a $op r.a)
+ |""".stripMargin),
+ Row("nn") :: Nil)
+ }
+ }
+
+ test("forward MATCH_CONDITION with a NULL struct field picks the smallest
right row") {
+ // A NULL field sorts first, so {null, 7} < {x, 1}.
+ for {
+ (nullField, value) <- Seq("CAST(NULL AS INT)" -> "0")
+ (left, right) <- Seq("t.k" -> "r.k", "(t.k.f, t.k.seq)" -> "(r.k.f,
r.k.seq)")
+ op <- Seq("<=", "<")
+ } {
+ checkSortMergeAsOf(
+ sql(
+ s"""
+ |SELECT r.tag
+ |FROM VALUES (named_struct('f', $nullField, 'seq', 5)) AS t(k)
+ |ASOF JOIN VALUES
+ | (named_struct('f', $nullField, 'seq', 7), 's7'),
+ | (named_struct('f', $value, 'seq', 1), 's1') AS r(k, tag)
+ | MATCH_CONDITION ($left $op $right)
+ |""".stripMargin),
+ Row("s7") :: Nil)
+ }
+ }
+
+ test("forward MATCH_CONDITION with a leading STRING field picks the smallest
right row") {
+ // {c, 1} < {d, 0}. The STRING field distance is 1 for both, so a distance
picks {d, 0}.
+ for {
+ (left, right) <- Seq("t.k" -> "r.k", "(t.k.s, t.k.n)" -> "(r.k.s,
r.k.n)")
+ op <- Seq("<=", "<")
+ } {
+ checkSortMergeAsOf(
+ sql(
+ s"""
+ |SELECT r.tag
+ |FROM VALUES (named_struct('s', 'b', 'n', 5)) AS t(k)
+ |ASOF JOIN VALUES
+ | (named_struct('s', 'c', 'n', 1), 'c1'),
+ | (named_struct('s', 'd', 'n', 0), 'd0') AS r(k, tag)
+ | MATCH_CONDITION ($left $op $right)
+ |""".stripMargin),
+ Row("c1") :: Nil)
+ }
+ }
+
+ test("forward MATCH_CONDITION skips a closer row that fails a non-equi ON
predicate") {
+ checkSortMergeAsOf(
+ sql(
+ """
+ |SELECT r.k
+ |FROM VALUES (10, 5) AS t(k, lim)
+ |ASOF JOIN VALUES (12, 9), (15, 1), (20, 0) AS r(k, v)
+ | MATCH_CONDITION (t.k <= r.k)
+ | ON r.v < t.lim
+ |""".stripMargin),
+ Row(15) :: Nil)
+ }
+
+ // The far row makes (right - left) too big for the type, so a
distance-based scan would fail.
+ Seq(
+ ("INT", "-100", "-50", "2147483647"),
+ ("BIGINT", "-100", "-50", "9223372036854775807"),
+ ("DECIMAL(38, 0)", "-99999999999999999999999999999999999999", "1", "2"),
Review Comment:
Fixed, thanks
--
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]