-
Notifications
You must be signed in to change notification settings - Fork 547
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
Adding translated.from
annotation when using SchemaTranslator
#970
base: master
Are you sure you want to change the base?
Conversation
if (!ConfigurableSchemaComparator.equals(avroSchemaFromEmbedded, avroSchemaFromJson, | ||
new SchemaComparisonConfiguration(true, true, true, false, true, true, | ||
Collections.singleton((TRANSLATED_FROM_SOURCE_OPTION))))) { |
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.
This is a bit hard to read. Why can you provide a constructor in ConfigurableSchemaComparator
to allow configure what options to be excluded? Also why DATA_PROPERTY
above is not handled simiarly?
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.
This check will never fail for DATA_PROPERTY
because the code above this check adds it just before the check.
Object embededSchemaPropertyVal = avroSchemaFromJson.getObjectProp(DATA_PROPERTY);
if (embededSchemaPropertyVal != null)
{
avroSchemaFromEmbedded.addProp(DATA_PROPERTY, embededSchemaPropertyVal);
}
Updated the SchemaComparisonConfiguration call
if (dataSchema instanceof NamedDataSchema) { | ||
NamedDataSchema namedDataSchema = (NamedDataSchema) dataSchema; | ||
// Add annotation if not already present | ||
if (!namedDataSchema.getProperties().containsKey(TRANSLATED_FROM_SOURCE_OPTION)) { |
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.
what should you do if existing translated_from prop is different from updated one?
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.
It doesn't update the source in that case. So, if schema A
translates to B
, and B
is translated to C
,
the translatedFrom option in C will be A
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.
My original question is talking about an error case, I am guessing that should never happen and we should throw error?
But your response provides me something different from my understanding, I thought that annotation is just for direct source, seems not?
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.
We don't need to stop users from translating a translated schema again, as it is allowed right now in SchemaTranslator right now, and stopping it might fail users.
However, we can use this annotation to fail other flows like PDL -> Proto or Avro -> proto.
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.
Based on this logic, translated.from
annotation is used to indicate the root source, not directly translated source, is this clearly communicated?
} | ||
dataSchema = namedDataSchema; | ||
} | ||
return dataSchema; |
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.
this will have side effect of changing passed DataSchema
?
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.
there should be none, except one additional json property in the result avro schema, which is the requirement of this change. This new property will identify the avro schemas as a translated schema.
li.data.translated.from
annotation when using SchemaTranslatorschema.translated.from.src
annotation when using SchemaTranslator
@@ -53,6 +58,7 @@ public class SchemaTranslator | |||
private static final Logger log = LoggerFactory.getLogger(SchemaTranslator.class); | |||
|
|||
public static final String DATA_PROPERTY = "com.linkedin.data"; | |||
public static final String TRANSLATED_FROM_SOURCE_OPTION = "schema.translated.from.src"; |
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.
will translated.from
enough?
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.
Yes. any unique key will work.
I'll update to translated.from
if (dataSchema instanceof NamedDataSchema) { | ||
NamedDataSchema namedDataSchema = (NamedDataSchema) dataSchema; | ||
// Add annotation if not already present | ||
if (!namedDataSchema.getProperties().containsKey(TRANSLATED_FROM_SOURCE_OPTION)) { |
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.
My original question is talking about an error case, I am guessing that should never happen and we should throw error?
But your response provides me something different from my understanding, I thought that annotation is just for direct source, seems not?
schema.translated.from.src
annotation when using SchemaTranslatortranslated.from
annotation when using SchemaTranslator
|
It was the description for the initial PR. The unit tests are updated now. Updated the |
What
Adding an annotation in translated schemas, translated through SchemaTranslator
Why
This will help in figuring out whether a schema is translated or source of truth.
This annotation can help in determining different behavior for SoT and translated schemas
Test
Updated Unit tests