Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions datafusion/expr/src/logical_plan/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ impl LogicalPlanBuilder {
}) = predicate
else {
return plan_err!(
"ASOF ON accepts only equality conditions combined with AND"
"ON clause for ASOF JOIN must contain conjunctions of equality conditions only. Disjunctions are not allowed. Each side of an equality condition must only refer to either the left table or the right table."
);
};
find_valid_equijoin_key_pair(
Expand Down Expand Up @@ -1107,7 +1107,7 @@ impl LogicalPlanBuilder {
|| !check_all_columns_from_schema(&right_columns, right.schema())?
{
return plan_err!(
"ASOF MATCH_CONDITION left operand must reference only the left input and right operand only the right input"
"MATCH_CONDITION clause is invalid: The left side allows only column references from the left side table, and the right side allows only column references from the right side table."
);
}
let normalize = |expr, schema: &DFSchema| {
Expand Down Expand Up @@ -3079,7 +3079,7 @@ mod tests {
col("l.column2").gt_eq(col("r.column2")),
)
.expect_err("non-equality ASOF ON should fail");
assert_snapshot!(invalid_on.strip_backtrace(), @r#"Error during planning: ASOF ON accepts only equality conditions combined with AND"#);
assert_snapshot!(invalid_on.strip_backtrace(), @r#"Error during planning: ON clause for ASOF JOIN must contain conjunctions of equality conditions only. Disjunctions are not allowed. Each side of an equality condition must only refer to either the left table or the right table."#);

let invalid_match = LogicalPlanBuilder::from(left.clone())
.asof_join_on(
Expand All @@ -3088,7 +3088,7 @@ mod tests {
col("l.column2").eq(col("r.column2")),
)
.expect_err("equality ASOF MATCH_CONDITION should fail");
assert_snapshot!(invalid_match.strip_backtrace(), @r#"Error during planning: ASOF MATCH_CONDITION requires <, <=, >, or >=, found ="#);
assert_snapshot!(invalid_match.strip_backtrace(), @r#"Error during planning: MATCH_CONDITION clause is invalid: Only comparison operators '>=', '>', '<=' and '<' are allowed. Keywords such as AND and OR are not allowed."#);

let reversed_match = LogicalPlanBuilder::from(left)
.asof_join_on(
Expand All @@ -3097,7 +3097,7 @@ mod tests {
col("r.column2").gt_eq(col("l.column2")),
)
.expect_err("reversed ASOF MATCH_CONDITION should fail");
assert_snapshot!(reversed_match.strip_backtrace(), @r#"Error during planning: ASOF MATCH_CONDITION left operand must reference only the left input and right operand only the right input"#);
assert_snapshot!(reversed_match.strip_backtrace(), @r#"Error during planning: MATCH_CONDITION clause is invalid: The left side allows only column references from the left side table, and the right side allows only column references from the right side table."#);

Ok(())
}
Expand Down
5 changes: 2 additions & 3 deletions datafusion/expr/src/logical_plan/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4385,7 +4385,7 @@ impl TryFrom<Expr> for AsOfMatch {
Operator::Lt | Operator::LtEq | Operator::Gt | Operator::GtEq
) {
return plan_err!(
"ASOF MATCH_CONDITION requires <, <=, >, or >=, found {op}"
"MATCH_CONDITION clause is invalid: Only comparison operators '>=', '>', '<=' and '<' are allowed. Keywords such as AND and OR are not allowed."
);
}
Ok(Self::new(*left, op, *right))
Expand Down Expand Up @@ -4434,8 +4434,7 @@ impl AsOfJoin {
Operator::Lt | Operator::LtEq | Operator::Gt | Operator::GtEq
) {
return plan_err!(
"ASOF MATCH_CONDITION requires <, <=, >, or >=, found {}",
match_condition.op
"MATCH_CONDITION clause is invalid: Only comparison operators '>=', '>', '<=' and '<' are allowed. Keywords such as AND and OR are not allowed."
);
}

Expand Down
6 changes: 3 additions & 3 deletions datafusion/sqllogictest/test_files/asof_join.slt
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,21 @@ physical_plan
05)----SortExec: expr=[grp@0 ASC, ts@1 ASC], preserve_partitioning=[false]
06)------DataSourceExec: partitions=1, partition_sizes=[1]

query error ASOF MATCH_CONDITION requires <, <=, >, or >=
query error MATCH_CONDITION clause is invalid: Only comparison operators '>=', '>', '<=' and '<' are allowed
SELECT *
FROM asof_left l
ASOF JOIN asof_right r
MATCH_CONDITION (l.ts = r.ts)
ON l.grp = r.grp;

query error ASOF MATCH_CONDITION left operand must reference only the left input
query error MATCH_CONDITION clause is invalid: The left side allows only column references from the left side table
SELECT *
FROM asof_left l
ASOF JOIN asof_right r
MATCH_CONDITION (r.ts >= l.ts)
ON l.grp = r.grp;

query error ASOF ON accepts only equality conditions combined with AND
query error ON clause for ASOF JOIN must contain conjunctions of equality conditions only
SELECT *
FROM asof_left l
ASOF JOIN asof_right r
Expand Down
Loading