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

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

                Author: ASF GitHub Bot
            Created on: 25/Oct/19 23:59
            Start Date: 25/Oct/19 23:59
    Worklog Time Spent: 10m 
      Work Description: TheNeuralBit 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_r339272432
 
 

 ##########
 File path: 
sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/meta/provider/mongodb/MongoDbTableTest.java
 ##########
 @@ -0,0 +1,104 @@
+/*
+ * 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 org.apache.beam.sdk.extensions.sql.meta.Table;
+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.values.PCollection;
+import org.apache.beam.sdk.values.Row;
+import org.bson.Document;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class MongoDbTableTest {
+
+  private static final Schema SCHEMA =
+      Schema.builder()
+          .addNullableField("long", INT64)
+          .addNullableField("int32", INT32)
+          .addNullableField("int16", INT16)
+          .addNullableField("byte", BYTE)
+          .addNullableField("bool", BOOLEAN)
+          .addNullableField("double", DOUBLE)
+          .addNullableField("float", FLOAT)
+          .addNullableField("string", STRING)
+          .addNullableField("arr", FieldType.array(STRING))
+          .build();
+  private static final String JSON_ROW =
+      "{ "
+          + "\"long\" : 9223372036854775807, "
+          + "\"int32\" : 2147483647, "
+          + "\"int16\" : 32767, "
+          + "\"byte\" : 127, "
+          + "\"bool\" : true, "
+          + "\"double\" : 1.0, "
+          + "\"float\" : 1.0, "
+          + "\"string\" : \"string\", "
+          + "\"arr\" : [\"str1\", \"str2\", \"str3\"]"
+          + " }";
+  private static final MongoDbTable SQL_TABLE =
+      (MongoDbTable)
+          new MongoDbTableProvider()
+              .buildBeamSqlTable(
+                  fakeTable("TEST", 
"mongodb://localhost:27017/database/collection"));
+
+  @Rule public transient TestPipeline pipeline = TestPipeline.create();
+
+  @Test
+  public void testDocumentToRowConverter() {
+    PCollection<String> output =
+        pipeline
+            .apply("Create document from JSON", 
Create.<Document>of(Document.parse(JSON_ROW)))
+            .apply("Decode document back into JSON", 
SQL_TABLE.createParserParDo());
+
+    // Make sure JSON was decoded correctly
+    PAssert.that(output).containsInAnyOrder(JSON_ROW);
 
 Review comment:
   I think this is brittle, since the string comparison can fail if the keys 
are written out in a different order, and I don't think there's anything 
guaranteeing the order. Maybe instead verify that `output` and `JSON_ROW` can 
be parsed into equivalent rows?
   
   This is a problem I keep running into as I'm writing tests with JSON, it 
would be nice to have some general purpose way to assert that two strings are 
equivalent JSON. Maybe we just need to write our own `Matcher` that parses to 
jackson nodes and compares. (You don't need to do that here unless you're so 
inclined, I'm just thinking out loud).
 
----------------------------------------------------------------
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:
[email protected]


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

    Worklog Id:     (was: 334436)
    Time Spent: 40m  (was: 0.5h)

> [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: 40m
>  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