Skip to content

Apache DataFusion SQL Query Engine

Fix panic on deep compound identifiers (#22186)

Daniël Heresd1c25125c899
diff --git a/datafusion/sql/src/expr/identifier.rs b/datafusion/sql/src/expr/identifier.rs
index 775cb2cfe8..e9e24b9716 100644
--- a/datafusion/sql/src/expr/identifier.rs
+++ b/datafusion/sql/src/expr/identifier.rs
@@ -182,8 +182,8 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
}
None => {
// Return default where use all identifiers to not have a nested field
- // this len check is because at 5 identifiers will have to have a nested field
- if ids.len() == 5 {
+ // this len check is because at 5 or more identifiers will have to have a nested field
+ if ids.len() >= 5 {
not_impl_err!("compound identifier: {ids:?}")
} else {
// Check the outer_query_schema and try to find a match
diff --git a/datafusion/sql/tests/sql_integration.rs b/datafusion/sql/tests/sql_integration.rs
index ba061d474b..64763e33d9 100644
--- a/datafusion/sql/tests/sql_integration.rs
+++ b/datafusion/sql/tests/sql_integration.rs
@@ -2061,6 +2061,16 @@ fn select_where_compound_identifiers() {
);
}
+#[test]
+fn select_unknown_deep_compound_identifier_returns_error() {
+ let err = logical_plan("SELECT a.b.c.d.e.f")
+ .expect_err("six-part compound identifier should be unsupported");
+ assert_contains!(
+ err.to_string(),
+ "This feature is not implemented: compound identifier: [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]"
+ );
+}
+
#[test]
fn select_order_by_index() {
let sql = "SELECT id FROM person ORDER BY 1";