Skip to content

Commit

Permalink
print null value as null
Browse files Browse the repository at this point in the history
to be consistent with postgresql
  • Loading branch information
houqp committed Jul 22, 2021
1 parent 2cbf918 commit 3d620f6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion arrow/src/util/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ fn append_struct_field_string(
/// suitable for converting large arrays or record batches.
pub fn array_value_to_string(column: &array::ArrayRef, row: usize) -> Result<String> {
if column.is_null(row) {
return Ok("".to_string());
return Ok("null".to_string());
}
match column.data_type() {
DataType::Utf8 => make_string!(array::StringArray, column, row),
Expand Down
68 changes: 34 additions & 34 deletions arrow/src/util/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ mod tests {
use crate::{
array::{
self, new_null_array, Array, Date32Array, Date64Array, PrimitiveBuilder,
StringBuilder, StringDictionaryBuilder, Time32MillisecondArray,
Time32SecondArray, Time64MicrosecondArray, Time64NanosecondArray,
TimestampMicrosecondArray, TimestampMillisecondArray,
StringArray, StringBuilder, StringDictionaryBuilder, StructArray,
Time32MillisecondArray, Time32SecondArray, Time64MicrosecondArray,
Time64NanosecondArray, TimestampMicrosecondArray, TimestampMillisecondArray,
TimestampNanosecondArray, TimestampSecondArray,
},
datatypes::{DataType, Field, Int32Type, Schema},
Expand Down Expand Up @@ -148,14 +148,14 @@ mod tests {
let table = pretty_format_batches(&[batch])?;

let expected = vec![
"+---+-----+",
"| a | b |",
"+---+-----+",
"| a | 1 |",
"| b | |",
"| | 10 |",
"| d | 100 |",
"+---+-----+",
"+------+------+",
"| a | b |",
"+------+------+",
"| a | 1 |",
"| b | null |",
"| null | 10 |",
"| d | 100 |",
"+------+------+",
];

let actual: Vec<&str> = table.lines().collect();
Expand All @@ -180,8 +180,8 @@ mod tests {
let table = pretty_format_columns("a", &columns)?;

let expected = vec![
"+---+", "| a |", "+---+", "| a |", "| b |", "| |", "| d |", "| e |",
"| |", "| g |", "+---+",
"+------+", "| a |", "+------+", "| a |", "| b |", "| null |",
"| d |", "| e |", "| null |", "| g |", "+------+",
];

let actual: Vec<&str> = table.lines().collect();
Expand Down Expand Up @@ -212,14 +212,14 @@ mod tests {
let table = pretty_format_batches(&[batch]).unwrap();

let expected = vec![
"+---+---+---+",
"| a | b | c |",
"+---+---+---+",
"| | | |",
"| | | |",
"| | | |",
"| | | |",
"+---+---+---+",
"+------+------+------+",
"| a | b | c |",
"+------+------+------+",
"| null | null | null |",
"| null | null | null |",
"| null | null | null |",
"| null | null | null |",
"+------+------+------+",
];

let actual: Vec<&str> = table.lines().collect();
Expand Down Expand Up @@ -252,7 +252,7 @@ mod tests {
"| d1 |",
"+-------+",
"| one |",
"| |",
"| null |",
"| three |",
"+-------+",
];
Expand Down Expand Up @@ -297,7 +297,7 @@ mod tests {
"| f |",
"+---------------------+",
"| 1970-05-09 14:25:11 |",
"| |",
"| null |",
"+---------------------+",
];
check_datetime!(TimestampSecondArray, 11111111, expected);
Expand All @@ -310,7 +310,7 @@ mod tests {
"| f |",
"+-------------------------+",
"| 1970-01-01 03:05:11.111 |",
"| |",
"| null |",
"+-------------------------+",
];
check_datetime!(TimestampMillisecondArray, 11111111, expected);
Expand All @@ -323,7 +323,7 @@ mod tests {
"| f |",
"+----------------------------+",
"| 1970-01-01 00:00:11.111111 |",
"| |",
"| null |",
"+----------------------------+",
];
check_datetime!(TimestampMicrosecondArray, 11111111, expected);
Expand All @@ -336,7 +336,7 @@ mod tests {
"| f |",
"+-------------------------------+",
"| 1970-01-01 00:00:00.011111111 |",
"| |",
"| null |",
"+-------------------------------+",
];
check_datetime!(TimestampNanosecondArray, 11111111, expected);
Expand All @@ -349,7 +349,7 @@ mod tests {
"| f |",
"+------------+",
"| 1973-05-19 |",
"| |",
"| null |",
"+------------+",
];
check_datetime!(Date32Array, 1234, expected);
Expand All @@ -362,7 +362,7 @@ mod tests {
"| f |",
"+------------+",
"| 2005-03-18 |",
"| |",
"| null |",
"+------------+",
];
check_datetime!(Date64Array, 1111111100000, expected);
Expand All @@ -375,7 +375,7 @@ mod tests {
"| f |",
"+----------+",
"| 00:18:31 |",
"| |",
"| null |",
"+----------+",
];
check_datetime!(Time32SecondArray, 1111, expected);
Expand All @@ -388,7 +388,7 @@ mod tests {
"| f |",
"+--------------+",
"| 03:05:11.111 |",
"| |",
"| null |",
"+--------------+",
];
check_datetime!(Time32MillisecondArray, 11111111, expected);
Expand All @@ -401,7 +401,7 @@ mod tests {
"| f |",
"+-----------------+",
"| 00:00:11.111111 |",
"| |",
"| null |",
"+-----------------+",
];
check_datetime!(Time64MicrosecondArray, 11111111, expected);
Expand All @@ -414,7 +414,7 @@ mod tests {
"| f |",
"+--------------------+",
"| 00:00:00.011111111 |",
"| |",
"| null |",
"+--------------------+",
];
check_datetime!(Time64NanosecondArray, 11111111, expected);
Expand Down Expand Up @@ -462,7 +462,7 @@ mod tests {
"| f |",
"+-------+",
"| 1.01 |",
"| |",
"| null |",
"| 2.00 |",
"| 30.40 |",
"+-------+",
Expand Down Expand Up @@ -498,7 +498,7 @@ mod tests {

let table = pretty_format_batches(&[batch])?;
let expected = vec![
"+------+", "| f |", "+------+", "| 101 |", "| |", "| 200 |",
"+------+", "| f |", "+------+", "| 101 |", "| null |", "| 200 |",
"| 3040 |", "+------+",
];

Expand Down

0 comments on commit 3d620f6

Please sign in to comment.