TheNeuralBit commented on a change in pull request #12341:
URL: https://github.com/apache/beam/pull/12341#discussion_r469443705



##########
File path: 
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/datastore/DataStoreV1SchemaIOProvider.java
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.datastore;
+
+import com.google.auto.service.AutoService;
+import com.google.datastore.v1.Query;
+import java.io.Serializable;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.beam.sdk.annotations.Internal;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.schemas.io.InvalidConfigurationException;
+import org.apache.beam.sdk.schemas.io.InvalidLocationException;
+import org.apache.beam.sdk.schemas.io.SchemaIO;
+import org.apache.beam.sdk.schemas.io.SchemaIOProvider;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.values.PBegin;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.POutput;
+import org.apache.beam.sdk.values.Row;
+
+/**
+ * An implementation of {@link SchemaIOProvider} for reading and writing 
payloads with {@link
+ * DatastoreIO}.
+ */
+@Internal
+@AutoService(SchemaIOProvider.class)
+public class DataStoreV1SchemaIOProvider implements SchemaIOProvider {
+  public static final String KEY_FIELD_PROPERTY = "keyField";
+  static final String DEFAULT_KEY_FIELD = "__key__";
+  private static final Pattern locationPattern = 
Pattern.compile("(?<projectId>.+)/(?<kind>.+)");
+
+  /** Returns an id that uniquely represents this IO. */
+  @Override
+  public String identifier() {
+    return "datastoreV1";
+  }
+
+  /**
+   * Returns the expected schema of the configuration object. Note this is 
distinct from the schema
+   * of the data source itself.
+   */

Review comment:
       Let's describe the configuration parameters here. Something like this 
(spotless probably has an opinion on how this should be formatted):
   ```suggestion
     /**
      * Returns the expected schema of the configuration object. Note this is 
distinct from the schema
      * of the data source itself.
      * 
      * <p>Configuration Parameters:
      * <ul>
      *   <li>STRING keyField: The name of the Beam schema field to map the 
DataStore entity key. Defaults to {@code __key__} if not set or null.
      * </ul>
      */
   ```

##########
File path: 
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/meta/provider/SchemaIOTableProviderWrapper.java
##########
@@ -80,13 +80,17 @@ public BeamSqlTable buildBeamSqlTable(Table 
tableDefinition) {
     }
   }
 
-  private BeamTableStatistics getTableStatistics(PipelineOptions options) {
+  public BeamTableStatistics getTableStatistics(PipelineOptions options) {
     if (isBounded().equals(PCollection.IsBounded.BOUNDED)) {
       return BeamTableStatistics.BOUNDED_UNKNOWN;
     }
     return BeamTableStatistics.UNBOUNDED_UNKNOWN;
   }
 
+  public BeamTableStatistics getTableStatistics(PipelineOptions options, 
SchemaIO schemaIO) {
+    return getTableStatistics(options);
+  }
+

Review comment:
       I don't think this new method is actually called anywhere. Should it be 
called from `SchemaIOTableWrapper#getTableStatistics`?
   
    It might also be good to just get rid of the other `getTableStatistics` and 
move the default implementation to this one.

##########
File path: 
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/datastore/EntityToRow.java
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.datastore;
+
+import static com.google.datastore.v1.client.DatastoreHelper.makeValue;
+
+import com.google.datastore.v1.Entity;
+import com.google.datastore.v1.Value;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.Row;
+import 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap;
+import org.joda.time.Instant;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** A {@code PTransform} to perform a conversion of {@link Entity} to {@link 
Row}. */
+public class EntityToRow extends PTransform<PCollection<Entity>, 
PCollection<Row>> {
+  private final Schema schema;
+  private final String keyField;
+  private static final Logger LOG = 
LoggerFactory.getLogger(DataStoreV1SchemaIOProvider.class);
+
+  private EntityToRow(Schema schema, String keyField) {
+    this.schema = schema;
+    this.keyField = keyField;
+
+    if (schema.getFieldNames().contains(keyField)) {
+      if 
(!schema.getField(keyField).getType().getTypeName().equals(Schema.TypeName.BYTES))
 {
+        throw new IllegalStateException(
+            "Field `"
+                + keyField
+                + "` should of type `VARBINARY`. Please change the type or 
specify a field to"

Review comment:
       ```suggestion
                   + "` should of type `BYTES`. Please change the type or 
specify a field to"
   ```
   Let's change this to the Beam schema type name




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

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


Reply via email to