Skip to content

Commit

Permalink
feat(ingest): throw codegen error on duplicate class names (datahub-p…
Browse files Browse the repository at this point in the history
  • Loading branch information
hsheth2 authored and Alexander Sukhoborov committed Mar 1, 2024
1 parent bc200a1 commit 4aa1dc3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions metadata-ingestion/scripts/avro_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,27 @@ def merge_schemas(schemas_obj: List[dict]) -> str:
# Combine schemas as a "union" of all of the types.
merged = ["null"] + schemas_obj

# Check that we don't have the same class name in multiple namespaces.
names_to_spaces: Dict[str, str] = {}

# Patch add_name method to NOT complain about duplicate names.
class NamesWithDups(avro.schema.Names):
def add_name(self, name_attr, space_attr, new_schema):

to_add = avro.schema.Name(name_attr, space_attr, self.default_namespace)
assert to_add.name
assert to_add.space
assert to_add.fullname

if to_add.name in names_to_spaces:
if names_to_spaces[to_add.name] != to_add.space:
raise ValueError(
f"Duplicate name {to_add.name} in namespaces {names_to_spaces[to_add.name]} and {to_add.space}. "
"This will cause conflicts in the generated code."
)
else:
names_to_spaces[to_add.name] = to_add.space

self.names[to_add.fullname] = new_schema
return to_add

Expand Down

0 comments on commit 4aa1dc3

Please sign in to comment.