Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Fix bug JSON input barfs on {"emptylist":[]} #1063

Closed
wants to merge 2 commits into from
Closed
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
9 changes: 8 additions & 1 deletion parquet/src/arrow/array_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ struct ArrayReaderBuilder {
}

/// Used in type visitor.
#[derive(Clone)]
#[derive(Clone, Debug)]
struct ArrayReaderBuilderContext {
def_level: i16,
rep_level: i16,
Expand Down Expand Up @@ -1491,6 +1491,11 @@ impl<'a> TypeVisitor<Option<Box<dyn ArrayReader>>, &'a ArrayReaderBuilderContext
}
_ => (),
}

dbg!(&list_type);
dbg!(&context);
dbg!(&item_type);
dbg!(&new_context);

let item_reader = self
.dispatch(item_type.clone(), &new_context)
Expand Down Expand Up @@ -1836,6 +1841,8 @@ impl<'a> ArrayReaderBuilder {

for child in cur_type.get_fields() {
let mut struct_context = context.clone();
dbg!(&context);
dbg!(&child);
if let Some(child_reader) = self.dispatch(child.clone(), context)? {
// TODO: this results in calling get_arrow_field twice, it could be reused
// from child_reader above, by making child_reader carry its `Field`
Expand Down
31 changes: 31 additions & 0 deletions parquet/src/arrow/arrow_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,37 @@ mod tests {
one_column_roundtrip("list_single_column", values, true, Some(SMALL_SIZE / 2));
}

#[test]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 for test driven development 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

Also pls #1036 (comment)

fn null_list_single_column() {
let null_field = Field::new("item", DataType::Null, true);
let list_field =
Field::new("emptylist", DataType::List(Box::new(null_field)), true);

let schema = Schema::new(vec![list_field]);

// Build a ListArray[NullArray(0)]
let a_values = NullArray::new(SMALL_SIZE);
let a_value_offsets = arrow::buffer::Buffer::from(&[0, 0].to_byte_slice());
let a_list_data = ArrayData::builder(DataType::List(Box::new(Field::new(
"item",
DataType::Null,
true,
))))
.len(1)
.add_buffer(a_value_offsets)
.null_bit_buffer(Buffer::from(vec![0b00011011]))
.add_child_data(a_values.data().clone())
.build()
.unwrap();

let a = ListArray::from(a_list_data);
// let values = Arc::new(a);
// one_column_roundtrip("null_list_single_column", values, true, Some(SMALL_SIZE / 2));

let batch = RecordBatch::try_new(Arc::new(schema), vec![Arc::new(a)]).unwrap();
roundtrip("test_null_list_single_column.parquet", batch, None);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error I am now seeing comes from the reader being unable to read the parquet that is written out.

thread 'arrow::arrow_writer::tests::null_list_single_column' panicked at 'called `Result::unwrap()` on an `Err` value: ArrowError("Unable to convert parquet INT32 logical type Some(UNKNOWN(NullType)) or converted type NONE")', parquet/src/arrow/array_reader.rs:1502:14

I have peppered the code with dbg! to see if I can make sense of what's going on but so far all I have is a hunch that we've also got a potential bug in the reader. Detailed output from this test appears below:

---- arrow::arrow_writer::tests::null_list_single_column stdout ----
[parquet/src/arrow/levels.rs:754] &self = LevelInfo {
    definition: [
        1,
    ],
    repetition: Some(
        [
            0,
        ],
    ),
    array_offsets: [
        0,
        0,
    ],
    array_mask: [
        true,
    ],
    max_definition: 2,
    level_type: List(
        true,
    ),
    offset: 0,
    length: 0,
}
[parquet/src/arrow/levels.rs:788] &filtered = []
[parquet/src/arrow/array_reader.rs:1844] &context = ArrayReaderBuilderContext {
    def_level: 0,
    rep_level: 0,
    path: ColumnPath {
        parts: [
            "arrow_schema",
        ],
    },
}
[parquet/src/arrow/array_reader.rs:1845] &child = GroupType {
    basic_info: BasicTypeInfo {
        name: "emptylist",
        repetition: Some(
            OPTIONAL,
        ),
        converted_type: LIST,
        logical_type: Some(
            LIST(
                ListType,
            ),
        ),
        id: None,
    },
    fields: [
        GroupType {
            basic_info: BasicTypeInfo {
                name: "list",
                repetition: Some(
                    REPEATED,
                ),
                converted_type: NONE,
                logical_type: None,
                id: None,
            },
            fields: [
                PrimitiveType {
                    basic_info: BasicTypeInfo {
                        name: "item",
                        repetition: Some(
                            OPTIONAL,
                        ),
                        converted_type: NONE,
                        logical_type: Some(
                            UNKNOWN(
                                NullType,
                            ),
                        ),
                        id: None,
                    },
                    physical_type: INT32,
                    type_length: -1,
                    scale: -1,
                    precision: -1,
                },
            ],
        },
    ],
}
[parquet/src/arrow/array_reader.rs:1495] &list_type = GroupType {
    basic_info: BasicTypeInfo {
        name: "emptylist",
        repetition: Some(
            OPTIONAL,
        ),
        converted_type: LIST,
        logical_type: Some(
            LIST(
                ListType,
            ),
        ),
        id: None,
    },
    fields: [
        GroupType {
            basic_info: BasicTypeInfo {
                name: "list",
                repetition: Some(
                    REPEATED,
                ),
                converted_type: NONE,
                logical_type: None,
                id: None,
            },
            fields: [
                PrimitiveType {
                    basic_info: BasicTypeInfo {
                        name: "item",
                        repetition: Some(
                            OPTIONAL,
                        ),
                        converted_type: NONE,
                        logical_type: Some(
                            UNKNOWN(
                                NullType,
                            ),
                        ),
                        id: None,
                    },
                    physical_type: INT32,
                    type_length: -1,
                    scale: -1,
                    precision: -1,
                },
            ],
        },
    ],
}
[parquet/src/arrow/array_reader.rs:1496] &context = ArrayReaderBuilderContext {
    def_level: 0,
    rep_level: 0,
    path: ColumnPath {
        parts: [
            "arrow_schema",
        ],
    },
}
[parquet/src/arrow/array_reader.rs:1497] &item_type = PrimitiveType {
    basic_info: BasicTypeInfo {
        name: "item",
        repetition: Some(
            OPTIONAL,
        ),
        converted_type: NONE,
        logical_type: Some(
            UNKNOWN(
                NullType,
            ),
        ),
        id: None,
    },
    physical_type: INT32,
    type_length: -1,
    scale: -1,
    precision: -1,
}
[parquet/src/arrow/array_reader.rs:1498] &new_context = ArrayReaderBuilderContext {
    def_level: 2,
    rep_level: 1,
    path: ColumnPath {
        parts: [
            "arrow_schema",
            "emptylist",
        ],
    },
}
thread 'arrow::arrow_writer::tests::null_list_single_column' panicked at 'called `Result::unwrap()` on an `Err` value: ArrowError("Unable to convert parquet INT32 logical type Some(UNKNOWN(NullType)) or converted type NONE")', parquet/src/arrow/array_reader.rs:1502:14

}

#[test]
fn large_list_single_column() {
let a_values = Int32Array::from(vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
Expand Down
4 changes: 3 additions & 1 deletion parquet/src/arrow/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,10 @@ impl LevelInfo {

/// Given a level's information, calculate the offsets required to index an array correctly.
pub(crate) fn filter_array_indices(&self) -> Vec<usize> {
// happy path if not dealing with lists
dbg!(&self);
let is_nullable = match self.level_type {
LevelType::Primitive(is_nullable) => is_nullable,
LevelType::List(is_nullable) => is_nullable,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only change to the code path -- it addresses the error message we were seeing where the List leveltype was being picked up by the catchall (thus the panic).

_ => panic!(
"Cannot filter indices on a non-primitive array, found {:?}",
self.level_type
Expand Down Expand Up @@ -784,6 +785,7 @@ impl LevelInfo {
index += 1;
}
});
dbg!(&filtered);
filtered
}
}
Expand Down