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

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

                Author: ASF GitHub Bot
            Created on: 28/Oct/19 20:53
            Start Date: 28/Oct/19 20:53
    Worklog Time Spent: 10m 
      Work Description: 11moon11 commented on pull request #9806: [BEAM-8427] 
Create a table and a table provider for MongoDB
URL: https://github.com/apache/beam/pull/9806#discussion_r339787287
 
 

 ##########
 File path: 
sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/meta/provider/mongodb/MongoDbReadWriteIT.java
 ##########
 @@ -0,0 +1,195 @@
+/*
+ * 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.mongodb;
+
+import static org.apache.beam.sdk.schemas.Schema.FieldType.BOOLEAN;
+import static org.apache.beam.sdk.schemas.Schema.FieldType.BYTE;
+import static org.apache.beam.sdk.schemas.Schema.FieldType.DOUBLE;
+import static org.apache.beam.sdk.schemas.Schema.FieldType.FLOAT;
+import static org.apache.beam.sdk.schemas.Schema.FieldType.INT16;
+import static org.apache.beam.sdk.schemas.Schema.FieldType.INT32;
+import static org.apache.beam.sdk.schemas.Schema.FieldType.INT64;
+import static org.apache.beam.sdk.schemas.Schema.FieldType.STRING;
+import static org.junit.Assert.assertEquals;
+
+import com.mongodb.MongoClient;
+import java.util.Arrays;
+import org.apache.beam.sdk.PipelineResult;
+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.mongodb.MongoDBIOIT.MongoDBPipelineOptions;
+import org.apache.beam.sdk.io.mongodb.MongoDbIO;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.schemas.Schema.FieldType;
+import org.apache.beam.sdk.testing.PAssert;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.transforms.Create;
+import org.apache.beam.sdk.transforms.MapElements;
+import org.apache.beam.sdk.transforms.SimpleFunction;
+import org.apache.beam.sdk.transforms.ToJson;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.Row;
+import org.bson.Document;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/**
+ * A test of {@link 
org.apache.beam.sdk.extensions.sql.meta.provider.mongodb.MongoDbTable} on an
+ * independent Mongo instance.
+ *
+ * <p>This test requires a running instance of MongoDB. Pass in connection 
information using
+ * PipelineOptions:
+ *
+ * <pre>
+ *  ./gradlew integrationTest -p sdks/java/extensions/sql/integrationTest 
-DintegrationTestPipelineOptions='[
+ *  "--mongoDBHostName=1.2.3.4",
+ *  "--mongoDBPort=27017",
+ *  "--mongoDBDatabaseName=mypass",
+ *  "--numberOfRecords=1000" ]'
+ *  --tests 
org.apache.beam.sdk.extensions.sql.meta.provider.mongodb.MongoDbReadWriteIT
+ *  -DintegrationTestRunner=direct
+ * </pre>
+ *
+ * <p>Please see 'build_rules.gradle' file for instructions regarding running 
this test using Beam
+ * performance testing framework.
+ */
+@RunWith(JUnit4.class)
+public class MongoDbReadWriteIT {
+  private static final Schema SOURCE_SCHEMA =
+      Schema.builder()
+          .addNullableField("_id", STRING)
+          .addNullableField("c_bigint", INT64)
+          .addNullableField("c_tinyint", BYTE)
+          .addNullableField("c_smallint", INT16)
+          .addNullableField("c_integer", INT32)
+          .addNullableField("c_float", FLOAT)
+          .addNullableField("c_double", DOUBLE)
+          .addNullableField("c_boolean", BOOLEAN)
+          .addNullableField("c_varchar", STRING)
+          .addNullableField("c_arr", FieldType.array(STRING))
+          .build();
+  private static final String collection = "collection";
+  private static MongoDBPipelineOptions options;
+
+  @Rule public final TestPipeline writePipeline = TestPipeline.create();
+  @Rule public final TestPipeline readPipeline = TestPipeline.create();
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    PipelineOptionsFactory.register(MongoDBPipelineOptions.class);
+    options = 
TestPipeline.testingPipelineOptions().as(MongoDBPipelineOptions.class);
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    dropDatabase();
+  }
+
+  private static void dropDatabase() throws Exception {
+    new MongoClient(options.getMongoDBHostName())
+        .getDatabase(options.getMongoDBDatabaseName())
+        .drop();
+  }
+
+  @Test
+  public void testWriteAndRead() {
+    final String mongoUrl =
+        String.format("mongodb://%s:%d", options.getMongoDBHostName(), 
options.getMongoDBPort());
+    final String mongoSqlUrl =
+        String.format(
+            "mongodb://%s:%d/%s/%s",
+            options.getMongoDBHostName(),
+            options.getMongoDBPort(),
+            options.getMongoDBDatabaseName(),
+            collection);
+
+    Row testRow =
+        row(
+            SOURCE_SCHEMA,
+            "object_id",
+            9223372036854775807L,
+            (byte) 127,
+            (short) 32767,
+            2147483647,
+            (float) 1.0,
+            1.0,
+            true,
+            "varchar",
+            Arrays.asList("123", "456"));
+
+    writePipeline
+        .apply(Create.of(testRow))
+        .setRowSchema(SOURCE_SCHEMA)
+        .apply("Transform Rows to JSON", new ToJson<Row>())
 
 Review comment:
   Rebased and updated to use `ToJson.of()`. 
   This part will change once `buildIOWriter` for `MongoDbTable` is implemented.
 
----------------------------------------------------------------
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: 335172)
    Time Spent: 1.5h  (was: 1h 20m)

> [SQL] Add support for MongoDB source
> ------------------------------------
>
>                 Key: BEAM-8427
>                 URL: https://issues.apache.org/jira/browse/BEAM-8427
>             Project: Beam
>          Issue Type: New Feature
>          Components: dsl-sql
>            Reporter: Kirill Kozlov
>            Assignee: Kirill Kozlov
>            Priority: Major
>          Time Spent: 1.5h
>  Remaining Estimate: 0h
>
> In progress:
>  * Create a MongoDB table and table provider.
>  * Implement buildIOReader
>  * Support primitive types
> Still needs to be done:
>  * Implement buildIOWrite
>  * improve getTableStatistics



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

Reply via email to