mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-17 03:43:56 +00:00
fix(ingest/mongodb): fix schema inference for lists of values (#9145)
This commit is contained in:
parent
932eebea35
commit
50789224a1
@ -16,7 +16,7 @@ class SchemaDescription(BasicSchemaDescription):
|
|||||||
nullable: bool # if field is ever missing
|
nullable: bool # if field is ever missing
|
||||||
|
|
||||||
|
|
||||||
def is_field_nullable(doc: Dict[str, Any], field_path: Tuple) -> bool:
|
def is_field_nullable(doc: Dict[str, Any], field_path: Tuple[str, ...]) -> bool:
|
||||||
"""
|
"""
|
||||||
Check if a nested field is nullable in a document from a collection.
|
Check if a nested field is nullable in a document from a collection.
|
||||||
|
|
||||||
@ -54,7 +54,10 @@ def is_field_nullable(doc: Dict[str, Any], field_path: Tuple) -> bool:
|
|||||||
# count empty lists of nested objects as nullable
|
# count empty lists of nested objects as nullable
|
||||||
if len(value) == 0:
|
if len(value) == 0:
|
||||||
return True
|
return True
|
||||||
return any(is_field_nullable(x, remaining_fields) for x in doc[field])
|
return any(
|
||||||
|
isinstance(x, dict) and is_field_nullable(x, remaining_fields)
|
||||||
|
for x in doc[field]
|
||||||
|
)
|
||||||
|
|
||||||
# any other types to check?
|
# any other types to check?
|
||||||
# raise ValueError("Nested type not 'list' or 'dict' encountered")
|
# raise ValueError("Nested type not 'list' or 'dict' encountered")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user