Skip to content

Commit

Permalink
fix(CLI): can not create external tables with format options (#10739)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahgao authored May 31, 2024
1 parent a803214 commit 7fd286b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions datafusion-cli/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::collections::HashMap;
use std::fs::File;
use std::io::prelude::*;
use std::io::BufReader;
use std::str::FromStr;

use crate::helper::split_from_semicolon;
use crate::print_format::PrintFormat;
Expand Down Expand Up @@ -300,11 +301,13 @@ async fn create_plan(
// datafusion-cli specific options before passing through to datafusion. Otherwise, datafusion
// will raise Configuration errors.
if let LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) = &plan {
// To support custom formats, treat error as None
let format = FileType::from_str(&cmd.file_type).ok();
register_object_store_and_config_extensions(
ctx,
&cmd.location,
&cmd.options,
None,
format,
)
.await?;
}
Expand Down Expand Up @@ -398,11 +401,12 @@ mod tests {
let plan = ctx.state().create_logical_plan(sql).await?;

if let LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) = &plan {
let format = FileType::from_str(&cmd.file_type).ok();
register_object_store_and_config_extensions(
&ctx,
&cmd.location,
&cmd.options,
None,
format,
)
.await?;
} else {
Expand Down Expand Up @@ -601,4 +605,16 @@ mod tests {

Ok(())
}

#[tokio::test]
async fn create_external_table_format_option() -> Result<()> {
let location = "path/to/file.cvs";

// Test with format options
let sql =
format!("CREATE EXTERNAL TABLE test STORED AS CSV LOCATION '{location}' OPTIONS('format.has_header' 'true')");
create_external_table_test(location, &sql).await.unwrap();

Ok(())
}
}

0 comments on commit 7fd286b

Please sign in to comment.