From e02a17aecfe8dc479083571275d95d2c8c8b5dab Mon Sep 17 00:00:00 2001 From: Thomas Larsson Date: Thu, 8 Apr 2021 23:23:12 +0200 Subject: [PATCH] =?UTF-8?q?fix(ingestion):=20Support=20mapping=20from=20av?= =?UTF-8?q?ro=20"boolean"=20and=20"map"=20types=20t=E2=80=A6=20(#2364)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: #2363 Co-authored-by: thomas.larsson --- .../ingestion/extractor/schema_util.py | 3 +++ .../tests/unit/test_schema_util.py | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/metadata-ingestion/src/datahub/ingestion/extractor/schema_util.py b/metadata-ingestion/src/datahub/ingestion/extractor/schema_util.py index 9b95236fdf..af7411a02e 100644 --- a/metadata-ingestion/src/datahub/ingestion/extractor/schema_util.py +++ b/metadata-ingestion/src/datahub/ingestion/extractor/schema_util.py @@ -9,6 +9,7 @@ from datahub.metadata.com.linkedin.pegasus2avro.schema import ( BytesTypeClass, EnumTypeClass, FixedTypeClass, + MapTypeClass, NullTypeClass, NumberTypeClass, RecordTypeClass, @@ -25,6 +26,7 @@ logger = logging.getLogger(__name__) _field_type_mapping = { "null": NullTypeClass, "bool": BooleanTypeClass, + "boolean": BooleanTypeClass, "int": NumberTypeClass, "long": NumberTypeClass, "float": NumberTypeClass, @@ -32,6 +34,7 @@ _field_type_mapping = { "bytes": BytesTypeClass, "string": StringTypeClass, "record": RecordTypeClass, + "map": MapTypeClass, "enum": EnumTypeClass, "array": ArrayTypeClass, "union": UnionTypeClass, diff --git a/metadata-ingestion/tests/unit/test_schema_util.py b/metadata-ingestion/tests/unit/test_schema_util.py index ea8b255045..06c7087939 100644 --- a/metadata-ingestion/tests/unit/test_schema_util.py +++ b/metadata-ingestion/tests/unit/test_schema_util.py @@ -47,6 +47,23 @@ EXAMPLE_EVENT_OPTIONAL_FIELD_VIA_PRIMITIVE_TYPE = """ } """ +SCHEMA_WITH_MAP_TYPE_FIELD = """ +{ + "type": "record", + "name": "some.event.name", + "namespace": "some.namespace", + "fields": [ + { + "name": "some.field.name", + "type": { + "type": "map", + "values": "long" + } + } + ] +} +""" + class SchemaUtilTest(unittest.TestCase): def test_avro_schema_to_mce_fields_events_with_nullable_fields(self): @@ -61,3 +78,11 @@ class SchemaUtilTest(unittest.TestCase): fields = avro_schema_to_mce_fields(event) self.assertEqual(1, len(fields)) self.assertTrue(fields[0].nullable) + + def test_avro_schema_to_mce_fields_sample_events_with_different_field_types(self): + + EXAMPLES = [SCHEMA_WITH_MAP_TYPE_FIELD] + + for schema in EXAMPLES: + fields = avro_schema_to_mce_fields(schema) + self.assertEqual(1, len(fields))