Skip to content

Commit 1e31093

Browse files
authored
Do not silently ignore unsupported CREATE TABLE and CREATE VIEW syntax (#12450)
* Minor: ignore other unsupported CREATE TABLE and CREATE TABLE syntax * Do not silently ignore temporary views
1 parent 3f0fb4a commit 1e31093

File tree

3 files changed

+182
-8
lines changed

3 files changed

+182
-8
lines changed

datafusion/sql/src/parser.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,10 +544,6 @@ impl<'a> DFParser<'a> {
544544
} else if self.parser.parse_keyword(Keyword::UNBOUNDED) {
545545
self.parser.expect_keyword(Keyword::EXTERNAL)?;
546546
self.parse_create_external_table(true)
547-
} else if self.parser.parse_keyword(Keyword::TEMPORARY) {
548-
Err(ParserError::ParserError(
549-
"Creating temporary tables is Unsupported".to_owned(),
550-
))
551547
} else {
552548
Ok(Statement::Statement(Box::from(self.parser.parse_create()?)))
553549
}

datafusion/sql/src/statement.rs

Lines changed: 180 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,15 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
222222
} => self.set_variable_to_plan(local, hivevar, &variables, value),
223223

224224
Statement::CreateTable(CreateTable {
225+
temporary,
226+
external,
227+
global,
228+
transient,
229+
volatile,
230+
hive_distribution,
231+
hive_formats,
232+
file_format,
233+
location,
225234
query,
226235
name,
227236
columns,
@@ -230,8 +239,149 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
230239
with_options,
231240
if_not_exists,
232241
or_replace,
233-
..
242+
without_rowid,
243+
like,
244+
clone,
245+
engine,
246+
comment,
247+
auto_increment_offset,
248+
default_charset,
249+
collation,
250+
on_commit,
251+
on_cluster,
252+
primary_key,
253+
order_by,
254+
partition_by,
255+
cluster_by,
256+
options,
257+
strict,
258+
copy_grants,
259+
enable_schema_evolution,
260+
change_tracking,
261+
data_retention_time_in_days,
262+
max_data_extension_time_in_days,
263+
default_ddl_collation,
264+
with_aggregation_policy,
265+
with_row_access_policy,
266+
with_tags,
234267
}) if table_properties.is_empty() && with_options.is_empty() => {
268+
if temporary {
269+
return not_impl_err!("Temporary tables not supported")?;
270+
}
271+
if external {
272+
return not_impl_err!("External tables not supported")?;
273+
}
274+
if global.is_some() {
275+
return not_impl_err!("Global tables not supported")?;
276+
}
277+
if transient {
278+
return not_impl_err!("Transient tables not supported")?;
279+
}
280+
if volatile {
281+
return not_impl_err!("Volatile tables not supported")?;
282+
}
283+
if hive_distribution != ast::HiveDistributionStyle::NONE {
284+
return not_impl_err!(
285+
"Hive distribution not supported: {hive_distribution:?}"
286+
)?;
287+
}
288+
if !matches!(
289+
hive_formats,
290+
Some(ast::HiveFormat {
291+
row_format: None,
292+
serde_properties: None,
293+
storage: None,
294+
location: None,
295+
})
296+
) {
297+
return not_impl_err!(
298+
"Hive formats not supported: {hive_formats:?}"
299+
)?;
300+
}
301+
if file_format.is_some() {
302+
return not_impl_err!("File format not supported")?;
303+
}
304+
if location.is_some() {
305+
return not_impl_err!("Location not supported")?;
306+
}
307+
if without_rowid {
308+
return not_impl_err!("Without rowid not supported")?;
309+
}
310+
if like.is_some() {
311+
return not_impl_err!("Like not supported")?;
312+
}
313+
if clone.is_some() {
314+
return not_impl_err!("Clone not supported")?;
315+
}
316+
if engine.is_some() {
317+
return not_impl_err!("Engine not supported")?;
318+
}
319+
if comment.is_some() {
320+
return not_impl_err!("Comment not supported")?;
321+
}
322+
if auto_increment_offset.is_some() {
323+
return not_impl_err!("Auto increment offset not supported")?;
324+
}
325+
if default_charset.is_some() {
326+
return not_impl_err!("Default charset not supported")?;
327+
}
328+
if collation.is_some() {
329+
return not_impl_err!("Collation not supported")?;
330+
}
331+
if on_commit.is_some() {
332+
return not_impl_err!("On commit not supported")?;
333+
}
334+
if on_cluster.is_some() {
335+
return not_impl_err!("On cluster not supported")?;
336+
}
337+
if primary_key.is_some() {
338+
return not_impl_err!("Primary key not supported")?;
339+
}
340+
if order_by.is_some() {
341+
return not_impl_err!("Order by not supported")?;
342+
}
343+
if partition_by.is_some() {
344+
return not_impl_err!("Partition by not supported")?;
345+
}
346+
if cluster_by.is_some() {
347+
return not_impl_err!("Cluster by not supported")?;
348+
}
349+
if options.is_some() {
350+
return not_impl_err!("Options not supported")?;
351+
}
352+
if strict {
353+
return not_impl_err!("Strict not supported")?;
354+
}
355+
if copy_grants {
356+
return not_impl_err!("Copy grants not supported")?;
357+
}
358+
if enable_schema_evolution.is_some() {
359+
return not_impl_err!("Enable schema evolution not supported")?;
360+
}
361+
if change_tracking.is_some() {
362+
return not_impl_err!("Change tracking not supported")?;
363+
}
364+
if data_retention_time_in_days.is_some() {
365+
return not_impl_err!("Data retention time in days not supported")?;
366+
}
367+
if max_data_extension_time_in_days.is_some() {
368+
return not_impl_err!(
369+
"Max data extension time in days not supported"
370+
)?;
371+
}
372+
if default_ddl_collation.is_some() {
373+
return not_impl_err!("Default DDL collation not supported")?;
374+
}
375+
if with_aggregation_policy.is_some() {
376+
return not_impl_err!("With aggregation policy not supported")?;
377+
}
378+
if with_row_access_policy.is_some() {
379+
return not_impl_err!("With row access policy not supported")?;
380+
}
381+
if with_tags.is_some() {
382+
return not_impl_err!("With tags not supported")?;
383+
}
384+
235385
// Merge inline constraints and existing constraints
236386
let mut all_constraints = constraints;
237387
let inline_constraints = calc_inline_constraints_from_columns(&columns);
@@ -317,12 +467,40 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
317467

318468
Statement::CreateView {
319469
or_replace,
470+
materialized,
320471
name,
321472
columns,
322473
query,
323474
options: CreateTableOptions::None,
324-
..
475+
cluster_by,
476+
comment,
477+
with_no_schema_binding,
478+
if_not_exists,
479+
temporary,
480+
to,
325481
} => {
482+
if materialized {
483+
return not_impl_err!("Materialized views not supported")?;
484+
}
485+
if !cluster_by.is_empty() {
486+
return not_impl_err!("Cluster by not supported")?;
487+
}
488+
if comment.is_some() {
489+
return not_impl_err!("Comment not supported")?;
490+
}
491+
if with_no_schema_binding {
492+
return not_impl_err!("With no schema binding not supported")?;
493+
}
494+
if if_not_exists {
495+
return not_impl_err!("If not exists not supported")?;
496+
}
497+
if temporary {
498+
return not_impl_err!("Temporary views not supported")?;
499+
}
500+
if to.is_some() {
501+
return not_impl_err!("To not supported")?;
502+
}
503+
326504
let columns = columns
327505
.into_iter()
328506
.map(|view_column_def| {

datafusion/sqllogictest/test_files/create_external_table.slt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ LOCATION 'foo.csv'
9696
OPTIONS ('format.delimiter' ';', 'format.column_index_truncate_length' '123')
9797

9898
# Creating Temporary tables
99-
statement error DataFusion error: SQL error: ParserError\("Creating temporary tables is Unsupported"\)
99+
statement error DataFusion error: This feature is not implemented: Temporary tables not supported
100100
CREATE TEMPORARY TABLE my_temp_table (
101101
id INTEGER PRIMARY KEY,
102102
name TEXT NOT NULL
103103
);
104104

105-
statement error DataFusion error: SQL error: ParserError\("Creating temporary tables is Unsupported"\)
105+
statement error DataFusion error: This feature is not implemented: Temporary views not supported
106106
CREATE TEMPORARY VIEW my_temp_view AS SELECT id, name FROM my_table;
107107

108108
# Partitioned table on a single file

0 commit comments

Comments
 (0)