fix(ingestion): Make AVRO schema parsing robust to exceptions. (#3541)

This commit is contained in:
Ravindra Lanka 2021-11-09 18:01:18 -08:00 committed by GitHub
parent 4bcc1f04f6
commit c3f1bf0534
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 4 deletions

View File

@ -440,8 +440,14 @@ def avro_schema_to_mce_fields(
:param is_key_schema: True if it is a key-schema. Default is False (value-schema).
:return: The list of MCE compatible SchemaFields.
"""
return list(
AvroToMceSchemaConverter.to_mce_fields(
avro_schema_string, is_key_schema, default_nullable
schema_fields: List[SchemaField] = []
try:
schema_fields = list(
AvroToMceSchemaConverter.to_mce_fields(
avro_schema_string, is_key_schema, default_nullable
)
)
)
except Exception:
logger.exception(f"Failed to parse {avro_schema_string} to mce_fields.")
return schema_fields

View File

@ -642,3 +642,19 @@ def test_key_schema_handling():
assret_field_paths_match(fields, expected_field_paths)
for f in fields:
assert f.isPartOfKey
def test_ignore_exceptions():
schema: str = """
["string",
{
"name": "event_ts",
"type": "long",
"logicalType": "timestamp-millis",
"tags": [
"business-timestamp"
]
}]
"""
fields: List[SchemaField] = avro_schema_to_mce_fields(schema, is_key_schema=False)
assert not fields