-
Notifications
You must be signed in to change notification settings - Fork 30
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 issue with unsupported list values and tuple #103
base: main
Are you sure you want to change the base?
Changes from all commits
5e21660
3fa8461
b08244b
71091d3
6810e16
13fdd7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,27 +84,31 @@ def get_type(value: dict) -> dict: | |
} | ||
|
||
classes_seen.add(class_name) | ||
elif t == "array" and "prefixItems" in value: | ||
# Handle tuple since it is considered an array | ||
prefix_items = value.get("prefixItems") | ||
possible_types = [] | ||
for prefix_item in prefix_items: | ||
item_type = get_type(prefix_item)["type"] | ||
if isinstance(item_type, list): | ||
possible_types.extend([x for x in item_type if x not in possible_types]) | ||
elif item_type not in possible_types: | ||
possible_types.append(item_type) | ||
avro_type_dict["type"] = {"type": "array", "items": possible_types} | ||
elif t == "array": | ||
items = value.get("items") | ||
tn = get_type(items) | ||
# If items in array are a object: | ||
|
||
# If items in array are an object: | ||
if "$ref" in items: | ||
tn = tn["type"] | ||
# If items in array are a logicalType | ||
|
||
# Necessary to handle things like logical types, list of lists, and list with union | ||
if ( | ||
isinstance(tn, dict) | ||
and isinstance(tn.get("type", {}), dict) | ||
and tn.get("type", {}).get("logicalType") is not None | ||
and isinstance(tn.get("type", None), (dict, list)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change to pull the
The |
||
): | ||
tn = tn["type"] | ||
# If items in array are an array, the structure must be corrected | ||
if ( | ||
isinstance(tn, dict) | ||
and isinstance(tn.get("type", {}), dict) | ||
and tn.get("type", {}).get("type") == "array" | ||
): | ||
items = tn["type"]["items"] | ||
tn = {"type": "array", "items": items} | ||
avro_type_dict["type"] = {"type": "array", "items": tn} | ||
elif t == "string" and f == "date-time": | ||
avro_type_dict["type"] = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The best we can do for a tuple with the AVRO schema is figure out all of the unique types and say the given field can be an array that is one of those unique types. We figure out the minimum set of possible types based on the
prefixItems
and return that as the type for the array.