You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "nancyxu123 (via GitHub)" <gi...@apache.org> on 2023/01/21 05:49:15 UTC

[GitHub] [beam] nancyxu123 commented on a diff in pull request #24999: Adding SpannerIO.readChangeStreams support for SchemaTransform

nancyxu123 commented on code in PR #24999:
URL: https://github.com/apache/beam/pull/24999#discussion_r1081812007


##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/changestreams/SpannerChangestreamsReadSchemaTransformProvider.java:
##########
@@ -0,0 +1,365 @@
+/*
+ * 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.spanner.changestreams;
+
+import com.google.auto.value.AutoValue;
+import com.google.cloud.Timestamp;
+import com.google.cloud.spanner.Dialect;
+import com.google.cloud.spanner.Type;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.nio.charset.StandardCharsets;
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.coders.StringUtf8Coder;
+import org.apache.beam.sdk.io.gcp.spanner.ReadSpannerSchema;
+import org.apache.beam.sdk.io.gcp.spanner.SpannerConfig;
+import org.apache.beam.sdk.io.gcp.spanner.SpannerIO;
+import org.apache.beam.sdk.io.gcp.spanner.SpannerSchema;
+import org.apache.beam.sdk.io.gcp.spanner.changestreams.model.DataChangeRecord;
+import org.apache.beam.sdk.io.gcp.spanner.changestreams.model.Mod;
+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.transforms.SchemaTransform;
+import org.apache.beam.sdk.schemas.transforms.TypedSchemaTransformProvider;
+import org.apache.beam.sdk.transforms.*;
+import org.apache.beam.sdk.values.PCollectionRowTuple;
+import org.apache.beam.sdk.values.PCollectionView;
+import org.apache.beam.sdk.values.Row;
+import org.apache.beam.vendor.grpc.v1p48p1.com.google.gson.Gson;
+import org.checkerframework.checker.initialization.qual.Initialized;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.checker.nullness.qual.UnknownKeyFor;
+import org.joda.time.DateTime;
+import org.joda.time.Instant;
+
+public class SpannerChangestreamsReadSchemaTransformProvider
+    extends TypedSchemaTransformProvider<
+        SpannerChangestreamsReadSchemaTransformProvider.SpannerChangestreamsReadConfiguration> {
+  @Override
+  protected @UnknownKeyFor @NonNull @Initialized Class<SpannerChangestreamsReadConfiguration>
+      configurationClass() {
+    return SpannerChangestreamsReadConfiguration.class;
+  }
+
+  @Override
+  public @UnknownKeyFor @NonNull @Initialized SchemaTransform from(
+      SpannerChangestreamsReadSchemaTransformProvider.SpannerChangestreamsReadConfiguration
+          configuration) {
+    return new SchemaTransform() {
+      @Override
+      public @UnknownKeyFor @NonNull @Initialized PTransform<
+              @UnknownKeyFor @NonNull @Initialized PCollectionRowTuple,
+              @UnknownKeyFor @NonNull @Initialized PCollectionRowTuple>
+          buildTransform() {
+        return new PTransform<PCollectionRowTuple, PCollectionRowTuple>() {
+          @Override
+          public PCollectionRowTuple expand(PCollectionRowTuple input) {
+            Pipeline p = input.getPipeline();
+            // TODO(pabloem): Does this action create/destroy a new metadata table??
+            Schema tableChangesSchema = getTableSchema(configuration);

Review Comment:
   Two main comments:
   
   1) Let's filter out tables from the schema that are not tracked by change streams. We don't want to cache tables in the schema if they are not tracked by change streams.
   
   2) Let's filter out columns from a change stream-tracked table if they are not tracked by change streams.
   
   Three potential cases:
   
   CREATE CHANGE STREAM changeStream FOR table(); // This statement will track only primary key columns.
   CREATE CHANGE STREAM changeStream FOR table(column1); this statement will track only primary key columns and column1.
   CREATE CHANGE STREAM changeStream FOR table; // This statement will track all columns



-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org