Skip to content

Commit

Permalink
Merge branch 'feature/format-options' of https://github.com/synnada-a…
Browse files Browse the repository at this point in the history
…i/datafusion-upstream into feature/format-options
  • Loading branch information
berkaysynnada committed May 9, 2024
2 parents f0f6f09 + 4873d61 commit d64de7e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
17 changes: 6 additions & 11 deletions datafusion-cli/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,20 @@
use std::borrow::Cow;

use crate::highlighter::{NoSyntaxHighlighter, SyntaxHighlighter};

use datafusion::common::sql_datafusion_err;
use datafusion::error::DataFusionError;
use datafusion::sql::parser::{DFParser, Statement};
use datafusion::sql::sqlparser::dialect::dialect_from_str;
use datafusion::sql::sqlparser::parser::ParserError;
use rustyline::completion::Completer;
use rustyline::completion::FilenameCompleter;
use rustyline::completion::Pair;

use rustyline::completion::{Completer, FilenameCompleter, Pair};
use rustyline::error::ReadlineError;
use rustyline::highlight::Highlighter;
use rustyline::hint::Hinter;
use rustyline::validate::ValidationContext;
use rustyline::validate::ValidationResult;
use rustyline::validate::Validator;
use rustyline::Context;
use rustyline::Helper;
use rustyline::Result;

use crate::highlighter::{NoSyntaxHighlighter, SyntaxHighlighter};
use rustyline::validate::{ValidationContext, ValidationResult, Validator};
use rustyline::{Context, Helper, Result};

pub struct CliHelper {
completer: FilenameCompleter,
Expand Down
23 changes: 12 additions & 11 deletions datafusion/common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1564,20 +1564,21 @@ config_namespace_with_hashmap! {
config_namespace! {
/// Options controlling CSV format
pub struct CsvOptions {
/// If the first line of the CSV is column names.
/// If not specified, uses default from `CREATE TABLE` command, if any.
pub has_header: Option<bool>, default =None
/// Specifies whether there is a CSV header (i.e. the first line
/// consists of is column names). If not specified, uses default from
/// the `CREATE TABLE` command, if any.
pub has_header: Option<bool>, default = None
pub delimiter: u8, default = b','
pub quote: u8, default = b'"'
pub escape: Option<u8>, default = None
pub compression: CompressionTypeVariant, default = CompressionTypeVariant::UNCOMPRESSED
pub schema_infer_max_rec: usize, default = 100
pub date_format: Option<String>, default = None
pub datetime_format: Option<String>, default = None
pub timestamp_format: Option<String>, default = None
pub timestamp_tz_format: Option<String>, default = None
pub time_format: Option<String>, default = None
pub null_value: Option<String>, default = None
pub date_format: Option<String>, default = None
pub datetime_format: Option<String>, default = None
pub timestamp_format: Option<String>, default = None
pub timestamp_tz_format: Option<String>, default = None
pub time_format: Option<String>, default = None
pub null_value: Option<String>, default = None
}
}

Expand Down Expand Up @@ -1606,8 +1607,8 @@ impl CsvOptions {
self
}

/// True if the first line is a header. If the condition of having header
/// is not set by the format options, session state decides it.
/// Returns true if the first line is a header. If format options does not
/// specify whether there is a header, consults the configuration.
pub fn has_header(&self, config_opt: &ConfigOptions) -> bool {
self.has_header.unwrap_or(config_opt.catalog.has_header)
}
Expand Down
12 changes: 6 additions & 6 deletions datafusion/core/src/datasource/file_format/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ use crate::datasource::physical_plan::{
use crate::error::Result;
use crate::execution::context::SessionState;
use crate::physical_plan::insert::{DataSink, DataSinkExec};
use crate::physical_plan::{DisplayAs, DisplayFormatType, Statistics};
use crate::physical_plan::{ExecutionPlan, SendableRecordBatchStream};
use crate::physical_plan::{
DisplayAs, DisplayFormatType, ExecutionPlan, SendableRecordBatchStream, Statistics,
};

use arrow::array::RecordBatch;
use arrow::csv::WriterBuilder;
Expand Down Expand Up @@ -242,8 +243,8 @@ impl FileFormat for CsvFormat {
) -> Result<Arc<dyn ExecutionPlan>> {
let exec = CsvExec::new(
conf,
// If the condition of having header is not set by
// the format options, session state decides it.
// If format options does not specify whether there is a header,
// we consult configuration options.
self.options.has_header(state.config_options()),
self.options.delimiter,
self.options.quote,
Expand Down Expand Up @@ -819,8 +820,7 @@ mod tests {
has_header: bool,
) -> Result<Arc<dyn ExecutionPlan>> {
let root = format!("{}/csv", crate::test_util::arrow_test_data());
let mut format = CsvFormat::default();
format = format.with_has_header(has_header);
let format = CsvFormat::default().with_has_header(has_header);
scan_format(state, &format, &root, file_name, projection, limit).await
}

Expand Down

0 comments on commit d64de7e

Please sign in to comment.