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

Schema::try_merge should be able to merge List of any data type with List of Null data type #5843

Closed
mnpw opened this issue Jun 4, 2024 · 1 comment · Fixed by #5852
Closed
Labels
arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog

Comments

@mnpw
Copy link
Contributor

mnpw commented Jun 4, 2024

Describe the bug
Schema::try_merge should be able to merge List(any data type) and List(Null data type)

To Reproduce

use serde_json::json;

let o_1 = vec![
    json!({"a": [1,2,3]}),
    json!({"a": [4,5,6]}),
];

let o_2 = vec![
    json!({"a": []}),
    json!({"a": []}),
];

let o_3 = vec![
    json!({"a": []}),
    json!({"a": [7,8,9]}),
];

let schema_1 = arrow_json::reader::infer_json_schema_from_iterator(o_1.iter().map(Ok)).unwrap();
println!("{:?}", schema_1);
// Schema { fields: [Field { name: "a", data_type: List(Field { name: "item", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }], metadata: {} }

let schema_2 = arrow_json::reader::infer_json_schema_from_iterator(o_2.iter().map(Ok)).unwrap();
println!("{:?}", schema_2);
// Schema { fields: [Field { name: "a", data_type: List(Field { name: "item", data_type: Null, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }], metadata: {} }

let schema_3 = arrow_json::reader::infer_json_schema_from_iterator(o_3.iter().map(Ok)).unwrap();
println!("{:?}", schema_3);
// Schema { fields: [Field { name: "a", data_type: List(Field { name: "item", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }], metadata: {} }

let merged = Schema::try_merge([schema_1, schema_2, schema_3]);
println!("{:?}", merged)
// Err(SchemaError("Fail to merge schema field 'a' because the from data_type = List(Field { name: \"item\", data_type: Null, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }) does not equal List(Field { name: \"item\", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} })"))

Expected behavior
Merge of List( data type) and List(Null) should be possible

let merged = Schema::try_merge([schema_1, schema_2, schema_3]);
println!("{:?}", merged)
// Ok(Schema { fields: [Field { name: "a", data_type: List(Field { name: "item", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }], metadata: {} })

Additional context
N/A

@mnpw mnpw added the bug label Jun 4, 2024
@tustvold tustvold added enhancement Any new improvement worthy of a entry in the changelog and removed bug labels Jun 4, 2024
@alamb alamb added the arrow Changes to the arrow crate label Jul 2, 2024
@alamb
Copy link
Contributor

alamb commented Jul 2, 2024

label_issue.py automatically added labels {'arrow'} from #5852

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants