[
https://issues.apache.org/jira/browse/BEAM-8427?focusedWorklogId=335173&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-335173
]
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_r339787299
##########
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:
Makes sense, updated the test to check that the same `Row`s are produced. It
would be a good thing to add at some point!
----------------------------------------------------------------
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: 335173)
Time Spent: 1h 40m (was: 1.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: 1h 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)