Skip to content

Commit 17446ad

Browse files
authored
added "DEFAULT_CLI_FORMAT_OPTIONS" for cli and sqllogic test (#14052)
* added "DEFAULT_CLI_FORMAT_OPTIONS" for cli and sqllotic test * cargo fmt fix * fixed few errors
1 parent d91a7c0 commit 17446ad

File tree

14 files changed

+370
-365
lines changed

14 files changed

+370
-365
lines changed

datafusion-cli/src/print_format.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use arrow::datatypes::SchemaRef;
2626
use arrow::json::{ArrayWriter, LineDelimitedWriter};
2727
use arrow::record_batch::RecordBatch;
2828
use arrow::util::pretty::pretty_format_batches_with_options;
29-
use datafusion::common::format::DEFAULT_FORMAT_OPTIONS;
29+
use datafusion::common::format::DEFAULT_CLI_FORMAT_OPTIONS;
3030
use datafusion::error::Result;
3131

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

134134
let formatted = pretty_format_batches_with_options(
135135
&filtered_batches,
136-
&DEFAULT_FORMAT_OPTIONS,
136+
&DEFAULT_CLI_FORMAT_OPTIONS,
137137
)?;
138138
if over_limit {
139139
let mut formatted_str = format!("{}", formatted);
@@ -145,7 +145,7 @@ fn format_batches_with_maxrows<W: std::io::Write>(
145145
}
146146
MaxRows::Unlimited => {
147147
let formatted =
148-
pretty_format_batches_with_options(batches, &DEFAULT_FORMAT_OPTIONS)?;
148+
pretty_format_batches_with_options(batches, &DEFAULT_CLI_FORMAT_OPTIONS)?;
149149
writeln!(writer, "{}", formatted)?;
150150
}
151151
}
@@ -201,7 +201,7 @@ impl PrintFormat {
201201
let empty_batch = RecordBatch::new_empty(schema);
202202
let formatted = pretty_format_batches_with_options(
203203
&[empty_batch],
204-
&DEFAULT_FORMAT_OPTIONS,
204+
&DEFAULT_CLI_FORMAT_OPTIONS,
205205
)?;
206206
writeln!(writer, "{}", formatted)?;
207207
}

datafusion/common/src/format.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ pub const DEFAULT_CAST_OPTIONS: CastOptions<'static> = CastOptions {
2727
safe: false,
2828
format_options: DEFAULT_FORMAT_OPTIONS,
2929
};
30+
31+
pub const DEFAULT_CLI_FORMAT_OPTIONS: FormatOptions<'static> = FormatOptions::new()
32+
.with_duration_format(DurationFormat::Pretty)
33+
.with_null("NULL");

datafusion/functions-nested/src/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ SELECT MAP('type', 'test');
195195
196196
SELECT MAP(['POST', 'HEAD', 'PATCH'], [41, 33, null]);
197197
----
198-
{POST: 41, HEAD: 33, PATCH: }
198+
{POST: 41, HEAD: 33, PATCH: NULL}
199199
200200
SELECT MAP([[1,2], [3,4]], ['a', 'b']);
201201
----

datafusion/sqllogictest/src/engines/datafusion_engine/normalize.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use arrow::array::{Array, AsArray};
2020
use arrow::datatypes::Fields;
2121
use arrow::util::display::ArrayFormatter;
2222
use arrow::{array, array::ArrayRef, datatypes::DataType, record_batch::RecordBatch};
23-
use datafusion_common::format::DEFAULT_FORMAT_OPTIONS;
23+
use datafusion_common::format::DEFAULT_CLI_FORMAT_OPTIONS;
2424
use datafusion_common::DataFusionError;
2525
use std::path::PathBuf;
2626
use std::sync::LazyLock;
@@ -240,7 +240,8 @@ pub fn cell_to_string(col: &ArrayRef, row: usize) -> Result<String> {
240240
Ok(cell_to_string(dict.values(), key)?)
241241
}
242242
_ => {
243-
let f = ArrayFormatter::try_new(col.as_ref(), &DEFAULT_FORMAT_OPTIONS);
243+
let f =
244+
ArrayFormatter::try_new(col.as_ref(), &DEFAULT_CLI_FORMAT_OPTIONS);
244245
Ok(f.unwrap().value(row).to_string())
245246
}
246247
}

datafusion/sqllogictest/test_files/aggregate.slt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4236,7 +4236,7 @@ query T?
42364236
SELECT tag, array_agg(millis - arrow_cast(secs, 'Timestamp(Millisecond, None)')) FROM t GROUP BY tag ORDER BY tag;
42374237
----
42384238
X [0 days 0 hours 0 mins 0.011 secs, 0 days 0 hours 0 mins 0.123 secs]
4239-
Y [, 0 days 0 hours 0 mins 0.432 secs]
4239+
Y [NULL, 0 days 0 hours 0 mins 0.432 secs]
42404240

42414241
statement ok
42424242
drop table t_source;

0 commit comments

Comments
 (0)