This is an automated email from the ASF dual-hosted git repository.
dheres pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/master by this push:
new ede82fb5a return empty dataframe on create table, remove a duplicate
optimize call (#3361)
ede82fb5a is described below
commit ede82fb5a88859b77b7939e4b58c174c8285216d
Author: kmitchener <[email protected]>
AuthorDate: Mon Sep 5 14:50:20 2022 -0400
return empty dataframe on create table, remove a duplicate optimize call
(#3361)
update docs
---
datafusion/core/src/execution/context.rs | 14 ++++++--------
datafusion/core/tests/sql/create_drop.rs | 4 +++-
docs/source/user-guide/sql/ddl.md | 12 ++++++------
3 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/datafusion/core/src/execution/context.rs
b/datafusion/core/src/execution/context.rs
index 1a4a7c9df..2a9d01124 100644
--- a/datafusion/core/src/execution/context.rs
+++ b/datafusion/core/src/execution/context.rs
@@ -269,35 +269,33 @@ impl SessionContext {
(true, false, Ok(_)) => self.return_empty_dataframe(),
(false, true, Ok(_)) => {
self.deregister_table(name.as_str())?;
- let plan = self.optimize(&input)?;
let physical =
- Arc::new(DataFrame::new(self.state.clone(),
&plan));
+ Arc::new(DataFrame::new(self.state.clone(),
&input));
let batches: Vec<_> =
physical.collect_partitioned().await?;
let table = Arc::new(MemTable::try_new(
- Arc::new(plan.schema().as_ref().into()),
+ Arc::new(input.schema().as_ref().into()),
batches,
)?);
self.register_table(name.as_str(), table)?;
- Ok(Arc::new(DataFrame::new(self.state.clone(), &plan)))
+ self.return_empty_dataframe()
}
(true, true, Ok(_)) => Err(DataFusionError::Internal(
"'IF NOT EXISTS' cannot coexist with
'REPLACE'".to_string(),
)),
(_, _, Err(_)) => {
- let plan = self.optimize(&input)?;
let physical =
- Arc::new(DataFrame::new(self.state.clone(),
&plan));
+ Arc::new(DataFrame::new(self.state.clone(),
&input));
let batches: Vec<_> =
physical.collect_partitioned().await?;
let table = Arc::new(MemTable::try_new(
- Arc::new(plan.schema().as_ref().into()),
+ Arc::new(input.schema().as_ref().into()),
batches,
)?);
self.register_table(name.as_str(), table)?;
- Ok(Arc::new(DataFrame::new(self.state.clone(), &plan)))
+ self.return_empty_dataframe()
}
(false, false, Ok(_)) =>
Err(DataFusionError::Execution(format!(
"Table '{:?}' already exists",
diff --git a/datafusion/core/tests/sql/create_drop.rs
b/datafusion/core/tests/sql/create_drop.rs
index e887da535..b327d64fe 100644
--- a/datafusion/core/tests/sql/create_drop.rs
+++ b/datafusion/core/tests/sql/create_drop.rs
@@ -57,12 +57,14 @@ async fn create_or_replace_table_as() -> Result<()> {
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
// Create table
- ctx.sql("CREATE TABLE y AS VALUES (1,2),(3,4)")
+ let result = ctx
+ .sql("CREATE TABLE y AS VALUES (1,2),(3,4)")
.await
.unwrap()
.collect()
.await
.unwrap();
+ assert!(result.is_empty());
// Replace table
ctx.sql("CREATE OR REPLACE TABLE y AS VALUES (5,6)")
diff --git a/docs/source/user-guide/sql/ddl.md
b/docs/source/user-guide/sql/ddl.md
index 8d24a8e4c..118314fdc 100644
--- a/docs/source/user-guide/sql/ddl.md
+++ b/docs/source/user-guide/sql/ddl.md
@@ -78,16 +78,16 @@ PARTITIONED BY (year, month)
LOCATION '/mnt/nyctaxi';
```
-## CREATE MEMORY TABLE
+## CREATE TABLE
-Memory table can be created with query.
+An in-memory table can be created with a query or values list.
-```
-CREATE TABLE TABLE_NAME AS [SELECT | VALUES LIST]
-```
+<pre>
+CREATE [OR REPLACE] TABLE [IF NOT EXISTS] <b><i>table_name</i></b> AS [SELECT
| VALUES LIST];
+</pre>
```sql
-CREATE TABLE valuetable AS VALUES(1,'HELLO'),(12,'DATAFUSION');
+CREATE TABLE valuetable IF NOT EXISTS AS VALUES(1,'HELLO'),(12,'DATAFUSION');
CREATE TABLE memtable as select * from valuetable;
```