Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor: add flags for temporary ddl #12561

Merged
merged 2 commits into from
Oct 14, 2024
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
1 change: 1 addition & 0 deletions datafusion/core/src/catalog_common/listing_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
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
16 changes: 16 additions & 0 deletions datafusion/core/src/execution/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -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())?;
Expand Down
6 changes: 6 additions & 0 deletions datafusion/expr/src/logical_plan/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ pub struct CreateExternalTable {
pub table_partition_cols: Vec<String>,
/// Option to not error if table already exists
pub if_not_exists: bool,
/// Whether the table is a temporary table
pub temporary: bool,
/// SQL used to create the table, if available
pub definition: Option<String>,
/// Order expressions supplied by user
Expand Down Expand Up @@ -298,6 +300,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 +315,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 @@ -993,6 +993,7 @@ impl LogicalPlan {
if_not_exists,
or_replace,
column_defaults,
temporary,
..
})) => {
self.assert_no_expressions(expr)?;
Expand All @@ -1005,13 +1006,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 @@ -1020,6 +1023,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
2 changes: 2 additions & 0 deletions datafusion/proto/proto/datafusion.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -200,6 +201,7 @@ message CreateViewNode {
TableReference name = 5;
LogicalPlanNode input = 2;
bool or_replace = 3;
bool temporary = 6;
string definition = 4;
}

Expand Down
34 changes: 34 additions & 0 deletions datafusion/proto/src/generated/pbjson.rs

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

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.

6 changes: 6 additions & 0 deletions datafusion/proto/src/logical_plan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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,
Expand Down Expand Up @@ -1386,6 +1388,7 @@ impl AsLogicalPlan for LogicalPlanNode {
options,
constraints,
column_defaults,
temporary,
},
)) => {
let mut converted_order_exprs: Vec<SortExprNodeCollection> = vec![];
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -1436,6 +1441,7 @@ impl AsLogicalPlan for LogicalPlanNode {
extension_codec,
)?)),
or_replace: *or_replace,
temporary: *temporary,
definition: definition.clone().unwrap_or_default(),
},
))),
Expand Down
Loading