Skip to content

Commit

Permalink
Support data type map in Glue import. (#340)
Browse files Browse the repository at this point in the history
* Support data type map in Glue import.
Resolves #334

* Support data type map in Glue import.
Resolves #334
  • Loading branch information
jochenchrist authored Jul 21, 2024
1 parent 3b3419a commit 56f4dbe
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Support data type map in Glue import. (#340)

### Fixed

- Fix an issue where the quality and definition `$ref` are not always resolved.
Expand Down
8 changes: 7 additions & 1 deletion datacontract/imports/glue_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def create_typed_field(dtype: str) -> Field:
"""
field = Field()
dtype = dtype.strip().lower().replace(" ", "")
if dtype.startswith(("array", "struct")):
if dtype.startswith(("array", "struct", "map")):
orig_dtype: str = dtype
if dtype.startswith("array"):
field.type = "array"
Expand All @@ -195,6 +195,12 @@ def create_typed_field(dtype: str) -> Field:
field.type = "struct"
for f in split_struct(orig_dtype[7:-1]):
field.fields[f.split(":", 1)[0].strip()] = create_typed_field(f.split(":", 1)[1])
elif dtype.startswith("map"):
field.type = "map"
key_type = orig_dtype[4:-1].split(",", 1)[0]
value_type = orig_dtype[4:-1].split(",", 1)[1]
field.keys = create_typed_field(key_type)
field.values = create_typed_field(value_type)
else:
field.type = map_type_from_sql(dtype)
return field
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/glue/datacontract.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ models:
type: string
sub_field_four:
type: integer
field_eight:
type: map
keys:
type: string
values:
type: integer
part_one:
description: Partition Key
required: True
Expand Down
4 changes: 4 additions & 0 deletions tests/test_import_glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def setup_mock_glue(aws_credentials):
"Name": "field_seven",
"Type": "array<struct<sub_field_three:string, sub_field_four:int>>",
},
{
"Name": "field_eight",
"Type": "map<string,int>",
},
]
},
"PartitionKeys": [
Expand Down

0 comments on commit 56f4dbe

Please sign in to comment.