[ 
https://issues.apache.org/jira/browse/BEAM-9072?focusedWorklogId=372677&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-372677
 ]

ASF GitHub Bot logged work on BEAM-9072:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 16/Jan/20 00:52
            Start Date: 16/Jan/20 00:52
    Worklog Time Spent: 10m 
      Work Description: 11moon11 commented on pull request #10440: [BEAM-9072] 
[SQL] DataStoreV1 IO connector
URL: https://github.com/apache/beam/pull/10440#discussion_r367182629
 
 

 ##########
 File path: 
sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/meta/provider/datastore/DataStoreReadWriteIT.java
 ##########
 @@ -0,0 +1,185 @@
+/*
+ * 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.extensions.sql.meta.provider.datastore;
+
+import static com.google.datastore.v1.client.DatastoreHelper.makeKey;
+import static 
org.apache.beam.sdk.extensions.sql.impl.utils.CalciteUtils.VARBINARY;
+import static org.apache.beam.sdk.schemas.Schema.FieldType.BOOLEAN;
+import static org.apache.beam.sdk.schemas.Schema.FieldType.DATETIME;
+import static org.apache.beam.sdk.schemas.Schema.FieldType.DOUBLE;
+import static org.apache.beam.sdk.schemas.Schema.FieldType.INT64;
+import static org.apache.beam.sdk.schemas.Schema.FieldType.STRING;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+
+import com.google.datastore.v1.Key;
+import java.util.UUID;
+import org.apache.beam.sdk.PipelineResult;
+import org.apache.beam.sdk.PipelineResult.State;
+import org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv;
+import org.apache.beam.sdk.extensions.sql.impl.rel.BeamSqlRelUtils;
+import org.apache.beam.sdk.io.gcp.bigquery.BigQueryOptions;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.schemas.Schema.FieldType;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.Row;
+import 
org.apache.beam.vendor.calcite.v1_20_0.org.apache.calcite.avatica.util.ByteString;
+import org.joda.time.Duration;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class DataStoreReadWriteIT {
+  private static final BigQueryOptions options =
+      TestPipeline.testingPipelineOptions().as(BigQueryOptions.class);
+  private static final Schema SOURCE_SCHEMA =
+      Schema.builder()
+          .addNullableField("__key__", VARBINARY)
+          .addNullableField("content", STRING)
+          .build();
+  private static final Schema SOURCE_SCHEMA_WITHOUT_KEY =
+      Schema.builder().addNullableField("content", STRING).build();
+  private static final String KIND = "writereadtest";
+  private static final String KIND_ALL_TYPES = "writereadalltypestest";
+
+  @Rule public final TestPipeline writePipeline = TestPipeline.create();
+  @Rule public transient TestPipeline readPipeline = TestPipeline.create();
+
+  @Test
+  public void testDataStoreV1SqlWriteRead() {
+    BeamSqlEnv sqlEnv = BeamSqlEnv.inMemory(new DataStoreV1TableProvider());
+    String projectId = options.getProject();
+
+    String createTableStatement =
+        "CREATE EXTERNAL TABLE TEST( \n"
+            + "   `__key__` VARBINARY, \n"
+            + "   `content` VARCHAR \n"
+            + ") \n"
+            + "TYPE 'datastoreV1' \n"
+            + "LOCATION '"
+            + projectId
+            + "/"
+            + KIND
+            + "'";
+    sqlEnv.executeDdl(createTableStatement);
+
+    Key ancestor = makeKey(KIND, UUID.randomUUID().toString()).build();
+    Key itemKey = makeKey(ancestor, KIND, 
UUID.randomUUID().toString()).build();
+    String insertStatement =
+        "INSERT INTO TEST VALUES ( \n" + keyToSqlByteString(itemKey) + ", \n" 
+ "'2000' \n" + ")";
+
+    BeamSqlRelUtils.toPCollection(writePipeline, 
sqlEnv.parseQuery(insertStatement));
+    writePipeline.run().waitUntilFinish();
+
+    String selectTableStatement = "SELECT * FROM TEST";
+    PCollection<Row> output =
+        BeamSqlRelUtils.toPCollection(readPipeline, 
sqlEnv.parseQuery(selectTableStatement));
+
+    assertThat(output.getSchema(), equalTo(SOURCE_SCHEMA));
+
+    PipelineResult.State state = 
readPipeline.run().waitUntilFinish(Duration.standardMinutes(5));
+    assertThat(state, equalTo(State.DONE));
+  }
+
+  @Test
+  public void testDataStoreV1SqlRead_withoutKey() {
 
 Review comment:
   Modified this test to perform both operations: write and read.
 
----------------------------------------------------------------
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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 372677)
    Time Spent: 2h 20m  (was: 2h 10m)

> [SQL] Add support for Datastore source
> --------------------------------------
>
>                 Key: BEAM-9072
>                 URL: https://issues.apache.org/jira/browse/BEAM-9072
>             Project: Beam
>          Issue Type: New Feature
>          Components: dsl-sql
>            Reporter: Kirill Kozlov
>            Assignee: Kirill Kozlov
>            Priority: Major
>          Time Spent: 2h 20m
>  Remaining Estimate: 0h
>
> * Create a Datastore table and table provider
>  * Conversion between Datastore and Beam data types
>  * Implement buildIOReader
>  * Implement buildIOWrite
>  * Implement getTableStatistics
> Doc: 
> [https://docs.google.com/document/d/1FxuEGewJ3GPDl0IKglfOYf1edwa2m_wryFZYRMpRNbA/edit?pli=1]



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to