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
127 changes: 0 additions & 127 deletions datafusion/core/tests/sql/create_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,90 +21,6 @@ use datafusion::test_util::TestTableFactory;

use super::*;

#[tokio::test]
async fn sql_create_table_if_not_exists() -> Result<()> {
// the information schema used to introduce cyclic Arcs
let ctx =
SessionContext::with_config(SessionConfig::new().with_information_schema(true));

// Create table
ctx.sql("CREATE TABLE y AS VALUES (1,2,3)")
.await?
.collect()
.await?;

// Create table again
let result = ctx
.sql("CREATE TABLE IF NOT EXISTS y AS VALUES (1,2,3)")
.await?
.collect()
.await?;

assert_eq!(result, Vec::new());

// Create external table
ctx.sql("CREATE EXTERNAL TABLE aggregate_simple STORED AS CSV WITH HEADER ROW LOCATION 'tests/data/aggregate_simple.csv'")
.await?
.collect()
.await?;

// Create external table again
let result = ctx.sql("CREATE EXTERNAL TABLE IF NOT EXISTS aggregate_simple STORED AS CSV WITH HEADER ROW LOCATION 'tests/data/aggregate_simple.csv'")
.await?
.collect()
.await?;

assert_eq!(result, Vec::new());

Ok(())
}

#[tokio::test]
async fn sql_create_table_exists() -> Result<()> {
// the information schema used to introduce cyclic Arcs
let ctx =
SessionContext::with_config(SessionConfig::new().with_information_schema(true));

// Create table
ctx.sql("CREATE TABLE y AS VALUES (1,2,3)")
.await?
.collect()
.await?;

// Create table again without if not exist
let result = ctx.sql("CREATE TABLE y AS VALUES (1,2,3)").await;

match result {
Err(DataFusionError::Execution(err_msg)) => {
assert_eq!(err_msg, "Table 'y' already exists");
}
_ => {
panic!("expect create table failed");
}
}

// Create external table
ctx.sql("CREATE EXTERNAL TABLE aggregate_simple STORED AS CSV WITH HEADER ROW LOCATION 'tests/data/aggregate_simple.csv'")
.await?
.collect()
.await?;

// Create external table again without if not exist
let result = ctx.sql("CREATE EXTERNAL TABLE aggregate_simple STORED AS CSV WITH HEADER ROW LOCATION 'tests/data/aggregate_simple.csv'")
.await;

match result {
Err(DataFusionError::Execution(err_msg)) => {
assert_eq!(err_msg, "Table 'aggregate_simple' already exists");
}
_ => {
panic!("expect create table failed");
}
}

Ok(())
}

#[tokio::test]
async fn create_custom_table() -> Result<()> {
let cfg = RuntimeConfig::new();
Expand Down Expand Up @@ -157,46 +73,3 @@ async fn create_external_table_with_ddl() -> Result<()> {

Ok(())
}

#[tokio::test]
async fn create_bad_custom_table() {
let ctx = SessionContext::new();

let sql = "CREATE EXTERNAL TABLE dt STORED AS DELTATABLE LOCATION 's3://bucket/schema/table';";
let res = ctx.sql(sql).await;
match res {
Ok(_) => panic!("Registration of tables without factories should fail"),
Err(e) => {
assert!(
e.to_string().contains("Unable to find factory for"),
"Registration of tables without factories should throw correct error"
)
}
}
}

#[tokio::test]
async fn create_csv_table_empty_file() -> Result<()> {
let ctx =
SessionContext::with_config(SessionConfig::new().with_information_schema(true));

let sql = "CREATE EXTERNAL TABLE empty STORED AS CSV WITH HEADER ROW LOCATION 'tests/data/empty.csv'";
ctx.sql(sql).await.unwrap();
let sql =
"select column_name, data_type, ordinal_position from information_schema.columns";
let results = execute_to_batches(&ctx, sql).await;

let expected = vec![
"+-------------+-----------+------------------+",
"| column_name | data_type | ordinal_position |",
"+-------------+-----------+------------------+",
"| c1 | Utf8 | 0 |",
"| c2 | Utf8 | 1 |",
"| c3 | Utf8 | 2 |",
"+-------------+-----------+------------------+",
];

assert_batches_eq!(expected, &results);

Ok(())
}
25 changes: 25 additions & 0 deletions datafusion/core/tests/sqllogictests/test_files/ddl.slt
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,20 @@ CREATE TABLE table_without_values(field1 BIGINT NULL, field2 BIGINT NULL);
statement ok
CREATE TABLE IF NOT EXISTS table_without_values(field1 BIGINT, field2 BIGINT);

statement ok
CREATE EXTERNAL TABLE aggregate_simple STORED AS CSV WITH HEADER ROW LOCATION 'tests/data/aggregate_simple.csv'

# Should not recreate the same EXTERNAL table
statement error Execution error: Table 'aggregate_simple' already exists
CREATE EXTERNAL TABLE aggregate_simple STORED AS CSV WITH HEADER ROW LOCATION 'tests/data/aggregate_simple.csv'

statement ok
CREATE EXTERNAL TABLE IF NOT EXISTS aggregate_simple STORED AS CSV WITH HEADER ROW LOCATION 'tests/data/aggregate_simple.csv'
Comment on lines +458 to +459
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the previous cases I think we need to create this table again without IF NOT EXIST and expect an error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed,thanks again.
CREATE EXTERNAL TABLE
need to check recreate the same EXTERNAL table


# create bad custom table
statement error DataFusion error: Execution error: Unable to find factory for DELTATABLE
CREATE EXTERNAL TABLE dt STORED AS DELTATABLE LOCATION 's3://bucket/schema/table';


# Should not recreate the same table
statement error Table 'table_without_values' already exists
Expand Down Expand Up @@ -569,6 +583,17 @@ NULL
statement ok
drop table foo;

# craete csv table with empty csv file
statement ok
CREATE EXTERNAL TABLE empty STORED AS CSV WITH HEADER ROW LOCATION 'tests/data/empty.csv';

query TTI
select column_name, data_type, ordinal_position from information_schema.columns where table_name='empty';;
----
c1 Utf8 0
c2 Utf8 1
c3 Utf8 2


## should allow any type of exprs as values
statement ok
Expand Down