-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix querying and defining table / view names with period #4530
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a5d5c45
Add tests for names with period
alamb 5169621
adjust docstrings
alamb 9c9c313
Improve docstrings
alamb ad007bf
Add tests coverage
alamb 569979c
Update datafusion/common/src/table_reference.rs
alamb c03cf2b
Add tests for creating tables with three periods
alamb e100bf2
Merge remote-tracking branch 'apache/master' into alamb/table_names_w…
alamb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,22 +24,21 @@ use datafusion::datasource::MemTable; | |
use datafusion::prelude::SessionContext; | ||
use datafusion_common::{DFSchema, DataFusionError}; | ||
use datafusion_expr::Expr as DFExpr; | ||
use datafusion_sql::planner::{PlannerContext, SqlToRel}; | ||
use datafusion_sql::planner::{object_name_to_table_reference, PlannerContext, SqlToRel}; | ||
use sqlparser::ast::{Expr, SetExpr, Statement as SQLStatement}; | ||
use std::sync::Arc; | ||
|
||
pub async fn insert(ctx: &SessionContext, insert_stmt: &SQLStatement) -> Result<String> { | ||
pub async fn insert(ctx: &SessionContext, insert_stmt: SQLStatement) -> Result<String> { | ||
// First, use sqlparser to get table name and insert values | ||
let table_name; | ||
let table_reference; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the test harness to use the new name handling as well |
||
let insert_values: Vec<Vec<Expr>>; | ||
match insert_stmt { | ||
SQLStatement::Insert { | ||
table_name: name, | ||
source, | ||
.. | ||
table_name, source, .. | ||
} => { | ||
table_reference = object_name_to_table_reference(table_name)?; | ||
|
||
// Todo: check columns match table schema | ||
table_name = name.to_string(); | ||
match &*source.body { | ||
SetExpr::Values(values) => { | ||
insert_values = values.0.clone(); | ||
|
@@ -54,9 +53,9 @@ pub async fn insert(ctx: &SessionContext, insert_stmt: &SQLStatement) -> Result< | |
} | ||
|
||
// Second, get batches in table and destroy the old table | ||
let mut origin_batches = ctx.table(table_name.as_str())?.collect().await?; | ||
let schema = ctx.table_provider(table_name.as_str())?.schema(); | ||
ctx.deregister_table(table_name.as_str())?; | ||
let mut origin_batches = ctx.table(&table_reference)?.collect().await?; | ||
let schema = ctx.table_provider(&table_reference)?.schema(); | ||
ctx.deregister_table(&table_reference)?; | ||
|
||
// Third, transfer insert values to `RecordBatch` | ||
// Attention: schema info can be ignored. (insert values don't contain schema info) | ||
|
@@ -84,7 +83,7 @@ pub async fn insert(ctx: &SessionContext, insert_stmt: &SQLStatement) -> Result< | |
|
||
// Final, create new memtable with same schema. | ||
let new_provider = MemTable::try_new(schema, vec![origin_batches])?; | ||
ctx.register_table(table_name.as_str(), Arc::new(new_provider))?; | ||
ctx.register_table(&table_reference, Arc::new(new_provider))?; | ||
|
||
Ok("".to_string()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if this is correct as it potentially splits on "." -- but I chose to keep the existing behavior