chamikaramj commented on code in PR #27146:
URL: https://github.com/apache/beam/pull/27146#discussion_r1240930415


##########
sdks/python/apache_beam/io/gcp/bigtableio.py:
##########
@@ -268,3 +272,95 @@ def process(self, row):
             partial_row.cells[fam_name][col_qualifier_bytes].append(
                 Cell(value, timestamp_micros))
       yield partial_row
+
+
+class WriteToBigtableXlang(beam.PTransform):

Review Comment:
   s/WriteToBigtableXlang/WriteToBigtable



##########
sdks/python/apache_beam/io/gcp/bigtableio_test.py:
##########
@@ -17,15 +17,16 @@
 

Review Comment:
   probably rename file to bigtableio_it_test to clearly denote that these are 
end-to-end ITs.



##########
sdks/python/apache_beam/io/gcp/bigtableio.py:
##########
@@ -268,3 +272,95 @@ def process(self, row):
             partial_row.cells[fam_name][col_qualifier_bytes].append(
                 Cell(value, timestamp_micros))
       yield partial_row
+
+
+class WriteToBigtableXlang(beam.PTransform):
+  """Writes rows to Bigtable.
+
+  Takes an input PCollection of DirectRow objects containing un-committed
+  mutations. For more information about this row object, visit
+  
https://cloud.google.com/python/docs/reference/bigtable/latest/row#class-googlecloudbigtablerowdirectrowrowkey-tablenone
+  """
+  URN = "beam:schematransform:org.apache.beam:bigtable_write:v1"
+
+  def __init__(self, table_id, instance_id, project_id, 
expansion_service=None):
+    """Initialize an WriteToBigtableXlang transform.

Review Comment:
   WriteToBigtable



##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigtable/BigtableWriteSchemaTransformProvider.java:
##########
@@ -0,0 +1,253 @@
+/*
+ * 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;
+
+import static java.util.Optional.ofNullable;
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument;
+
+import com.google.auto.service.AutoService;
+import com.google.auto.value.AutoValue;
+import com.google.bigtable.v2.Mutation;
+import com.google.bigtable.v2.TimestampRange;
+import com.google.protobuf.ByteString;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import 
org.apache.beam.sdk.io.gcp.bigtable.BigtableWriteSchemaTransformProvider.BigtableWriteSchemaTransformConfiguration;
+import org.apache.beam.sdk.schemas.AutoValueSchema;
+import org.apache.beam.sdk.schemas.annotations.DefaultSchema;
+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.MapElements;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.transforms.SimpleFunction;
+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.apache.beam.vendor.guava.v26_0_jre.com.google.common.primitives.Longs;
+
+/**
+ * An implementation of {@link TypedSchemaTransformProvider} for Bigtable 
Write jobs configured via
+ * {@link BigtableWriteSchemaTransformConfiguration}.
+ *
+ * <p><b>Internal only:</b> This class is actively being worked on, and it 
will likely change. We
+ * provide no backwards compatibility guarantees, and it should not be 
implemented outside the Beam
+ * repository.
+ */
+@AutoService(SchemaTransformProvider.class)
+public class BigtableWriteSchemaTransformProvider
+    extends 
TypedSchemaTransformProvider<BigtableWriteSchemaTransformConfiguration> {
+
+  private static final String INPUT_TAG = "input";
+
+  @Override
+  protected Class<BigtableWriteSchemaTransformConfiguration> 
configurationClass() {
+    return BigtableWriteSchemaTransformConfiguration.class;
+  }
+
+  @Override
+  protected SchemaTransform from(BigtableWriteSchemaTransformConfiguration 
configuration) {
+    return new BigtableWriteSchemaTransform(configuration);
+  }
+
+  @Override
+  public String identifier() {
+    return "beam:schematransform:org.apache.beam:bigtable_write:v1";
+  }
+
+  @Override
+  public List<String> inputCollectionNames() {
+    return Collections.singletonList(INPUT_TAG);
+  }
+
+  @Override
+  public List<String> outputCollectionNames() {
+    return Collections.emptyList();
+  }
+
+  /** Configuration for writing to Bigtable. */
+  @DefaultSchema(AutoValueSchema.class)
+  @AutoValue
+  public abstract static class BigtableWriteSchemaTransformConfiguration {
+    /** Instantiates a {@link 
BigtableWriteSchemaTransformConfiguration.Builder} instance. */
+    public static Builder builder() {
+      return new 
AutoValue_BigtableWriteSchemaTransformProvider_BigtableWriteSchemaTransformConfiguration
+          .Builder();
+    }
+
+    /** Validates the configuration object. */
+    public void validate() {
+      String invalidConfigMessage =
+          "Invalid Bigtable Write configuration: %s should be a non-empty 
String";
+      checkArgument(!this.getTableId().isEmpty(), 
String.format(invalidConfigMessage, "table"));
+      checkArgument(
+          !this.getInstanceId().isEmpty(), String.format(invalidConfigMessage, 
"instance"));
+      checkArgument(!this.getProjectId().isEmpty(), 
String.format(invalidConfigMessage, "project"));
+    }
+
+    public abstract String getTableId();
+
+    public abstract String getInstanceId();
+
+    public abstract String getProjectId();
+
+    /** Builder for the {@link BigtableWriteSchemaTransformConfiguration}. */
+    @AutoValue.Builder
+    public abstract static class Builder {
+      public abstract Builder setTableId(String table);

Review Comment:
   s/table/tableId (and also similar changes for the other fields below).



##########
sdks/python/apache_beam/io/gcp/bigtableio.py:
##########
@@ -268,3 +272,95 @@ def process(self, row):
             partial_row.cells[fam_name][col_qualifier_bytes].append(
                 Cell(value, timestamp_micros))
       yield partial_row
+
+
+class WriteToBigtableXlang(beam.PTransform):
+  """Writes rows to Bigtable.
+
+  Takes an input PCollection of DirectRow objects containing un-committed
+  mutations. For more information about this row object, visit

Review Comment:
   Probably it's good to add a comment that this is implemented using the 
multi-language transforms framework to prevent confusion.



##########
sdks/python/apache_beam/io/gcp/bigtableio_test.py:
##########
@@ -205,6 +211,380 @@ def test_beam_row_to_bigtable_row(self):
                      bigtable_row.find_cells('family_2', b'column_qualifier'))
 
 
[email protected]_gcp_java_expansion_service
[email protected](
+    os.environ.get('EXPANSION_PORT'),
+    "EXPANSION_PORT environment var is not provided.")
[email protected](client is None, 'Bigtable dependencies are not installed')
+class TestWriteToBigtableXlang(unittest.TestCase):

Review Comment:
   TestWriteToBigtable



-- 
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