-
Notifications
You must be signed in to change notification settings - Fork 3k
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: pulsar ingestion fails when Avro schema is missing namespace or name #12058
base: master
Are you sure you want to change the base?
fix: pulsar ingestion fails when Avro schema is missing namespace or name #12058
Conversation
fix: pulsar ingestion fails when Avro schema is missing namespace or name Problem Description The root cause is that the code attempts to concatenate these fields without checking if they exist: Fix Description Modified Files |
namespace = avro_schema.get("namespace") | ||
name = avro_schema.get("name") | ||
if not namespace: | ||
logger.warning("namespace is missing in schema, using 'default_namespace'") | ||
namespace = "default_namespace" | ||
if not name: | ||
logger.warning("name is missing in schema, using 'default_name'") | ||
name = "default_name" | ||
self.schema_name = namespace + "." + name | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking avro specs, both namespace
and name
are optional.
Only name
is required in the case of record
or enum
and optional if eg primitive types or arrays.
So the fix makes sense to cover that scenario.
I'm concerned about having such a fallback values, since they do not match the original avro schema definition.
Ideally, if both namespace
and name
are missed, schema_name
should be null or empty string.
This schema_name
is used as the schemaName
for the SchemaMetadataKey
, which is required and len > 1.
datahub/metadata-models/src/main/pegasus/com/linkedin/schema/SchemaMetadataKey.pdl
Lines 10 to 17 in b091e46
/** | |
* Schema name e.g. PageViewEvent, identity.Profile, ams.account_management_tracking | |
*/ | |
@validate.strlen = { | |
"max" : 500, | |
"min" : 1 | |
} | |
schemaName: string |
So what about something like that:
namespace = avro_schema.get("namespace") | |
name = avro_schema.get("name") | |
if not namespace: | |
logger.warning("namespace is missing in schema, using 'default_namespace'") | |
namespace = "default_namespace" | |
if not name: | |
logger.warning("name is missing in schema, using 'default_name'") | |
name = "default_name" | |
self.schema_name = namespace + "." + name | |
self.schema_name = "null" | |
if avro_schema.get("namespace") and avro_schema.get("name"): | |
self.schema_name = avro_schema.get("namespace") + "." + avro_schema.get("name") | |
elif avro_schema.get("namespace"): | |
self.schema_name = avro_schema.get("namespace") | |
elif avro_schema.get("name"): | |
self.schema_name = avro_schema.get("name") |
WDYT @hsheth2 ? Other solutions may require to update the SchemaMetadataKey
definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that seems pretty reasonable
we don't really use the schema_name for much, so a fallback value of null
feels reasonable over throwing an exception / reporting a warning
fix: pulsar ingestion fails when Avro schema is missing namespace or name
Checklist