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(ingestion): Fix nullability determination for the AVRO fixed type. #5023

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,14 @@ def _is_nullable(self, schema: avro.schema.Schema) -> bool:
return self._is_nullable(schema.type)
if isinstance(schema, avro.schema.UnionSchema):
return any(self._is_nullable(sub_schema) for sub_schema in schema.schemas)
elif isinstance(schema, avro.schema.PrimitiveSchema):
return schema.type == AVRO_TYPE_NULL or schema.props.get("_nullable", False)
else:
return self.default_nullable
if (
isinstance(schema, avro.schema.PrimitiveSchema)
and schema.type == AVRO_TYPE_NULL
):
return True
if isinstance(schema.props, dict):
return schema.props.get("_nullable", self.default_nullable)
return self.default_nullable

def _get_cur_field_path(self) -> str:
return ".".join(self._prefix_name_stack)
Expand Down
21 changes: 21 additions & 0 deletions metadata-ingestion/tests/unit/test_schema_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@
}
"""

SCHEMA_WITH_OPTIONAL_FIELD_VIA_FIXED_TYPE: str = json.dumps(
{
"type": "record",
"name": "__struct_",
"fields": [
{
"name": "value",
"type": {
"type": "fixed",
"name": "__fixed_d9d2d051916045d9975d6c573aaabb89",
"size": 4,
"native_data_type": "fixed[4]",
"_nullable": True,
},
},
],
}
)


def log_field_paths(fields: List[SchemaField]) -> None:
logger.debug('FieldPaths=\n"' + '",\n"'.join(f.fieldPath for f in fields) + '"')
Expand Down Expand Up @@ -93,11 +112,13 @@ def assert_field_paths_match(
SCHEMA_WITH_OPTIONAL_FIELD_VIA_UNION_TYPE,
SCHEMA_WITH_OPTIONAL_FIELD_VIA_UNION_TYPE_NULL_ISNT_FIRST_IN_UNION,
SCHEMA_WITH_OPTIONAL_FIELD_VIA_PRIMITIVE_TYPE,
SCHEMA_WITH_OPTIONAL_FIELD_VIA_FIXED_TYPE,
],
ids=[
"optional_field_via_union_type",
"optional_field_via_union_null_not_first",
"optional_field_via_primitive",
"optional_field_via_fixed",
],
)
def test_avro_schema_to_mce_fields_events_with_nullable_fields(schema):
Expand Down