Skip to content

Commit

Permalink
Minor: Add sql level test for inserting into non-existent directory
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Nov 20, 2023
1 parent 53d5df2 commit 7d3d8d2
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions datafusion/sqllogictest/test_files/insert.slt
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,39 @@ select * from table_without_values;

statement ok
drop table table_without_values;


### Test for creating tables into directories that do not already exist
# note use of `scratch` directory (which is cleared between runs)

statement ok
create external table new_empty_table(x int) stored as parquet location 'test_files/scratch/insert/new_empty_table/'; -- needs trailing slash

# should start empty
query I
select * from new_empty_table;
----

# should succeed and the table should create the direectory
statement ok
insert into new_empty_table values (1);

# Now has values
query I
select * from new_empty_table;
----
1

statement ok
drop table new_empty_table;

## test we get an error if the path doesn't end in slash
statement ok
create external table bad_new_empty_table(x int) stored as parquet location 'test_files/scratch/insert/bad_new_empty_table'; -- no trailing slash

# should fail
query error DataFusion error: Error during planning: Inserting into a ListingTable backed by a single file is not supported, URL is possibly missing a trailing `/`\. To append to an existing file use StreamTable, e\.g\. by using CREATE UNBOUNDED EXTERNAL TABLE
insert into bad_new_empty_table values (1);

statement ok
drop table bad_new_empty_table;

0 comments on commit 7d3d8d2

Please sign in to comment.