return false;
}
List<TypedField> columnFields = streamSym.getFields();
for (int i = 0; i < columnFields.size(); i++) {
TypedField col = columnFields.get(i);
Type colType = col.getType();
// Get the schema field that matches this column name.
Schema.Field schemaField = null;
for (Schema.Field testSchemaField : schemaFields) {
if (testSchemaField.name().equals(col.getUserAlias())) {
schemaField = testSchemaField;
break;
}
}
if (null == schemaField) {
// Can't find a field in the schema to match the current column.
LOG.error("The Avro schema does not contain a field with the same name "
+ "as column '" + col.getUserAlias() + "'.");
return false;
}
// Are the schemas compatible?
if (!schemaField.schema().equals(colType.getAvroSchema())) {
boolean warned = false;
if (colType.isNullable() && colType.isPrimitive()) {
// A common error is that the rtsql type is nullable and the schema
// type isn't. Give a specific suggestion in this case.
Type nonNullVersion = Type.getPrimitive(colType.getPrimitiveTypeName());
if (schemaField.schema().equals(nonNullVersion.getAvroSchema())) {
LOG.error("Column " + col.getUserAlias() + " has type " + colType
+ ", but requires type " + nonNullVersion + " to match the Avro schema.");
warned = true;
}
}
if (!warned) {
// Give a generic error message.
LOG.error("Column " + col.getUserAlias() + " has type " + colType
+ " with avro schema " + colType.getAvroSchema()
+ " but the stream schema field " + schemaField.name() + " has "
+ " an incompatible Avro schema: " + schemaField.schema());
}
return false;