This is an automated email from the ASF dual-hosted git repository.
mbudiu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new c8387a6e7d [CALCITE-7363] Improve error message for ASOF JOIN
c8387a6e7d is described below
commit c8387a6e7d9d67ce2577e24f11929696668a1a76
Author: Mihai Budiu <[email protected]>
AuthorDate: Thu Jan 8 11:37:38 2026 -0800
[CALCITE-7363] Improve error message for ASOF JOIN
Signed-off-by: Mihai Budiu <[email protected]>
---
.../java/org/apache/calcite/runtime/CalciteResource.java | 2 +-
.../apache/calcite/runtime/CalciteResource.properties | 2 +-
.../java/org/apache/calcite/test/SqlValidatorTest.java | 12 +++++++-----
server/src/test/resources/sql/type.iq | 16 ++++++++++++++++
4 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
b/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
index e3bc081496..124c5d5203 100644
--- a/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
+++ b/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
@@ -1151,7 +1151,7 @@ ExInst<RuntimeException>
multipleCapturingGroupsForRegexpFunctions(String value,
@BaseMessage("ASOF JOIN MATCH_CONDITION must be a comparison between columns
from the two inputs")
ExInst<SqlValidatorException> asofMatchMustBeComparison();
- @BaseMessage("ASOF JOIN condition must be a conjunction of equality
comparisons")
+ @BaseMessage("ASOF JOIN condition must be a conjunction of equality
comparisons of columns from both sides")
ExInst<SqlValidatorException> asofConditionMustBeComparison();
@BaseMessage("ASOF JOIN does not support correlated subqueries")
diff --git
a/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
b/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
index cf600b98cf..3ffb88a552 100644
---
a/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
+++
b/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
@@ -376,7 +376,7 @@ WindowInHavingNotAllowed=Window expressions are not
permitted in the HAVING clau
MatchConditionRequiresAsof=MATCH_CONDITION only allowed with ASOF JOIN
AsofRequiresMatchCondition=ASOF JOIN missing MATCH_CONDITION
AsofMatchMustBeComparison=ASOF JOIN MATCH_CONDITION must be a comparison
between columns from the two inputs
-AsofConditionMustBeComparison=ASOF JOIN condition must be a conjunction of
equality comparisons
+AsofConditionMustBeComparison=ASOF JOIN condition must be a conjunction of
equality comparisons of columns from both sides
AsofCannotBeCorrelated=ASOF JOIN does not support correlated subqueries
UnknownRowField=ROW type does not have a field named ''{0}'': {1}
IllegalRowIndexValue=ROW type does not have a field with index {0,number};
legal range is 1 to {1,number}
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
index 98c7ea665e..40cf5bddf8 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -3606,6 +3606,8 @@ void testWinPartClause() {
+ "on emp.ename = dept.name")
.fails(
"ASOF JOIN MATCH_CONDITION must be a comparison between columns
from the two inputs");
+ final String failMessage = "ASOF JOIN condition must be a conjunction of
equality comparisons "
+ + "of columns from both sides";
// match condition does not compare columns from both tables
sql("select emp.empno from emp asof join dept\n"
+ "match_condition ^emp.deptno < 12^\n"
@@ -3616,29 +3618,29 @@ void testWinPartClause() {
sql("select emp.empno from emp asof join dept\n"
+ "match_condition emp.deptno < dept.deptno\n"
+ "on ^emp.ename < 'foo'^")
- .fails("ASOF JOIN condition must be a conjunction of equality
comparisons");
+ .fails(failMessage);
// comparison contains an equality test that does not check both tables
joined
sql("select emp.empno from emp asof join dept\n"
+ "match_condition emp.deptno < dept.deptno\n"
+ "on ^emp.ename = 'foo'^")
- .fails("ASOF JOIN condition must be a conjunction of equality
comparisons");
+ .fails(failMessage);
// comparison contains is not a conjunction
sql("select emp.empno from emp asof join dept\n"
+ "match_condition emp.deptno < dept.deptno\n"
+ "on ^emp.ename = dept.name OR emp.deptno = dept.deptno^")
- .fails("ASOF JOIN condition must be a conjunction of equality
comparisons");
+ .fails(failMessage);
// comparison is not a conjunction
sql("select * from (VALUES(true, false)) AS T0(b0, b1)\n"
+ "asof join (VALUES(false, false)) AS T1(b0, b1)\n"
+ "match_condition T0.b0 < T1.b0\n"
+ "on ^T0.b1 AND T1.b1^")
- .fails("ASOF JOIN condition must be a conjunction of equality
comparisons");
+ .fails(failMessage);
// Condition contains a cast that is not applied to a column
sql("select * from (VALUES(true, false)) AS T0(b0, b1)\n"
+ "asof join (VALUES(false, 1)) AS T1(b0, b1)\n"
+ "match_condition T0.b0 < T1.b0\n"
+ "on ^T0.b1 = CAST(T1.b1 + 1 AS BOOLEAN)^")
- .fails("ASOF JOIN condition must be a conjunction of equality
comparisons");
+ .fails(failMessage);
}
/** Test case for
diff --git a/server/src/test/resources/sql/type.iq
b/server/src/test/resources/sql/type.iq
index 9aa2648efc..a63b8c58c1 100644
--- a/server/src/test/resources/sql/type.iq
+++ b/server/src/test/resources/sql/type.iq
@@ -18,6 +18,22 @@
!use server
!set outputformat mysql
+CREATE TABLE asof_tbl(intt INT, arr VARCHAR ARRAY );
+(0 rows modified)
+
+!update
+
+SELECT * FROM asof_tbl t1
+LEFT ASOF JOIN asof_tbl AS t2
+MATCH_CONDITION (t1.intt >= t2.intt)
+ON t1.arr[2] = t2.arr[2];
+java.sql.SQLException: Error while executing SQL "SELECT * FROM asof_tbl t1
+LEFT ASOF JOIN asof_tbl AS t2
+MATCH_CONDITION (t1.intt >= t2.intt)
+ON t1.arr[2] = t2.arr[2]": From line 4, column 4 to line 4, column 24: ASOF
JOIN condition must be a conjunction of equality comparisons of columns from
both sides
+
+!error
+
create type myint1 as int;
(0 rows modified)