Skip to content

Commit c3f5cab

Browse files
committed
check MATCH_CONDITION must specify column from both table
1 parent 7b752e2 commit c3f5cab

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,12 @@ private LogicalJoin<Plan, Plan> bindJoin(MatchingContext<LogicalJoin<Plan, Plan>
703703
if (conjunct instanceof ComparisonPredicate) {
704704
if (conjunct.child(0).getDataType().isDateLikeType()
705705
&& conjunct.child(1).getDataType().isDateLikeType()) {
706+
Set<Slot> leftSlots = join.left().getOutputSet();
707+
Set<Slot> rightSlots = join.right().getOutputSet();
708+
Set<Slot> usedSlots = conjunct.getInputSlots();
709+
if (leftSlots.containsAll(usedSlots) || rightSlots.containsAll(usedSlots)) {
710+
throw new AnalysisException("MATCH_CONDITION must specify column from both table");
711+
}
706712
isValid = true;
707713
} else {
708714
throw new AnalysisException("only allow date, datetime and timestamptz in MATCH_CONDITION");

regression-test/suites/nereids_p0/join/test_asof_join.groovy

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,4 +1198,28 @@ suite("test_asof_join", "nereids_p0") {
11981198
ORDER BY l.id
11991199
"""
12001200

1201+
test {
1202+
sql """
1203+
SELECT l.id, l.ts, r.id as rid, r.ts as rts, r.value
1204+
FROM asof_precision_left l
1205+
ASOF LEFT JOIN asof_precision_right r
1206+
MATCH_CONDITION(l.ts >= l.ts)
1207+
ON l.grp = r.grp
1208+
ORDER BY l.id
1209+
"""
1210+
exception "MATCH_CONDITION must specify column from both table"
1211+
}
1212+
1213+
test {
1214+
sql """
1215+
SELECT l.id, l.ts, r.id as rid, r.ts as rts, r.value
1216+
FROM asof_precision_left l
1217+
ASOF LEFT JOIN asof_precision_right r
1218+
MATCH_CONDITION(l.ts - l.ts >= 1)
1219+
ON l.grp = r.grp
1220+
ORDER BY l.id
1221+
"""
1222+
exception "only allow date, datetime and timestamptz in MATCH_CONDITION"
1223+
}
1224+
12011225
}

0 commit comments

Comments
 (0)