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

feat(ingest): throw codegen error on duplicate class names #9960

Merged
merged 1 commit into from
Mar 1, 2024
Merged
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
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
Loading