Apache DataFusion SQL Query Engine
Minor: add flags for temporary ddl (#12561)
Haile636f43321acf
diff --git a/datafusion/core/src/catalog_common/listing_schema.rs b/datafusion/core/src/catalog_common/listing_schema.rsindex e45c8a8d4a..665ea58c5f 100644--- a/datafusion/core/src/catalog_common/listing_schema.rs+++ b/datafusion/core/src/catalog_common/listing_schema.rs@@ -136,6 +136,7 @@ impl ListingSchemaProvider {file_type: self.format.clone(),table_partition_cols: vec![],if_not_exists: false,+ temporary: false,definition: None,order_exprs: vec![],unbounded: false,diff --git a/datafusion/core/src/datasource/listing_table_factory.rs b/datafusion/core/src/datasource/listing_table_factory.rsindex fed63ec12b..701a13477b 100644--- a/datafusion/core/src/datasource/listing_table_factory.rs+++ b/datafusion/core/src/datasource/listing_table_factory.rs@@ -197,6 +197,7 @@ mod tests {schema: Arc::new(DFSchema::empty()),table_partition_cols: vec![],if_not_exists: false,+ temporary: false,definition: None,order_exprs: vec![],unbounded: false,@@ -236,6 +237,7 @@ mod tests {schema: Arc::new(DFSchema::empty()),table_partition_cols: vec![],if_not_exists: false,+ temporary: false,definition: None,order_exprs: vec![],unbounded: false,diff --git a/datafusion/core/src/execution/context/mod.rs b/datafusion/core/src/execution/context/mod.rsindex b0951d9ec4..606759aae5 100644--- a/datafusion/core/src/execution/context/mod.rs+++ b/datafusion/core/src/execution/context/mod.rs@@ -738,6 +738,11 @@ impl SessionContext {cmd: &CreateExternalTable,) -> Result<DataFrame> {let exist = self.table_exist(cmd.name.clone())?;++ if cmd.temporary {+ return not_impl_err!("Temporary tables not supported");+ }+if exist {match cmd.if_not_exists {true => return self.return_empty_dataframe(),@@ -761,10 +766,16 @@ impl SessionContext {or_replace,constraints,column_defaults,+ temporary,} = cmd;let input = Arc::unwrap_or_clone(input);let input = self.state().optimize(&input)?;++ if temporary {+ return not_impl_err!("Temporary tables not supported");+ }+let table = self.table(name.clone()).await;match (if_not_exists, or_replace, table) {(true, false, Ok(_)) => self.return_empty_dataframe(),@@ -813,10 +824,15 @@ impl SessionContext {input,or_replace,definition,+ temporary,} = cmd;let view = self.table(name.clone()).await;+ if temporary {+ return not_impl_err!("Temporary views not supported");+ }+match (or_replace, view) {(true, Ok(_)) => {self.deregister_table(name.clone())?;diff --git a/datafusion/expr/src/logical_plan/ddl.rs b/datafusion/expr/src/logical_plan/ddl.rsindex 9aaa5c9803..c4fa9f4c3f 100644--- a/datafusion/expr/src/logical_plan/ddl.rs+++ b/datafusion/expr/src/logical_plan/ddl.rs@@ -202,6 +202,8 @@ pub struct CreateExternalTable {pub table_partition_cols: Vec<String>,/// Option to not error if table already existspub if_not_exists: bool,+ /// Whether the table is a temporary table+ pub temporary: bool,/// SQL used to create the table, if availablepub definition: Option<String>,/// Order expressions supplied by user@@ -298,6 +300,8 @@ pub struct CreateMemoryTable {pub or_replace: bool,/// Default values for columnspub column_defaults: Vec<(String, Expr)>,+ /// Wheter the table is `TableType::Temporary`+ pub temporary: bool,}/// Creates a view.@@ -311,6 +315,8 @@ pub struct CreateView {pub or_replace: bool,/// SQL used to create the view, if availablepub definition: Option<String>,+ /// Wheter the view is ephemeral+ pub temporary: bool,}/// Creates a catalog (aka "Database").diff --git a/datafusion/expr/src/logical_plan/plan.rs b/datafusion/expr/src/logical_plan/plan.rsindex 0292274e57..9bd57d2212 100644--- a/datafusion/expr/src/logical_plan/plan.rs+++ b/datafusion/expr/src/logical_plan/plan.rs@@ -993,6 +993,7 @@ impl LogicalPlan {if_not_exists,or_replace,column_defaults,+ temporary,..})) => {self.assert_no_expressions(expr)?;@@ -1005,6 +1006,7 @@ impl LogicalPlan {if_not_exists: *if_not_exists,or_replace: *or_replace,column_defaults: column_defaults.clone(),+ temporary: *temporary,},)))}@@ -1012,6 +1014,7 @@ impl LogicalPlan {name,or_replace,definition,+ temporary,..})) => {self.assert_no_expressions(expr)?;@@ -1020,6 +1023,7 @@ impl LogicalPlan {input: Arc::new(input),name: name.clone(),or_replace: *or_replace,+ temporary: *temporary,definition: definition.clone(),})))}diff --git a/datafusion/expr/src/logical_plan/tree_node.rs b/datafusion/expr/src/logical_plan/tree_node.rsindex 8ba68697bd..83206a2b2a 100644--- a/datafusion/expr/src/logical_plan/tree_node.rs+++ b/datafusion/expr/src/logical_plan/tree_node.rs@@ -285,6 +285,7 @@ impl TreeNode for LogicalPlan {if_not_exists,or_replace,column_defaults,+ temporary,}) => rewrite_arc(input, f)?.update_data(|input| {DdlStatement::CreateMemoryTable(CreateMemoryTable {name,@@ -293,6 +294,7 @@ impl TreeNode for LogicalPlan {if_not_exists,or_replace,column_defaults,+ temporary,})}),DdlStatement::CreateView(CreateView {@@ -300,12 +302,14 @@ impl TreeNode for LogicalPlan {input,or_replace,definition,+ temporary,}) => rewrite_arc(input, f)?.update_data(|input| {DdlStatement::CreateView(CreateView {name,input,or_replace,definition,+ temporary,})}),// no inputs in these statementsdiff --git a/datafusion/proto/proto/datafusion.proto b/datafusion/proto/proto/datafusion.protoindex 803cb49919..5256f7473c 100644--- a/datafusion/proto/proto/datafusion.proto+++ b/datafusion/proto/proto/datafusion.proto@@ -163,6 +163,7 @@ message CreateExternalTableNode {datafusion_common.DfSchema schema = 4;repeated string table_partition_cols = 5;bool if_not_exists = 6;+ bool temporary = 14;string definition = 7;repeated SortExprNodeCollection order_exprs = 10;bool unbounded = 11;@@ -200,6 +201,7 @@ message CreateViewNode {TableReference name = 5;LogicalPlanNode input = 2;bool or_replace = 3;+ bool temporary = 6;string definition = 4;}diff --git a/datafusion/proto/src/generated/pbjson.rs b/datafusion/proto/src/generated/pbjson.rsindex c7d4c4561a..e876008e85 100644--- a/datafusion/proto/src/generated/pbjson.rs+++ b/datafusion/proto/src/generated/pbjson.rs@@ -3193,6 +3193,9 @@ impl serde::Serialize for CreateExternalTableNode {if self.if_not_exists {len += 1;}+ if self.temporary {+ len += 1;+ }if !self.definition.is_empty() {len += 1;}@@ -3230,6 +3233,9 @@ impl serde::Serialize for CreateExternalTableNode {if self.if_not_exists {struct_ser.serialize_field("ifNotExists", &self.if_not_exists)?;}+ if self.temporary {+ struct_ser.serialize_field("temporary", &self.temporary)?;+ }if !self.definition.is_empty() {struct_ser.serialize_field("definition", &self.definition)?;}@@ -3267,6 +3273,7 @@ impl<'de> serde::Deserialize<'de> for CreateExternalTableNode {"tablePartitionCols","if_not_exists","ifNotExists",+ "temporary","definition","order_exprs","orderExprs",@@ -3285,6 +3292,7 @@ impl<'de> serde::Deserialize<'de> for CreateExternalTableNode {Schema,TablePartitionCols,IfNotExists,+ Temporary,Definition,OrderExprs,Unbounded,@@ -3318,6 +3326,7 @@ impl<'de> serde::Deserialize<'de> for CreateExternalTableNode {"schema" => Ok(GeneratedField::Schema),"tablePartitionCols" | "table_partition_cols" => Ok(GeneratedField::TablePartitionCols),"ifNotExists" | "if_not_exists" => Ok(GeneratedField::IfNotExists),+ "temporary" => Ok(GeneratedField::Temporary),"definition" => Ok(GeneratedField::Definition),"orderExprs" | "order_exprs" => Ok(GeneratedField::OrderExprs),"unbounded" => Ok(GeneratedField::Unbounded),@@ -3349,6 +3358,7 @@ impl<'de> serde::Deserialize<'de> for CreateExternalTableNode {let mut schema__ = None;let mut table_partition_cols__ = None;let mut if_not_exists__ = None;+ let mut temporary__ = None;let mut definition__ = None;let mut order_exprs__ = None;let mut unbounded__ = None;@@ -3393,6 +3403,12 @@ impl<'de> serde::Deserialize<'de> for CreateExternalTableNode {}if_not_exists__ = Some(map_.next_value()?);}+ GeneratedField::Temporary => {+ if temporary__.is_some() {+ return Err(serde::de::Error::duplicate_field("temporary"));+ }+ temporary__ = Some(map_.next_value()?);+ }GeneratedField::Definition => {if definition__.is_some() {return Err(serde::de::Error::duplicate_field("definition"));@@ -3442,6 +3458,7 @@ impl<'de> serde::Deserialize<'de> for CreateExternalTableNode {schema: schema__,table_partition_cols: table_partition_cols__.unwrap_or_default(),if_not_exists: if_not_exists__.unwrap_or_default(),+ temporary: temporary__.unwrap_or_default(),definition: definition__.unwrap_or_default(),order_exprs: order_exprs__.unwrap_or_default(),unbounded: unbounded__.unwrap_or_default(),@@ -3471,6 +3488,9 @@ impl serde::Serialize for CreateViewNode {if self.or_replace {len += 1;}+ if self.temporary {+ len += 1;+ }if !self.definition.is_empty() {len += 1;}@@ -3484,6 +3504,9 @@ impl serde::Serialize for CreateViewNode {if self.or_replace {struct_ser.serialize_field("orReplace", &self.or_replace)?;}+ if self.temporary {+ struct_ser.serialize_field("temporary", &self.temporary)?;+ }if !self.definition.is_empty() {struct_ser.serialize_field("definition", &self.definition)?;}@@ -3501,6 +3524,7 @@ impl<'de> serde::Deserialize<'de> for CreateViewNode {"input","or_replace","orReplace",+ "temporary","definition",];@@ -3509,6 +3533,7 @@ impl<'de> serde::Deserialize<'de> for CreateViewNode {Name,Input,OrReplace,+ Temporary,Definition,}impl<'de> serde::Deserialize<'de> for GeneratedField {@@ -3534,6 +3559,7 @@ impl<'de> serde::Deserialize<'de> for CreateViewNode {"name" => Ok(GeneratedField::Name),"input" => Ok(GeneratedField::Input),"orReplace" | "or_replace" => Ok(GeneratedField::OrReplace),+ "temporary" => Ok(GeneratedField::Temporary),"definition" => Ok(GeneratedField::Definition),_ => Err(serde::de::Error::unknown_field(value, FIELDS)),}@@ -3557,6 +3583,7 @@ impl<'de> serde::Deserialize<'de> for CreateViewNode {let mut name__ = None;let mut input__ = None;let mut or_replace__ = None;+ let mut temporary__ = None;let mut definition__ = None;while let Some(k) = map_.next_key()? {match k {@@ -3578,6 +3605,12 @@ impl<'de> serde::Deserialize<'de> for CreateViewNode {}or_replace__ = Some(map_.next_value()?);}+ GeneratedField::Temporary => {+ if temporary__.is_some() {+ return Err(serde::de::Error::duplicate_field("temporary"));+ }+ temporary__ = Some(map_.next_value()?);+ }GeneratedField::Definition => {if definition__.is_some() {return Err(serde::de::Error::duplicate_field("definition"));@@ -3590,6 +3623,7 @@ impl<'de> serde::Deserialize<'de> for CreateViewNode {name: name__,input: input__,or_replace: or_replace__.unwrap_or_default(),+ temporary: temporary__.unwrap_or_default(),definition: definition__.unwrap_or_default(),})}diff --git a/datafusion/proto/src/generated/prost.rs b/datafusion/proto/src/generated/prost.rsindex 8cba6f84f7..2aa14f7e80 100644--- a/datafusion/proto/src/generated/prost.rs+++ b/datafusion/proto/src/generated/prost.rs@@ -240,6 +240,8 @@ pub struct CreateExternalTableNode {pub table_partition_cols: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,#[prost(bool, tag = "6")]pub if_not_exists: bool,+ #[prost(bool, tag = "14")]+ pub temporary: bool,#[prost(string, tag = "7")]pub definition: ::prost::alloc::string::String,#[prost(message, repeated, tag = "10")]@@ -303,6 +305,8 @@ pub struct CreateViewNode {pub input: ::core::option::Option<::prost::alloc::boxed::Box<LogicalPlanNode>>,#[prost(bool, tag = "3")]pub or_replace: bool,+ #[prost(bool, tag = "6")]+ pub temporary: bool,#[prost(string, tag = "4")]pub definition: ::prost::alloc::string::String,}diff --git a/datafusion/proto/src/logical_plan/mod.rs b/datafusion/proto/src/logical_plan/mod.rsindex 7156cee66a..6061a7a061 100644--- a/datafusion/proto/src/logical_plan/mod.rs+++ b/datafusion/proto/src/logical_plan/mod.rs@@ -579,6 +579,7 @@ impl AsLogicalPlan for LogicalPlanNode {.clone(),order_exprs,if_not_exists: create_extern_table.if_not_exists,+ temporary: create_extern_table.temporary,definition,unbounded: create_extern_table.unbounded,options: create_extern_table.options.clone(),@@ -601,6 +602,7 @@ impl AsLogicalPlan for LogicalPlanNode {Ok(LogicalPlan::Ddl(DdlStatement::CreateView(CreateView {name: from_table_reference(create_view.name.as_ref(), "CreateView")?,+ temporary: create_view.temporary,input: Arc::new(plan),or_replace: create_view.or_replace,definition,@@ -1386,6 +1388,7 @@ impl AsLogicalPlan for LogicalPlanNode {options,constraints,column_defaults,+ temporary,},)) => {let mut converted_order_exprs: Vec<SortExprNodeCollection> = vec![];@@ -1412,6 +1415,7 @@ impl AsLogicalPlan for LogicalPlanNode {schema: Some(df_schema.try_into()?),table_partition_cols: table_partition_cols.clone(),if_not_exists: *if_not_exists,+ temporary: *temporary,order_exprs: converted_order_exprs,definition: definition.clone().unwrap_or_default(),unbounded: *unbounded,@@ -1427,6 +1431,7 @@ impl AsLogicalPlan for LogicalPlanNode {input,or_replace,definition,+ temporary,})) => Ok(protobuf::LogicalPlanNode {logical_plan_type: Some(LogicalPlanType::CreateView(Box::new(protobuf::CreateViewNode {@@ -1436,6 +1441,7 @@ impl AsLogicalPlan for LogicalPlanNode {extension_codec,)?)),or_replace: *or_replace,+ temporary: *temporary,definition: definition.clone().unwrap_or_default(),},))),diff --git a/datafusion/sql/src/parser.rs b/datafusion/sql/src/parser.rsindex a68d849185..8a984f1645 100644--- a/datafusion/sql/src/parser.rs+++ b/datafusion/sql/src/parser.rs@@ -194,6 +194,8 @@ pub struct CreateExternalTable {pub order_exprs: Vec<LexOrdering>,/// Option to not error if table already existspub if_not_exists: bool,+ /// Whether the table is a temporary table+ pub temporary: bool,/// Infinite streams?pub unbounded: bool,/// Table(provider) specific options@@ -699,6 +701,10 @@ impl<'a> DFParser<'a> {&mut self,unbounded: bool,) -> Result<Statement, ParserError> {+ let temporary = self+ .parser+ .parse_one_of_keywords(&[Keyword::TEMP, Keyword::TEMPORARY])+ .is_some();self.parser.expect_keyword(Keyword::TABLE)?;let if_not_exists =self.parser@@ -820,6 +826,7 @@ impl<'a> DFParser<'a> {table_partition_cols: builder.table_partition_cols.unwrap_or(vec![]),order_exprs: builder.order_exprs,if_not_exists,+ temporary,unbounded,options: builder.options.unwrap_or(Vec::new()),constraints,@@ -924,6 +931,7 @@ mod tests {table_partition_cols: vec![],order_exprs: vec![],if_not_exists: false,+ temporary: false,unbounded: false,options: vec![],constraints: vec![],@@ -940,6 +948,7 @@ mod tests {table_partition_cols: vec![],order_exprs: vec![],if_not_exists: false,+ temporary: false,unbounded: false,options: vec![],constraints: vec![],@@ -957,6 +966,7 @@ mod tests {table_partition_cols: vec![],order_exprs: vec![],if_not_exists: false,+ temporary: false,unbounded: false,options: vec![],constraints: vec![],@@ -974,6 +984,7 @@ mod tests {table_partition_cols: vec![],order_exprs: vec![],if_not_exists: false,+ temporary: false,unbounded: false,options: vec![("format.delimiter".into(),@@ -994,6 +1005,7 @@ mod tests {table_partition_cols: vec!["p1".to_string(), "p2".to_string()],order_exprs: vec![],if_not_exists: false,+ temporary: false,unbounded: false,options: vec![],constraints: vec![],@@ -1021,6 +1033,7 @@ mod tests {table_partition_cols: vec![],order_exprs: vec![],if_not_exists: false,+ temporary: false,unbounded: false,options: vec![("format.compression".into(),@@ -1041,6 +1054,7 @@ mod tests {table_partition_cols: vec![],order_exprs: vec![],if_not_exists: false,+ temporary: false,unbounded: false,options: vec![],constraints: vec![],@@ -1057,6 +1071,7 @@ mod tests {table_partition_cols: vec![],order_exprs: vec![],if_not_exists: false,+ temporary: false,unbounded: false,options: vec![],constraints: vec![],@@ -1073,6 +1088,7 @@ mod tests {table_partition_cols: vec![],order_exprs: vec![],if_not_exists: false,+ temporary: false,unbounded: false,options: vec![],constraints: vec![],@@ -1090,6 +1106,7 @@ mod tests {table_partition_cols: vec![],order_exprs: vec![],if_not_exists: true,+ temporary: false,unbounded: false,options: vec![],constraints: vec![],@@ -1110,6 +1127,7 @@ mod tests {table_partition_cols: vec!["p1".to_string()],order_exprs: vec![],if_not_exists: false,+ temporary: false,unbounded: false,options: vec![],constraints: vec![],@@ -1140,6 +1158,7 @@ mod tests {table_partition_cols: vec![],order_exprs: vec![],if_not_exists: false,+ temporary: false,unbounded: false,options: vec![("k1".into(), Value::SingleQuotedString("v1".into()))],constraints: vec![],@@ -1157,6 +1176,7 @@ mod tests {table_partition_cols: vec![],order_exprs: vec![],if_not_exists: false,+ temporary: false,unbounded: false,options: vec![("k1".into(), Value::SingleQuotedString("v1".into())),@@ -1204,6 +1224,7 @@ mod tests {with_fill: None,}]],if_not_exists: false,+ temporary: false,unbounded: false,options: vec![],constraints: vec![],@@ -1244,6 +1265,7 @@ mod tests {},]],if_not_exists: false,+ temporary: false,unbounded: false,options: vec![],constraints: vec![],@@ -1279,6 +1301,7 @@ mod tests {with_fill: None,}]],if_not_exists: false,+ temporary: false,unbounded: false,options: vec![],constraints: vec![],@@ -1323,6 +1346,7 @@ mod tests {with_fill: None,}]],if_not_exists: true,+ temporary: false,unbounded: true,options: vec![(diff --git a/datafusion/sql/src/query.rs b/datafusion/sql/src/query.rsindex 125259d227..54945ec43d 100644--- a/datafusion/sql/src/query.rs+++ b/datafusion/sql/src/query.rs@@ -150,6 +150,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {input: Arc::new(plan),if_not_exists: false,or_replace: false,+ temporary: false,column_defaults: vec![],},))),diff --git a/datafusion/sql/src/statement.rs b/datafusion/sql/src/statement.rsindex 3111fab9a2..edb4316db1 100644--- a/datafusion/sql/src/statement.rs+++ b/datafusion/sql/src/statement.rs@@ -440,6 +440,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {if_not_exists,or_replace,column_defaults,+ temporary,},)))}@@ -463,6 +464,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {if_not_exists,or_replace,column_defaults,+ temporary,},)))}@@ -498,9 +500,6 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {if if_not_exists {return not_impl_err!("If not exists not supported")?;}- if temporary {- return not_impl_err!("Temporary views not supported")?;- }if to.is_some() {return not_impl_err!("To not supported")?;}@@ -526,6 +525,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {input: Arc::new(plan),or_replace,definition: sql,+ temporary,})))}Statement::ShowCreate { obj_type, obj_name } => match obj_type {@@ -1198,6 +1198,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {location,table_partition_cols,if_not_exists,+ temporary,order_exprs,unbounded,options,@@ -1250,6 +1251,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {file_type,table_partition_cols,if_not_exists,+ temporary,definition,order_exprs: ordered_exprs,unbounded,diff --git a/datafusion/sqllogictest/test_files/create_external_table.slt b/datafusion/sqllogictest/test_files/create_external_table.sltindex 9ac2ecdce7..7dba4d01d6 100644--- a/datafusion/sqllogictest/test_files/create_external_table.slt+++ b/datafusion/sqllogictest/test_files/create_external_table.slt@@ -102,9 +102,6 @@ CREATE TEMPORARY TABLE my_temp_table (name TEXT NOT NULL);-statement error DataFusion error: This feature is not implemented: Temporary views not supported-CREATE TEMPORARY VIEW my_temp_view AS SELECT id, name FROM my_table;-# Partitioned table on a single filequery error DataFusion error: Error during planning: Can't create a partitioned table backed by a single file, perhaps the URL is missing a trailing slash\?CREATE EXTERNAL TABLE single_file_partition(c1 int)diff --git a/datafusion/sqllogictest/test_files/ddl.slt b/datafusion/sqllogictest/test_files/ddl.sltindex 21edb458fe..813f7e95ad 100644--- a/datafusion/sqllogictest/test_files/ddl.slt+++ b/datafusion/sqllogictest/test_files/ddl.slt@@ -775,3 +775,27 @@ physical_plan CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/testatement okdrop table t;++statement ok+set datafusion.explain.logical_plan_only=true;++query TT+explain CREATE TEMPORARY VIEW z AS VALUES (1,2,3);+----+logical_plan+01)CreateView: Bare { table: "z" }+02)--Values: (Int64(1), Int64(2), Int64(3))++query TT+explain CREATE EXTERNAL TEMPORARY TABLE tty STORED as ARROW LOCATION '../core/tests/data/example.arrow';+----+logical_plan CreateExternalTable: Bare { table: "tty" }++statement ok+set datafusion.explain.logical_plan_only=false;++statement error DataFusion error: This feature is not implemented: Temporary tables not supported+CREATE EXTERNAL TEMPORARY TABLE tty STORED as ARROW LOCATION '../core/tests/data/example.arrow';++statement error DataFusion error: This feature is not implemented: Temporary views not supported+CREATE TEMPORARY VIEW y AS VALUES (1,2,3);