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

Add support for DG-410 Fix doc/defaults in Avro converter #159

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.wepay.kafka.connect.bigquery.exception.ConversionConnectException;

import org.apache.kafka.connect.data.Schema;
import org.apache.kafka.connect.data.Schema.Type;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -57,6 +56,8 @@ public class BigQuerySchemaConverter implements SchemaConverter<com.google.cloud

private static final Map<Schema.Type, LegacySQLTypeName> PRIMITIVE_TYPE_MAP;

private static final String AVRO_DOC_PARAMETER = "io.confluent.connect.avro.field.doc.";

static {
// force registration
new DebeziumLogicalConverters();
Expand Down Expand Up @@ -178,6 +179,9 @@ private Optional<com.google.cloud.bigquery.Field.Builder> convertField(Schema ka
setNullability(kafkaConnectSchema, res);
if (kafkaConnectSchema.doc() != null) {
res.setDescription(kafkaConnectSchema.doc());
} else if (kafkaConnectSchema.parameters() != null &&
kafkaConnectSchema.parameters().get(AVRO_DOC_PARAMETER + fieldName) != null){
res.setDescription(kafkaConnectSchema.parameters().get(AVRO_DOC_PARAMETER + fieldName));

Choose a reason for hiding this comment

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

We're introducing Avro converter-specific logic into the connector here. That doesn't feel right; connectors should be largely agnostic about the converter that they're configured with, with the possible exception of requiring schemas with the data that they process.

If we add this logic here, what's to stop other converter developers from filing similar PRs against this and other connector repos to add more converter-specific logic?

Do you know why the Avro converter was changed in such a way that causes a property that used to be set as the doc of the Connect schema to be set instead as a converter-specific property, leaving the doc blank? The linked PR's description is a little thin and the accompanying issue is pretty lengthy. It'd be nice if you could provide a summary of the motivation for that change (if you're already aware of the rationale), or maybe bring in someone who worked on it to help explain things here.

As things stand right now, I'm hesitant to include this change and think that an adjustment of the converter logic may be warranted in its place.

}
return res;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,30 @@ public void testDescription() {
assertEquals(bigQueryExpectedSchema, bigQueryTestSchema);
}

@Test
public void testDescriptionInField() {
final String fieldName = "WithDoc";
final String fieldDoc = "test documentation";

com.google.cloud.bigquery.Schema bigQueryExpectedSchema =
com.google.cloud.bigquery.Schema.of(
com.google.cloud.bigquery.Field.newBuilder(fieldName,
LegacySQLTypeName.STRING)
.setMode(com.google.cloud.bigquery.Field.Mode.REQUIRED)
.setDescription(fieldDoc)
.build()
);

Schema kafkaConnectTestSchema =
SchemaBuilder.struct()
.field(fieldName, SchemaBuilder.string().parameter("io.confluent.connect.avro.field.doc." + fieldName,fieldDoc).build())
Copy link
Member

Choose a reason for hiding this comment

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

The Doc will be in the Struct's parameter, not fieldSchema's parameter.

.build();

com.google.cloud.bigquery.Schema bigQueryTestSchema =
new BigQuerySchemaConverter(false).convertSchema(kafkaConnectTestSchema);
assertEquals(bigQueryExpectedSchema, bigQueryTestSchema);
}

Choose a reason for hiding this comment

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

Should we add another case that ensures backwards compatibility by converting a Connect schema that has both a standard doc and an Avro converter-specific doc property, and verifies that the former is used for the field's description?


@Test
public void testAllFieldsNullable() {
final String fieldName = "RequiredField";
Expand Down