-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Bugfix: Remove df-cli specific SQL statment options before executing with DataFusion #8426
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,20 +30,23 @@ use url::Url; | |
|
||
pub async fn get_s3_object_store_builder( | ||
url: &Url, | ||
cmd: &CreateExternalTable, | ||
cmd: &mut CreateExternalTable, | ||
) -> Result<AmazonS3Builder> { | ||
let bucket_name = get_bucket_name(url)?; | ||
let mut builder = AmazonS3Builder::from_env().with_bucket_name(bucket_name); | ||
|
||
if let (Some(access_key_id), Some(secret_access_key)) = ( | ||
cmd.options.get("access_key_id"), | ||
cmd.options.get("secret_access_key"), | ||
// These options are datafusion-cli specific and must be removed before passing through to datafusion. | ||
// Otherwise, a Configuration error will be raised. | ||
cmd.options.remove("access_key_id"), | ||
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. This is a very subtle change -- maybe we can add a comment explaining why these options are removed Likewise below 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. Added some comments explaining why the keys are removed/plan made mutable within datafusion-cli. I also updated one of the unit tests to invoke FileTypeWriterOptions::build to test for this issue in the future. 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. Thank you |
||
cmd.options.remove("secret_access_key"), | ||
) { | ||
println!("removing secret access key!"); | ||
builder = builder | ||
.with_access_key_id(access_key_id) | ||
.with_secret_access_key(secret_access_key); | ||
|
||
if let Some(session_token) = cmd.options.get("session_token") { | ||
if let Some(session_token) = cmd.options.remove("session_token") { | ||
builder = builder.with_token(session_token); | ||
} | ||
} else { | ||
|
@@ -66,7 +69,7 @@ pub async fn get_s3_object_store_builder( | |
builder = builder.with_credentials(credentials); | ||
} | ||
|
||
if let Some(region) = cmd.options.get("region") { | ||
if let Some(region) = cmd.options.remove("region") { | ||
builder = builder.with_region(region); | ||
} | ||
|
||
|
@@ -99,7 +102,7 @@ impl CredentialProvider for S3CredentialProvider { | |
|
||
pub fn get_oss_object_store_builder( | ||
url: &Url, | ||
cmd: &CreateExternalTable, | ||
cmd: &mut CreateExternalTable, | ||
) -> Result<AmazonS3Builder> { | ||
let bucket_name = get_bucket_name(url)?; | ||
let mut builder = AmazonS3Builder::from_env() | ||
|
@@ -109,15 +112,15 @@ pub fn get_oss_object_store_builder( | |
.with_region("do_not_care"); | ||
|
||
if let (Some(access_key_id), Some(secret_access_key)) = ( | ||
cmd.options.get("access_key_id"), | ||
cmd.options.get("secret_access_key"), | ||
cmd.options.remove("access_key_id"), | ||
cmd.options.remove("secret_access_key"), | ||
) { | ||
builder = builder | ||
.with_access_key_id(access_key_id) | ||
.with_secret_access_key(secret_access_key); | ||
} | ||
|
||
if let Some(endpoint) = cmd.options.get("endpoint") { | ||
if let Some(endpoint) = cmd.options.remove("endpoint") { | ||
builder = builder.with_endpoint(endpoint); | ||
} | ||
|
||
|
@@ -126,21 +129,21 @@ pub fn get_oss_object_store_builder( | |
|
||
pub fn get_gcs_object_store_builder( | ||
url: &Url, | ||
cmd: &CreateExternalTable, | ||
cmd: &mut CreateExternalTable, | ||
) -> Result<GoogleCloudStorageBuilder> { | ||
let bucket_name = get_bucket_name(url)?; | ||
let mut builder = GoogleCloudStorageBuilder::from_env().with_bucket_name(bucket_name); | ||
|
||
if let Some(service_account_path) = cmd.options.get("service_account_path") { | ||
if let Some(service_account_path) = cmd.options.remove("service_account_path") { | ||
builder = builder.with_service_account_path(service_account_path); | ||
} | ||
|
||
if let Some(service_account_key) = cmd.options.get("service_account_key") { | ||
if let Some(service_account_key) = cmd.options.remove("service_account_key") { | ||
builder = builder.with_service_account_key(service_account_key); | ||
} | ||
|
||
if let Some(application_credentials_path) = | ||
cmd.options.get("application_credentials_path") | ||
cmd.options.remove("application_credentials_path") | ||
{ | ||
builder = builder.with_application_credentials(application_credentials_path); | ||
} | ||
|
@@ -180,9 +183,9 @@ mod tests { | |
let sql = format!("CREATE EXTERNAL TABLE test STORED AS PARQUET OPTIONS('access_key_id' '{access_key_id}', 'secret_access_key' '{secret_access_key}', 'region' '{region}', 'session_token' {session_token}) LOCATION '{location}'"); | ||
|
||
let ctx = SessionContext::new(); | ||
let plan = ctx.state().create_logical_plan(&sql).await?; | ||
let mut plan = ctx.state().create_logical_plan(&sql).await?; | ||
|
||
if let LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) = &plan { | ||
if let LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) = &mut plan { | ||
let builder = get_s3_object_store_builder(table_url.as_ref(), cmd).await?; | ||
// get the actual configuration information, then assert_eq! | ||
let config = [ | ||
|
@@ -212,9 +215,9 @@ mod tests { | |
let sql = format!("CREATE EXTERNAL TABLE test STORED AS PARQUET OPTIONS('access_key_id' '{access_key_id}', 'secret_access_key' '{secret_access_key}', 'endpoint' '{endpoint}') LOCATION '{location}'"); | ||
|
||
let ctx = SessionContext::new(); | ||
let plan = ctx.state().create_logical_plan(&sql).await?; | ||
let mut plan = ctx.state().create_logical_plan(&sql).await?; | ||
|
||
if let LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) = &plan { | ||
if let LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) = &mut plan { | ||
let builder = get_oss_object_store_builder(table_url.as_ref(), cmd)?; | ||
// get the actual configuration information, then assert_eq! | ||
let config = [ | ||
|
@@ -244,9 +247,9 @@ mod tests { | |
let sql = format!("CREATE EXTERNAL TABLE test STORED AS PARQUET OPTIONS('service_account_path' '{service_account_path}', 'service_account_key' '{service_account_key}', 'application_credentials_path' '{application_credentials_path}') LOCATION '{location}'"); | ||
|
||
let ctx = SessionContext::new(); | ||
let plan = ctx.state().create_logical_plan(&sql).await?; | ||
let mut plan = ctx.state().create_logical_plan(&sql).await?; | ||
|
||
if let LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) = &plan { | ||
if let LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) = &mut plan { | ||
let builder = get_gcs_object_store_builder(table_url.as_ref(), cmd)?; | ||
// get the actual configuration information, then assert_eq! | ||
let config = [ | ||
|
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.
❤️