Skip to content

Commit

Permalink
Minor: add flags for temporary ddl
Browse files Browse the repository at this point in the history
Signed-off-by: Haile Lagi <[email protected]>
  • Loading branch information
hailelagi committed Sep 30, 2024
1 parent 3892499 commit 7ac494c
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 1 deletion.
2 changes: 2 additions & 0 deletions datafusion/core/src/datasource/listing_table_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions datafusion/core/src/execution/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,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!("CREATE TEMPORARY table");
}

let table = self.table(name.clone()).await;
match (if_not_exists, or_replace, table) {
(true, false, Ok(_)) => self.return_empty_dataframe(),
Expand Down Expand Up @@ -813,10 +819,15 @@ impl SessionContext {
input,
or_replace,
definition,
temporary,
} = cmd;

let view = self.table(name.clone()).await;

if temporary {
return not_impl_err!("CREATE TEMPORARY view");
}

match (or_replace, view) {
(true, Ok(_)) => {
self.deregister_table(name.clone())?;
Expand Down
4 changes: 4 additions & 0 deletions datafusion/expr/src/logical_plan/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ pub struct CreateMemoryTable {
pub or_replace: bool,
/// Default values for columns
pub column_defaults: Vec<(String, Expr)>,
/// Wheter the table is `TableType::Temporary`
pub temporary: bool,
}

/// Creates a view.
Expand All @@ -311,6 +313,8 @@ pub struct CreateView {
pub or_replace: bool,
/// SQL used to create the view, if available
pub definition: Option<String>,
/// Wheter the view is ephemeral
pub temporary: bool,
}

/// Creates a catalog (aka "Database").
Expand Down
4 changes: 4 additions & 0 deletions datafusion/expr/src/logical_plan/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,7 @@ impl LogicalPlan {
if_not_exists,
or_replace,
column_defaults,
temporary,
..
})) => {
self.assert_no_expressions(expr)?;
Expand All @@ -1004,13 +1005,15 @@ impl LogicalPlan {
if_not_exists: *if_not_exists,
or_replace: *or_replace,
column_defaults: column_defaults.clone(),
temporary: *temporary,
},
)))
}
LogicalPlan::Ddl(DdlStatement::CreateView(CreateView {
name,
or_replace,
definition,
temporary,
..
})) => {
self.assert_no_expressions(expr)?;
Expand All @@ -1019,6 +1022,7 @@ impl LogicalPlan {
input: Arc::new(input),
name: name.clone(),
or_replace: *or_replace,
temporary: *temporary,
definition: definition.clone(),
})))
}
Expand Down
4 changes: 4 additions & 0 deletions datafusion/expr/src/logical_plan/tree_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -293,19 +294,22 @@ impl TreeNode for LogicalPlan {
if_not_exists,
or_replace,
column_defaults,
temporary,
})
}),
DdlStatement::CreateView(CreateView {
name,
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 statements
Expand Down
4 changes: 4 additions & 0 deletions datafusion/proto/src/generated/prost.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions datafusion/proto/src/logical_plan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ impl AsLogicalPlan for LogicalPlanNode {

Ok(LogicalPlan::Ddl(DdlStatement::CreateView(CreateView {
name: from_table_reference(create_view.name.as_ref(), "CreateView")?,
temporary: false,
input: Arc::new(plan),
or_replace: create_view.or_replace,
definition,
Expand Down Expand Up @@ -1386,6 +1387,7 @@ impl AsLogicalPlan for LogicalPlanNode {
options,
constraints,
column_defaults,
temporary,
},
)) => {
let mut converted_order_exprs: Vec<SortExprNodeCollection> = vec![];
Expand All @@ -1412,6 +1414,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: Some(*temporary),
order_exprs: converted_order_exprs,
definition: definition.clone().unwrap_or_default(),
unbounded: *unbounded,
Expand All @@ -1427,6 +1430,7 @@ impl AsLogicalPlan for LogicalPlanNode {
input,
or_replace,
definition,
temporary,
})) => Ok(protobuf::LogicalPlanNode {
logical_plan_type: Some(LogicalPlanType::CreateView(Box::new(
protobuf::CreateViewNode {
Expand All @@ -1436,6 +1440,7 @@ impl AsLogicalPlan for LogicalPlanNode {
extension_codec,
)?)),
or_replace: *or_replace,
temporary: Some(*temporary),
definition: definition.clone().unwrap_or_default(),
},
))),
Expand Down
17 changes: 17 additions & 0 deletions datafusion/sql/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ mod tests {
table_partition_cols: vec![],
order_exprs: vec![],
if_not_exists: false,
temporary: false,
unbounded: false,
options: vec![],
constraints: vec![],
Expand All @@ -939,6 +940,7 @@ mod tests {
table_partition_cols: vec![],
order_exprs: vec![],
if_not_exists: false,
temporary: false,
unbounded: false,
options: vec![],
constraints: vec![],
Expand All @@ -956,6 +958,7 @@ mod tests {
table_partition_cols: vec![],
order_exprs: vec![],
if_not_exists: false,
temporary: false,
unbounded: false,
options: vec![],
constraints: vec![],
Expand All @@ -973,6 +976,7 @@ mod tests {
table_partition_cols: vec![],
order_exprs: vec![],
if_not_exists: false,
temporary: false,
unbounded: false,
options: vec![(
"format.delimiter".into(),
Expand All @@ -993,6 +997,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![],
Expand Down Expand Up @@ -1020,6 +1025,7 @@ mod tests {
table_partition_cols: vec![],
order_exprs: vec![],
if_not_exists: false,
temporary: false,
unbounded: false,
options: vec![(
"format.compression".into(),
Expand All @@ -1040,6 +1046,7 @@ mod tests {
table_partition_cols: vec![],
order_exprs: vec![],
if_not_exists: false,
temporary: false,
unbounded: false,
options: vec![],
constraints: vec![],
Expand All @@ -1056,6 +1063,7 @@ mod tests {
table_partition_cols: vec![],
order_exprs: vec![],
if_not_exists: false,
temporary: false,
unbounded: false,
options: vec![],
constraints: vec![],
Expand All @@ -1072,6 +1080,7 @@ mod tests {
table_partition_cols: vec![],
order_exprs: vec![],
if_not_exists: false,
temporary: false,
unbounded: false,
options: vec![],
constraints: vec![],
Expand All @@ -1089,6 +1098,7 @@ mod tests {
table_partition_cols: vec![],
order_exprs: vec![],
if_not_exists: true,
temporary: false,
unbounded: false,
options: vec![],
constraints: vec![],
Expand All @@ -1109,6 +1119,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![],
Expand Down Expand Up @@ -1139,6 +1150,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![],
Expand All @@ -1156,6 +1168,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())),
Expand Down Expand Up @@ -1203,6 +1216,7 @@ mod tests {
with_fill: None,
}]],
if_not_exists: false,
temporary: false,
unbounded: false,
options: vec![],
constraints: vec![],
Expand Down Expand Up @@ -1243,6 +1257,7 @@ mod tests {
},
]],
if_not_exists: false,
temporary: false,
unbounded: false,
options: vec![],
constraints: vec![],
Expand Down Expand Up @@ -1278,6 +1293,7 @@ mod tests {
with_fill: None,
}]],
if_not_exists: false,
temporary: false,
unbounded: false,
options: vec![],
constraints: vec![],
Expand Down Expand Up @@ -1322,6 +1338,7 @@ mod tests {
with_fill: None,
}]],
if_not_exists: true,
temporary: false,
unbounded: true,
options: vec![
(
Expand Down
1 change: 1 addition & 0 deletions datafusion/sql/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![],
},
))),
Expand Down
5 changes: 4 additions & 1 deletion datafusion/sql/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
if_not_exists,
or_replace,
column_defaults,
temporary,
},
)))
}
Expand All @@ -463,6 +464,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
if_not_exists,
or_replace,
column_defaults,
temporary,
},
)))
}
Expand Down Expand Up @@ -526,6 +528,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 {
Expand Down Expand Up @@ -1256,7 +1259,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
unbounded,
options: options_map,
constraints,
column_defaults,
column_defaults
},
)))
}
Expand Down
6 changes: 6 additions & 0 deletions datafusion/sqllogictest/test_files/ddl.slt
Original file line number Diff line number Diff line change
Expand Up @@ -775,3 +775,9 @@ physical_plan CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/te

statement ok
drop table t;

statement ok
set datafusion.explain.logical_plan_only=true;

statement error DataFusion error: This feature is not implemented: Temporary views not supported
explain CREATE TEMPORARY VIEW y AS VALUES (1,2,3);

0 comments on commit 7ac494c

Please sign in to comment.