Apache DataFusion SQL Query Engine
Port tests in errors.rs to sqllogictest (#6239)
parkma99d9f0a3a596ad
diff --git a/datafusion/core/tests/sql/errors.rs b/datafusion/core/tests/sql/errors.rsindex f04531417d..343551f1f0 100644--- a/datafusion/core/tests/sql/errors.rs+++ b/datafusion/core/tests/sql/errors.rs@@ -17,122 +17,6 @@use super::*;-#[tokio::test]-async fn csv_query_error() -> Result<()> {- // sin(utf8) should error- let ctx = create_ctx();- register_aggregate_csv(&ctx).await?;- let sql = "SELECT sin(c1) FROM aggregate_test_100";- ctx.sql(sql).await.unwrap_err();- Ok(())-}--#[tokio::test]-async fn test_cast_expressions_error() -> Result<()> {- // sin(utf8) should error- let ctx = create_ctx();- register_aggregate_csv(&ctx).await?;- let sql = "SELECT CAST(c1 AS INT) FROM aggregate_test_100";- let dataframe = ctx.sql(sql).await.unwrap();- let result = dataframe.collect().await;-- match result {- Ok(_) => panic!("expected error"),- Err(e) => {- assert_contains!(- e.to_string(),- "Cannot cast string 'c' to value of Int32 type"- );- }- }-- Ok(())-}--#[tokio::test]-async fn test_aggregation_with_bad_arguments() -> Result<()> {- let ctx = SessionContext::new();- register_aggregate_csv(&ctx).await?;- let sql = "SELECT COUNT(DISTINCT) FROM aggregate_test_100";- let err = ctx.sql(sql).await.unwrap_err().to_string();- assert_eq!(- err,- DataFusionError::Plan(- "The function Count expects at least one argument".to_string()- )- .to_string()- );- Ok(())-}--#[tokio::test]-async fn query_cte_incorrect() -> Result<()> {- let ctx = SessionContext::new();-- // self reference- let sql = "WITH t AS (SELECT * FROM t) SELECT * from u";- let err = ctx.sql(sql).await.unwrap_err().to_string();- assert_eq!(- err,- "Error during planning: table 'datafusion.public.t' not found"- );-- // forward referencing- let sql = "WITH t AS (SELECT * FROM u), u AS (SELECT 1) SELECT * from u";- let err = ctx.sql(sql).await.unwrap_err().to_string();- assert_eq!(- err,- "Error during planning: table 'datafusion.public.u' not found"- );-- // wrapping should hide u- let sql = "WITH t AS (WITH u as (SELECT 1) SELECT 1) SELECT * from u";- let err = ctx.sql(sql).await.unwrap_err().to_string();- assert_eq!(- err,- "Error during planning: table 'datafusion.public.u' not found"- );-- Ok(())-}--#[tokio::test]-async fn test_select_wildcard_without_table() -> Result<()> {- let ctx = SessionContext::new();- let sql = "SELECT * ";- let actual = ctx.sql(sql).await;- match actual {- Ok(_) => panic!("expect err"),- Err(e) => {- assert_contains!(- e.to_string(),- "Error during planning: SELECT * with no tables specified is not valid"- );- }- }- Ok(())-}--#[tokio::test]-async fn invalid_qualified_table_references() -> Result<()> {- let ctx = SessionContext::new();- register_aggregate_csv(&ctx).await?;-- for table_ref in &[- "nonexistentschema.aggregate_test_100",- "nonexistentcatalog.public.aggregate_test_100",- "way.too.many.namespaces.as.ident.prefixes.aggregate_test_100",- ] {- let sql = format!("SELECT COUNT(*) FROM {table_ref}");- let result = ctx.sql(&sql).await;- assert!(- matches!(result, Err(DataFusionError::Plan(_))),- "result was: {result:?}"- );- }- Ok(())-}-#[tokio::test]async fn unsupported_sql_returns_error() -> Result<()> {let ctx = SessionContext::new();diff --git a/datafusion/core/tests/sqllogictests/test_files/errors.slt b/datafusion/core/tests/sqllogictests/test_files/errors.sltnew file mode 100644index 0000000000..ee934f4618--- /dev/null+++ b/datafusion/core/tests/sqllogictests/test_files/errors.slt@@ -0,0 +1,75 @@+# Licensed to the Apache Software Foundation (ASF) under one+# or more contributor license agreements. See the NOTICE file+# distributed with this work for additional information+# regarding copyright ownership. The ASF licenses this file+# to you under the Apache License, Version 2.0 (the+# "License"); you may not use this file except in compliance+# with the License. You may obtain a copy of the License at++# http://www.apache.org/licenses/LICENSE-2.0++# Unless required by applicable law or agreed to in writing,+# software distributed under the License is distributed on an+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY+# KIND, either express or implied. See the License for the+# specific language governing permissions and limitations+# under the License.+++# create aggregate_test_100 table+statement ok+CREATE EXTERNAL TABLE aggregate_test_100 (+ c1 VARCHAR NOT NULL,+ c2 TINYINT NOT NULL,+ c3 SMALLINT NOT NULL,+ c4 SMALLINT,+ c5 INT,+ c6 BIGINT NOT NULL,+ c7 SMALLINT NOT NULL,+ c8 INT NOT NULL,+ c9 BIGINT UNSIGNED NOT NULL,+ c10 VARCHAR NOT NULL,+ c11 FLOAT NOT NULL,+ c12 DOUBLE NOT NULL,+ c13 VARCHAR NOT NULL+)+STORED AS CSV+WITH HEADER ROW+LOCATION '../../testing/data/csv/aggregate_test_100.csv'++# csv_query_error+statement error Error during planning: Coercion from \[Utf8\] to the signature Uniform\(1, \[Float64, Float32\]\) failed\.+SELECT sin(c1) FROM aggregate_test_100++# cast_expressions_error+statement error DataFusion error: Arrow error: Cast error: Cannot cast string 'c' to value of Int32 type+SELECT CAST(c1 AS INT) FROM aggregate_test_100++# aggregation_with_bad_arguments+statement error Error during planning: The function Count expects at least one argument+SELECT COUNT(DISTINCT) FROM aggregate_test_100++# query_cte_incorrect+statement error Error during planning: table 'datafusion\.public\.t' not found+WITH t AS (SELECT * FROM t) SELECT * from u++statement error Error during planning: table 'datafusion\.public\.u' not found+WITH t AS (SELECT * FROM u), u AS (SELECT 1) SELECT * from u++statement error Error during planning: table 'datafusion\.public\.u' not found+WITH t AS (WITH u as (SELECT 1) SELECT 1) SELECT * from u++# select_wildcard_without_table+statement error Error during planning: SELECT \* with no tables specified is not valid+SELECT *++# invalid_qualified_table_references+statement error Error during planning: table 'datafusion\.nonexistentschema\.aggregate_test_100' not found+SELECT COUNT(*) FROM nonexistentschema.aggregate_test_100++statement error Error during planning: table 'nonexistentcatalog\.public\.aggregate_test_100' not found+SELECT COUNT(*) FROM nonexistentcatalog.public.aggregate_test_100++statement error Error during planning: Unsupported compound identifier '\[Ident \{ value: "way", quote_style: None \}, Ident \{ value: "too", quote_style: None \}, Ident \{ value: "many", quote_style: None \}, Ident \{ value: "namespaces", quote_style: None \}, Ident \{ value: "as", quote_style: None \}, Ident \{ value: "ident", quote_style: None \}, Ident \{ value: "prefixes", quote_style: None \}, Ident \{ value: "aggregate_test_100", quote_style: None \}\]'+SELECT COUNT(*) FROM way.too.many.namespaces.as.ident.prefixes.aggregate_test_100+