Amar3tto commented on code in PR #40261:
URL: https://github.com/apache/beam/pull/40261#discussion_r4311012748


##########
sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigtable/changestreams/BigtableChangeStreamReadSchemaTransformProviderTest.java:
##########


Review Comment:
   Added a mutationToRow test covering the top-level mutation fields and nested 
entries.



##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigtable/changestreams/BigtableChangeStreamReadSchemaTransformProvider.java:
##########
@@ -0,0 +1,402 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.gcp.bigtable.changestreams;
+
+import static 
org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkArgument;
+
+import com.google.auto.service.AutoService;
+import com.google.auto.value.AutoValue;
+import com.google.cloud.bigtable.data.v2.models.AddToCell;
+import com.google.cloud.bigtable.data.v2.models.ChangeStreamMutation;
+import com.google.cloud.bigtable.data.v2.models.DeleteCells;
+import com.google.cloud.bigtable.data.v2.models.DeleteFamily;
+import com.google.cloud.bigtable.data.v2.models.Entry;
+import com.google.cloud.bigtable.data.v2.models.MergeToCell;
+import com.google.cloud.bigtable.data.v2.models.Range;
+import com.google.cloud.bigtable.data.v2.models.SetCell;
+import com.google.cloud.bigtable.data.v2.models.Value;
+import com.google.protobuf.ByteString;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.apache.beam.sdk.io.gcp.bigtable.BigtableIO;
+import org.apache.beam.sdk.schemas.AutoValueSchema;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.schemas.annotations.DefaultSchema;
+import org.apache.beam.sdk.schemas.annotations.SchemaFieldDescription;
+import org.apache.beam.sdk.schemas.transforms.SchemaTransform;
+import org.apache.beam.sdk.schemas.transforms.SchemaTransformProvider;
+import org.apache.beam.sdk.schemas.transforms.TypedSchemaTransformProvider;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionRowTuple;
+import org.apache.beam.sdk.values.Row;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.joda.time.Instant;
+
+/**
+ * A {@link TypedSchemaTransformProvider} for reading Cloud Bigtable change 
streams.
+ *
+ * <p>Internal only.
+ */
+@AutoService(SchemaTransformProvider.class)
+public class BigtableChangeStreamReadSchemaTransformProvider
+    extends TypedSchemaTransformProvider<
+        
BigtableChangeStreamReadSchemaTransformProvider.BigtableChangeStreamReadConfiguration>
 {
+
+  private static final String OUTPUT_TAG = "output";
+
+  static final Schema VALUE_SCHEMA =
+      Schema.builder()
+          .addStringField("type")
+          .addNullableInt64Field("int_value")
+          .addNullableInt64Field("raw_timestamp_micros")
+          .addNullableByteArrayField("raw_value")
+          .build();
+
+  static final Schema TIMESTAMP_RANGE_SCHEMA =
+      Schema.builder()
+          .addStringField("start_bound")
+          .addNullableInt64Field("start_timestamp_micros")
+          .addStringField("end_bound")
+          .addNullableInt64Field("end_timestamp_micros")
+          .build();
+
+  static final Schema ENTRY_SCHEMA =
+      Schema.builder()
+          .addStringField("type")
+          .addStringField("family_name")
+          .addNullableByteArrayField("qualifier")
+          .addNullableInt64Field("timestamp_micros")
+          .addNullableByteArrayField("value")
+          .addNullableRowField("timestamp_range", TIMESTAMP_RANGE_SCHEMA)
+          .addNullableRowField("value_qualifier", VALUE_SCHEMA)
+          .addNullableRowField("value_timestamp", VALUE_SCHEMA)
+          .addNullableRowField("value_input", VALUE_SCHEMA)
+          .build();
+
+  static final Schema CHANGE_STREAM_MUTATION_SCHEMA =
+      Schema.builder()
+          .addByteArrayField("row_key")
+          .addStringField("mutation_type")
+          .addStringField("source_cluster_id")
+          .addDateTimeField("commit_timestamp")
+          .addInt32Field("tie_breaker")
+          .addStringField("token")
+          .addDateTimeField("estimated_low_watermark")
+          .addArrayField("entries", Schema.FieldType.row(ENTRY_SCHEMA))
+          .build();
+
+  @Override
+  protected Class<BigtableChangeStreamReadConfiguration> configurationClass() {
+    return BigtableChangeStreamReadConfiguration.class;
+  }
+
+  @Override
+  protected SchemaTransform from(BigtableChangeStreamReadConfiguration 
configuration) {
+    return new BigtableChangeStreamReadSchemaTransform(configuration);
+  }
+
+  @Override
+  public String identifier() {
+    return "beam:schematransform:org.apache.beam:bigtable_cdc_read:v1";
+  }
+
+  @Override
+  public String description() {
+    return "Reads change stream records from a Google Cloud Bigtable table.";

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to