Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Fixed error in displaying dictionaries with nulls in values #334

Merged
merged 1 commit into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/array/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ macro_rules! dyn_dict {
.downcast_ref::<DictionaryArray<$ty>>()
.unwrap();
let keys = a.keys();
let display = get_value_display(a.values().as_ref());
let display = get_display(a.values().as_ref());
Box::new(move |row: usize| display(keys.value(row) as usize))
}};
}
Expand Down
25 changes: 25 additions & 0 deletions tests/it/io/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,31 @@ fn write_dictionary() -> Result<()> {
Ok(())
}

#[test]
fn dictionary_validities() -> Result<()> {
// define a schema.
let field_type = DataType::Dictionary(Box::new(DataType::Int32), Box::new(DataType::Int32));
let schema = Arc::new(Schema::new(vec![Field::new("d1", field_type, true)]));

let keys = PrimitiveArray::<i32>::from([Some(1), None, Some(0)]);
let values = PrimitiveArray::<i32>::from([None, Some(10)]);
let array = DictionaryArray::<i32>::from_data(keys, Arc::new(values));

let batch = RecordBatch::try_new(schema, vec![Arc::new(array)])?;

let table = write(&[batch]);

let expected = vec![
"+----+", "| d1 |", "+----+", "| 10 |", "| |", "| |", "+----+",
];

let actual: Vec<&str> = table.lines().collect();

assert_eq!(expected, actual, "Actual result:\n{}", table);

Ok(())
}

/// Generate an array with type $ARRAYTYPE with a numeric value of
/// $VALUE, and compare $EXPECTED_RESULT to the output of
/// formatting that array with `write`
Expand Down