From f46ef1b0b3291ab2d3cc4f36d829c0fb02d8f193 Mon Sep 17 00:00:00 2001 From: osipovartem Date: Fri, 9 Oct 2026 12:55:38 +0300 Subject: [PATCH 1/2] Align ASOF validation diagnostics with Snowflake --- datafusion/expr/src/logical_plan/builder.rs | 10 +++++----- datafusion/expr/src/logical_plan/plan.rs | 5 ++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/datafusion/expr/src/logical_plan/builder.rs b/datafusion/expr/src/logical_plan/builder.rs index b227d137389d6..1d845aa94980d 100644 --- a/datafusion/expr/src/logical_plan/builder.rs +++ b/datafusion/expr/src/logical_plan/builder.rs @@ -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( @@ -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| { @@ -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( @@ -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( @@ -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(()) } diff --git a/datafusion/expr/src/logical_plan/plan.rs b/datafusion/expr/src/logical_plan/plan.rs index fa8ceb9d826b7..ab00cb0bca87d 100644 --- a/datafusion/expr/src/logical_plan/plan.rs +++ b/datafusion/expr/src/logical_plan/plan.rs @@ -4385,7 +4385,7 @@ impl TryFrom 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)) @@ -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." ); } From dfedccb61a6d8e874a088384c8fc9807091100e9 Mon Sep 17 00:00:00 2001 From: osipovartem Date: Fri, 9 Oct 2026 13:01:34 +0300 Subject: [PATCH 2/2] Update ASOF SQLLogicTest error expectations --- datafusion/sqllogictest/test_files/asof_join.slt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/datafusion/sqllogictest/test_files/asof_join.slt b/datafusion/sqllogictest/test_files/asof_join.slt index 3e84cd037653e..48ca9eaf12583 100644 --- a/datafusion/sqllogictest/test_files/asof_join.slt +++ b/datafusion/sqllogictest/test_files/asof_join.slt @@ -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