Skip to content

SAMZA-2316: Validate that all non-default value fields in output schema are set in the projected fields. - #1149

Merged
atoomula merged 6 commits into
apache:masterfrom
atoomula:schema_validation
Sep 6, 2019
Merged

atoomula merged 6 commits into
apache:masterfrom
atoomula:schema_validation

Conversation

@atoomula

@atoomula atoomula commented Sep 4, 2019 •

Copy link
Copy Markdown
Contributor

No description provided.

@atoomula
atoomula requested a review from srinipunuru September 4, 2019 17:06
SqlSchemaBuilder schemaBuilder = SqlSchemaBuilder.builder();
for (Schema.Field field : fields) {
SqlFieldSchema fieldSchema = convertField(field.schema());
// Consider any field with default value as nullable. Is it the right assumption ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is slightly tricky. Nullable fields in avro is of type union with one of the value being null.
The fields with default value means they are optional during serializing and deserializing.

The behavior on the consumption side.

  1. All avro fields should have values including nullable fields as well as optional fields(fields with default values)

Behavior on the producer side.

  1. fields with default values are optional
  2. Nullable fields may still need values if they are not optional

So nullability and optionality are slightly different. I am not sure it is a good idea to conflate them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying the behavior. Updated the logic by separating out nullable fields and fields with default values. Using default values for validation but not nullable fields.

@weiqingy

weiqingy commented Sep 4, 2019

Copy link
Copy Markdown
Contributor

Nit: copy the words in the description to the title?

@atoomula atoomula changed the title SAMZA-2316: Validate that all non-default value fields in output schema are set i… SAMZA-2316: Validate that all non-default value fields in output schema are set in the projected fields. Sep 5, 2019

@srinipunuru srinipunuru left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


private SqlFieldSchema(SamzaSqlFieldType fieldType, SqlFieldSchema elementType, SqlFieldSchema valueType, SqlSchema rowSchema) {
private SqlFieldSchema(SamzaSqlFieldType fieldType, SqlFieldSchema elementType, SqlFieldSchema valueType,
SqlSchema rowSchema, boolean isNullable, boolean hasDefaultValue) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it makes sense to call the hasDefaultValue field as optionalField? I think it also is a good idea to document isNullable and isOptional in sqlFieldSchema to make the differences clear?

RelRecordType outputRecord = (RelRecordType) QueryPlanner.getSourceRelSchema(relSchemaProvider,
new RelSchemaConverter());
// Get Samza Sql schema along with Calcite schema. The reason is that the Calcite schema does not have a way
// to represent fields with default values while Samza Sql schema can represent default value fields. This is

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it makes sense to call these as optional fields rather than fields with default values?

SqlFieldSchema outputSqlFieldSchema = outputFieldSchemaMap.get(entry.getKey());

if (projectFieldType == null) {
if (entry.getKey().equals(SamzaSqlRelMessage.KEY_NAME) || outputSqlFieldSchema.hasDefaultValue()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add comments here on why we are special casing KEY_NAME field?

Comment thread samza-sql/src/main/java/org/apache/samza/sql/planner/SamzaSqlValidator.java Outdated
}
}

// Ensure that all projected fields exist in the output schema and are of the same type.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Rather than call them as projected fields can we say fields from sql statement?.


if (outputFieldType == null) {
if (entry.getKey().equals(SamzaSqlRelMessage.OP_NAME)) {
if (entry.getKey().equals(SamzaSqlRelMessage.OP_NAME) || entry.getKey().equals(SamzaSqlRelMessage.KEY_NAME)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add comments on why we are special casing these fields?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made key as optional and nullable value as it is by default being set to null in SamzaSqlRelMessage.

@srinipunuru srinipunuru left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@atoomula
atoomula merged commit 713a8bf into apache:master Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants