Skip to content

Commit

Permalink
added "DEFAULT_CLI_FORMAT_OPTIONS" for cli and sqllogic test (#14052)
Browse files Browse the repository at this point in the history
* added "DEFAULT_CLI_FORMAT_OPTIONS"  for cli and sqllotic test

* cargo fmt fix

* fixed few errors
  • Loading branch information
jatin510 authored Jan 11, 2025
1 parent d91a7c0 commit 17446ad
Show file tree
Hide file tree
Showing 14 changed files with 370 additions and 365 deletions.
8 changes: 4 additions & 4 deletions datafusion-cli/src/print_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use arrow::datatypes::SchemaRef;
use arrow::json::{ArrayWriter, LineDelimitedWriter};
use arrow::record_batch::RecordBatch;
use arrow::util::pretty::pretty_format_batches_with_options;
use datafusion::common::format::DEFAULT_FORMAT_OPTIONS;
use datafusion::common::format::DEFAULT_CLI_FORMAT_OPTIONS;
use datafusion::error::Result;

/// Allow records to be printed in different formats
Expand Down Expand Up @@ -133,7 +133,7 @@ fn format_batches_with_maxrows<W: std::io::Write>(

let formatted = pretty_format_batches_with_options(
&filtered_batches,
&DEFAULT_FORMAT_OPTIONS,
&DEFAULT_CLI_FORMAT_OPTIONS,
)?;
if over_limit {
let mut formatted_str = format!("{}", formatted);
Expand All @@ -145,7 +145,7 @@ fn format_batches_with_maxrows<W: std::io::Write>(
}
MaxRows::Unlimited => {
let formatted =
pretty_format_batches_with_options(batches, &DEFAULT_FORMAT_OPTIONS)?;
pretty_format_batches_with_options(batches, &DEFAULT_CLI_FORMAT_OPTIONS)?;
writeln!(writer, "{}", formatted)?;
}
}
Expand Down Expand Up @@ -201,7 +201,7 @@ impl PrintFormat {
let empty_batch = RecordBatch::new_empty(schema);
let formatted = pretty_format_batches_with_options(
&[empty_batch],
&DEFAULT_FORMAT_OPTIONS,
&DEFAULT_CLI_FORMAT_OPTIONS,
)?;
writeln!(writer, "{}", formatted)?;
}
Expand Down
4 changes: 4 additions & 0 deletions datafusion/common/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ pub const DEFAULT_CAST_OPTIONS: CastOptions<'static> = CastOptions {
safe: false,
format_options: DEFAULT_FORMAT_OPTIONS,
};

pub const DEFAULT_CLI_FORMAT_OPTIONS: FormatOptions<'static> = FormatOptions::new()
.with_duration_format(DurationFormat::Pretty)
.with_null("NULL");
2 changes: 1 addition & 1 deletion datafusion/functions-nested/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ SELECT MAP('type', 'test');
SELECT MAP(['POST', 'HEAD', 'PATCH'], [41, 33, null]);
----
{POST: 41, HEAD: 33, PATCH: }
{POST: 41, HEAD: 33, PATCH: NULL}
SELECT MAP([[1,2], [3,4]], ['a', 'b']);
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use arrow::array::{Array, AsArray};
use arrow::datatypes::Fields;
use arrow::util::display::ArrayFormatter;
use arrow::{array, array::ArrayRef, datatypes::DataType, record_batch::RecordBatch};
use datafusion_common::format::DEFAULT_FORMAT_OPTIONS;
use datafusion_common::format::DEFAULT_CLI_FORMAT_OPTIONS;
use datafusion_common::DataFusionError;
use std::path::PathBuf;
use std::sync::LazyLock;
Expand Down Expand Up @@ -240,7 +240,8 @@ pub fn cell_to_string(col: &ArrayRef, row: usize) -> Result<String> {
Ok(cell_to_string(dict.values(), key)?)
}
_ => {
let f = ArrayFormatter::try_new(col.as_ref(), &DEFAULT_FORMAT_OPTIONS);
let f =
ArrayFormatter::try_new(col.as_ref(), &DEFAULT_CLI_FORMAT_OPTIONS);
Ok(f.unwrap().value(row).to_string())
}
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/sqllogictest/test_files/aggregate.slt
Original file line number Diff line number Diff line change
Expand Up @@ -4236,7 +4236,7 @@ query T?
SELECT tag, array_agg(millis - arrow_cast(secs, 'Timestamp(Millisecond, None)')) FROM t GROUP BY tag ORDER BY tag;
----
X [0 days 0 hours 0 mins 0.011 secs, 0 days 0 hours 0 mins 0.123 secs]
Y [, 0 days 0 hours 0 mins 0.432 secs]
Y [NULL, 0 days 0 hours 0 mins 0.432 secs]

statement ok
drop table t_source;
Expand Down
Loading

0 comments on commit 17446ad

Please sign in to comment.