From f033d9c3b2bb038777fdfa2f539e7130eb926cdc Mon Sep 17 00:00:00 2001 From: "r.4ntix" Date: Wed, 12 Apr 2023 01:26:13 +0800 Subject: [PATCH] fix: return `NotImplemented` when execute `SELECT INTO` syntax (#5945) * fix: return `NotImplemented` when execute `SELECT INTO` syntax * chore: add tests for select unsupported syntax --- datafusion/sql/src/select.rs | 3 +++ datafusion/sql/tests/integration_test.rs | 31 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/datafusion/sql/src/select.rs b/datafusion/sql/src/select.rs index a723c7263f02..d77c1aefd291 100644 --- a/datafusion/sql/src/select.rs +++ b/datafusion/sql/src/select.rs @@ -61,6 +61,9 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { if !select.sort_by.is_empty() { return Err(DataFusionError::NotImplemented("SORT BY".to_string())); } + if select.into.is_some() { + return Err(DataFusionError::NotImplemented("INTO".to_string())); + } // process `from` clause let plan = self.plan_from_tables(select.from, planner_context)?; diff --git a/datafusion/sql/tests/integration_test.rs b/datafusion/sql/tests/integration_test.rs index 181e35a466a3..3749e655732d 100644 --- a/datafusion/sql/tests/integration_test.rs +++ b/datafusion/sql/tests/integration_test.rs @@ -3366,6 +3366,37 @@ fn test_select_distinct_order_by() { assert_eq!(err.to_string(), expected); } +#[rstest] +#[case::select_cluster_by_unsupported( + "SELECT customer_name, SUM(order_total) as total_order_amount FROM orders CLUSTER BY customer_name", + "This feature is not implemented: CLUSTER BY" +)] +#[case::select_lateral_view_unsupported( + "SELECT id, number FROM person LATERAL VIEW explode(numbers) exploded_table AS number", + "This feature is not implemented: LATERAL VIEWS" +)] +#[case::select_qualify_unsupported( + "SELECT i, p, o FROM person QUALIFY ROW_NUMBER() OVER (PARTITION BY p ORDER BY o) = 1", + "This feature is not implemented: QUALIFY" +)] +#[case::select_top_unsupported( + "SELECT TOP (5) * FROM person", + "This feature is not implemented: TOP" +)] +#[case::select_sort_by_unsupported( + "SELECT * FROM person SORT BY id", + "This feature is not implemented: SORT BY" +)] +#[case::select_into_unsupported( + "SELECT * INTO test FROM person", + "This feature is not implemented: INTO" +)] +#[test] +fn test_select_unsupported_syntax_errors(#[case] sql: &str, #[case] error: &str) { + let err = logical_plan(sql).unwrap_err(); + assert_eq!(err.to_string(), error) +} + #[test] fn select_order_by_with_cast() { let sql =