-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(bigtable): Support Avro schema bundles in Bigtable's Admin API #14351
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import com.google.bigtable.admin.v2.SchemaBundleName; | ||
| import com.google.common.base.Objects; | ||
| import com.google.common.base.Preconditions; | ||
| import java.util.List; | ||
| import javax.annotation.Nonnull; | ||
|
|
||
| /** | ||
|
|
@@ -42,7 +43,8 @@ private SchemaBundle(@Nonnull com.google.bigtable.admin.v2.SchemaBundle proto) { | |
| Preconditions.checkNotNull(proto); | ||
| Preconditions.checkArgument(!proto.getName().isEmpty(), "SchemaBundle must have a name"); | ||
| Preconditions.checkArgument( | ||
| proto.hasProtoSchema(), "Schemabundle must have a proto_schema field"); | ||
| proto.hasProtoSchema() || proto.hasAvroSchema(), | ||
| "Schemabundle must have a proto_schema or avro_schema field"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is proto.hasProtoSchema && proto.hasAvroSchema() also invalid?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In API definition,
If the GAPIC correctly translates that into the Java classes, I think there won't be a schema bundle with proto.hasProtoSchema && proto.hasAvroSchema()
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a comment?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also in this case, in CreateSchemaBundle, should we validate that avro schema is not set when setting proto schema, vice versa? |
||
| this.proto = proto; | ||
| this.schemaBundleName = SchemaBundleName.parse(proto.getName()); | ||
| } | ||
|
|
@@ -67,6 +69,14 @@ public com.google.protobuf.ByteString getProtoSchema() { | |
| throw new IllegalStateException("This SchemaBundle doesn't have a valid type specified"); | ||
| } | ||
|
|
||
| /** Gets the avro schema of this schema bundle. */ | ||
| public List<String> getAvroSchema() { | ||
| if (proto.hasAvroSchema()) { | ||
| return proto.getAvroSchema().getJsonSchemasList(); | ||
| } | ||
| throw new IllegalStateException("This SchemaBundle does not contain an Avro schema"); | ||
| } | ||
|
|
||
| /** | ||
| * Creates the request protobuf. This method is considered an internal implementation detail and | ||
| * not meant to be used by applications. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| package com.google.cloud.bigtable.admin.v2.models; | ||
|
|
||
| import com.google.api.core.InternalApi; | ||
| import com.google.bigtable.admin.v2.AvroSchema; | ||
| import com.google.bigtable.admin.v2.ProtoSchema; | ||
| import com.google.cloud.bigtable.admin.v2.internal.NameUtil; | ||
| import com.google.common.base.Objects; | ||
|
|
@@ -27,6 +28,8 @@ | |
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Paths; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import javax.annotation.Nonnull; | ||
|
|
||
| /** | ||
|
|
@@ -90,13 +93,29 @@ public UpdateSchemaBundleRequest setProtoSchemaFile(@Nonnull String protoSchemaF | |
| public UpdateSchemaBundleRequest setProtoSchema(@Nonnull ByteString protoSchema) | ||
| throws IOException { | ||
| Preconditions.checkNotNull(protoSchema, "protoSchema must be set"); | ||
| requestBuilder.setSchemaBundle( | ||
| com.google.bigtable.admin.v2.SchemaBundle.newBuilder() | ||
| .setProtoSchema(ProtoSchema.newBuilder().setProtoDescriptors(protoSchema))); | ||
| requestBuilder | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we validate that avro schema is not set? |
||
| .getSchemaBundleBuilder() | ||
| .setProtoSchema(ProtoSchema.newBuilder().setProtoDescriptors(protoSchema)); | ||
| updateFieldMask(com.google.bigtable.admin.v2.SchemaBundle.PROTO_SCHEMA_FIELD_NUMBER); | ||
| return this; | ||
| } | ||
|
|
||
| /** Sets the avro schema for this schema bundle. */ | ||
| public UpdateSchemaBundleRequest setAvroSchema(@Nonnull String avroSchema) { | ||
| Preconditions.checkNotNull(avroSchema, "avroSchema must be set"); | ||
| return setAvroSchema(Collections.singletonList(avroSchema)); | ||
| } | ||
|
|
||
| /** Sets the avro schema for this schema bundle. */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sets a list of avro schema for this schema bundle. |
||
| public UpdateSchemaBundleRequest setAvroSchema(@Nonnull List<String> avroSchema) { | ||
| Preconditions.checkNotNull(avroSchema, "avroSchema must be set"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we validate proto schema is not set? |
||
| requestBuilder | ||
| .getSchemaBundleBuilder() | ||
| .setAvroSchema(AvroSchema.newBuilder().addAllJsonSchemas(avroSchema)); | ||
| updateFieldMask(com.google.bigtable.admin.v2.SchemaBundle.AVRO_SCHEMA_FIELD_NUMBER); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Configures if safety warnings should be disabled. If set, then non backwards compatible changes | ||
| * are allowed. | ||
|
|
||
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.
proto schema doesn't have a list override, why is it needed for avro schema?
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.
Because their proto definitions differ: http://google3/google/bigtable/admin/v2/table.proto;l=1121-1157;rcl=974104276!
i.e.,
ProtoSchemadefines a single bytesproto_descriptorsfield, whereasAvroSchemadefines arepeated string json_schemasfield to accept multiple schema files in a bundle.