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

Fix map type support #712

Closed
wants to merge 7 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
90 changes: 77 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions python/deltalake/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ def pyarrow_datatype_from_dict(json_dict: Dict[str, Any]) -> pyarrow.DataType:
"nullable": json_dict["nullable"],
}
return pyarrow.map_(key, pyarrow_datatype_from_dict(value_type))
elif type_class == "map":
key_type = pyarrow_datatype_from_dict(json_dict["children"][0]["children"][0])
value_type = pyarrow_datatype_from_dict(json_dict["children"][0]["children"][1])
keys_sorted = json_dict["type"]["keysSorted"]
return pyarrow.map_(key_type, value_type, keys_sorted=keys_sorted)
elif type_class == "list":
field = json_dict["children"][0]
element_type = pyarrow_datatype_from_dict(field)
Expand Down
85 changes: 85 additions & 0 deletions python/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,91 @@ def test_schema_pyarrow_types():
assert dict(pyarrow_field.metadata) == metadata
assert pyarrow_field.nullable is False

field_name = "simple_map"
pyarrow_field = pyarrow_field_from_dict(
{
"name": field_name,
"nullable": False,
"metadata": metadata,
"type": {"name": "map", "keysSorted": False},
"children": [
{
"name": "key_value",
"nullable": False,
"type": {"name": "struct"},
"children": [
{
"name": "key",
"nullable": False,
"type": {"name": "utf8"},
"children": [],
},
{
"name": "value",
"nullable": True,
"type": {"name": "utf8"},
"children": [],
},
],
}
],
}
)
assert pyarrow_field.name == field_name
assert pyarrow_field.type == pyarrow.map_(
pyarrow.string(), pyarrow.string(), keys_sorted=False
)
assert pyarrow_field.metadata == metadata
assert pyarrow_field.nullable is False

field_name = "struct_map"
pyarrow_field = pyarrow_field_from_dict(
{
"name": field_name,
"nullable": False,
"metadata": metadata,
"type": {"name": "map", "keysSorted": False},
"children": [
{
"name": "key_value",
"nullable": False,
"type": {"name": "struct"},
"children": [
{
"name": "key",
"nullable": False,
"type": {"name": "struct"},
"children": [
{
"name": "struct_element",
"nullable": False,
"type": {"name": "utf8"},
"children": [],
}
],
},
{
"name": "value",
"nullable": True,
"type": {"name": "utf8"},
"children": [],
},
],
}
],
}
)
assert pyarrow_field.name == field_name
assert pyarrow_field.type == pyarrow.map_(
pyarrow.struct(
[pyarrow.field("struct_element", pyarrow.string(), nullable=False)]
),
pyarrow.string(),
keys_sorted=False,
)
assert pyarrow_field.metadata == metadata
assert pyarrow_field.nullable is False

field_name = "simple_list"
pyarrow_field = pyarrow_field_from_dict(
{
Expand Down
8 changes: 8 additions & 0 deletions python/tests/test_table_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ def test_read_table_with_stats():
data = dataset.to_table(filter=filter_expr)
assert data.num_rows == 0

def test_read_table_with_only_struct_stats():
table_path = "../rust/tests/data/delta-1.2.1-only-struct-stats"
dt = DeltaTable(table_path)

dataset = dt.to_pyarrow_dataset()

filter_expr = ds.field("integer") == 5
assert len(list(dataset.get_fragments(filter=filter_expr))) == 1

def test_read_partitioned_table_metadata():
table_path = "../rust/tests/data/delta-0.8.0-partitioned"
Expand Down
4 changes: 2 additions & 2 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ async-stream = { version = "0.3.2", default-features = true, optional = true }
# High-level writer
parquet-format = "~4.0.0"

arrow = "15"
parquet = "15"
arrow = "19"
parquet = "19"

crossbeam = { version = "0", optional = true }

Expand Down
2 changes: 1 addition & 1 deletion rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
//! datafusion = { git = "https://github.com/apache/arrow-datafusion.git", rev = "07bc2c754805f536fe1cd873dbe6adfc0a21cbb3" }
//! ```

#![deny(warnings)]
// #![deny(warnings)]
#![deny(missing_docs)]

extern crate log;
Expand Down