You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/09/08 18:29:41 UTC

[GitHub] [incubator-seatunnel] wuchunfu opened a new pull request, #2694: [Feature][Connector-V2] Add mongodb connecter sink

wuchunfu opened a new pull request, #2694:
URL: https://github.com/apache/incubator-seatunnel/pull/2694

   <!--
   
   Thank you for contributing to SeaTunnel! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/incubator-seatunnel/issues).
   
     - Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
   
     - Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
   
   -->
   
   ## Purpose of this pull request
   
   <!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
   
   ## Check list
   
   * [x] Code changed are covered with tests, or it does not need tests for reason:
   * [ ] If any new Jar binary package adding in your PR, please add License Notice according
     [New License Guide](https://github.com/apache/incubator-seatunnel/blob/dev/docs/en/contribution/new-license.md)
   * [x] If necessary, please update the documentation to describe the new feature. https://github.com/apache/incubator-seatunnel/tree/dev/docs
   


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

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] wuchunfu commented on pull request #2694: [Feature][Connector-V2] Add mongodb connecter sink

Posted by GitBox <gi...@apache.org>.
wuchunfu commented on PR #2694:
URL: https://github.com/apache/incubator-seatunnel/pull/2694#issuecomment-1241419652

   > add spark e2e-testcase?
   
   OK, thank you for your reminder. I'll add it later


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

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] wuchunfu commented on a diff in pull request #2694: [Feature][Connector-V2] Add mongodb connecter sink

Posted by GitBox <gi...@apache.org>.
wuchunfu commented on code in PR #2694:
URL: https://github.com/apache/incubator-seatunnel/pull/2694#discussion_r967626102


##########
seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/sink/MongodbSinkWriter.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.mongodb.sink;
+
+import org.apache.seatunnel.api.serialization.SerializationSchema;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import org.apache.seatunnel.connectors.seatunnel.mongodb.config.MongodbParameters;
+import org.apache.seatunnel.format.json.JsonSerializationSchema;
+
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import com.mongodb.client.MongoCollection;
+import org.bson.Document;
+
+import java.io.IOException;
+
+public class MongodbSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> {
+
+    private final SeaTunnelRowType rowType;
+
+    private final SerializationSchema serializationSchema;
+
+    private MongoClient client;
+
+    private final String database;
+
+    private final String collection;
+
+    public MongodbSinkWriter(SeaTunnelRowType rowType, MongodbParameters params) {
+        this.rowType = rowType;
+        this.database = params.getDatabase();
+        this.collection = params.getCollection();
+        this.client = MongoClients.create(params.getUri());
+        this.serializationSchema = new JsonSerializationSchema(rowType);
+    }
+
+    @Override
+    public void write(SeaTunnelRow rows) throws IOException {
+        byte[] serialize = serializationSchema.serialize(rows);
+        String content = new String(serialize);
+
+        MongoCollection<Document> mongoCollection = this.client

Review Comment:
   Makes sense, done



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

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] wuchunfu commented on a diff in pull request #2694: [Feature][Connector-V2] Add mongodb connecter sink

Posted by GitBox <gi...@apache.org>.
wuchunfu commented on code in PR #2694:
URL: https://github.com/apache/incubator-seatunnel/pull/2694#discussion_r966561916


##########
seatunnel-e2e/seatunnel-flink-connector-v2-e2e/connector-mongodb-flink-e2e/src/test/java/org/apache/seatunnel/e2e/flink/v2/mongodb/FakeSourceToMongodbIT.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.seatunnel.e2e.flink.v2.mongodb;
+
+import static java.net.HttpURLConnection.HTTP_OK;
+import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
+
+import org.apache.seatunnel.e2e.flink.FlinkContainer;
+
+import com.google.common.collect.Lists;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
+import org.testcontainers.lifecycle.Startables;
+import org.testcontainers.utility.DockerImageName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.stream.Stream;
+
+@Slf4j
+public class FakeSourceToMongodbIT extends FlinkContainer {
+
+    private static final String MONGODB_IMAGE = "mongo:latest";
+
+    private static final String MONGODB_CONTAINER_HOST = "flink_e2e_mongodb_sink";
+
+    private static final int MONGODB_PORT = 27017;
+
+    private GenericContainer<?> mongodbContainer;
+
+    @BeforeEach
+    public void startMongoContainer() {
+        DockerImageName imageName = DockerImageName.parse(MONGODB_IMAGE);
+        mongodbContainer = new GenericContainer<>(imageName)
+            .withNetwork(NETWORK)
+            .withNetworkAliases(MONGODB_CONTAINER_HOST)
+            .withExposedPorts(MONGODB_PORT)
+            .waitingFor(new HttpWaitStrategy()
+                .forPort(MONGODB_PORT)
+                .forStatusCodeMatching(response -> response == HTTP_OK || response == HTTP_UNAUTHORIZED)
+                .withStartupTimeout(Duration.ofMinutes(2)))
+            .withLogConsumer(new Slf4jLogConsumer(log));
+        mongodbContainer.setPortBindings(Lists.newArrayList(String.format("%s:%s", MONGODB_PORT, MONGODB_PORT)));
+        Startables.deepStart(Stream.of(mongodbContainer)).join();
+        log.info("Mongodb container started");
+    }
+
+    @Test
+    public void testMongodbSource() throws IOException, InterruptedException {
+        Container.ExecResult execResult = executeSeaTunnelFlinkJob("/mongodb/fake_to_mongodb.conf");
+        Assertions.assertEquals(0, execResult.getExitCode());
+    }

Review Comment:
   > You can refer the IOTDB Sink e2e
   
   OK, Thanks



##########
seatunnel-e2e/seatunnel-flink-connector-v2-e2e/connector-mongodb-flink-e2e/src/test/java/org/apache/seatunnel/e2e/flink/v2/mongodb/FakeSourceToMongodbIT.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.seatunnel.e2e.flink.v2.mongodb;
+
+import static java.net.HttpURLConnection.HTTP_OK;
+import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
+
+import org.apache.seatunnel.e2e.flink.FlinkContainer;
+
+import com.google.common.collect.Lists;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
+import org.testcontainers.lifecycle.Startables;
+import org.testcontainers.utility.DockerImageName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.stream.Stream;
+
+@Slf4j
+public class FakeSourceToMongodbIT extends FlinkContainer {
+
+    private static final String MONGODB_IMAGE = "mongo:latest";
+
+    private static final String MONGODB_CONTAINER_HOST = "flink_e2e_mongodb_sink";
+
+    private static final int MONGODB_PORT = 27017;
+
+    private GenericContainer<?> mongodbContainer;
+
+    @BeforeEach
+    public void startMongoContainer() {
+        DockerImageName imageName = DockerImageName.parse(MONGODB_IMAGE);
+        mongodbContainer = new GenericContainer<>(imageName)
+            .withNetwork(NETWORK)
+            .withNetworkAliases(MONGODB_CONTAINER_HOST)
+            .withExposedPorts(MONGODB_PORT)
+            .waitingFor(new HttpWaitStrategy()
+                .forPort(MONGODB_PORT)
+                .forStatusCodeMatching(response -> response == HTTP_OK || response == HTTP_UNAUTHORIZED)
+                .withStartupTimeout(Duration.ofMinutes(2)))
+            .withLogConsumer(new Slf4jLogConsumer(log));
+        mongodbContainer.setPortBindings(Lists.newArrayList(String.format("%s:%s", MONGODB_PORT, MONGODB_PORT)));
+        Startables.deepStart(Stream.of(mongodbContainer)).join();
+        log.info("Mongodb container started");
+    }
+
+    @Test
+    public void testMongodbSource() throws IOException, InterruptedException {
+        Container.ExecResult execResult = executeSeaTunnelFlinkJob("/mongodb/fake_to_mongodb.conf");
+        Assertions.assertEquals(0, execResult.getExitCode());
+    }

Review Comment:
   > You can refer the IOTDB Sink e2e
   
   OK, Thanks



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

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] TyrantLucifer commented on a diff in pull request #2694: [Feature][Connector-V2] Add mongodb connecter sink

Posted by GitBox <gi...@apache.org>.
TyrantLucifer commented on code in PR #2694:
URL: https://github.com/apache/incubator-seatunnel/pull/2694#discussion_r967356433


##########
seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/sink/MongodbSinkWriter.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.mongodb.sink;
+
+import org.apache.seatunnel.api.serialization.SerializationSchema;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import org.apache.seatunnel.connectors.seatunnel.mongodb.config.MongodbParameters;
+import org.apache.seatunnel.format.json.JsonSerializationSchema;
+
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import com.mongodb.client.MongoCollection;
+import org.bson.Document;
+
+import java.io.IOException;
+
+public class MongodbSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> {
+
+    private final SeaTunnelRowType rowType;
+
+    private final MongodbParameters params;
+
+    private final SerializationSchema serializationSchema;
+
+    private MongoClient client;
+
+    private final String database;
+
+    private final String collection;
+
+    public MongodbSinkWriter(SeaTunnelRowType rowType, MongodbParameters params) {
+        this.rowType = rowType;
+        this.params = params;
+        this.database = this.params.getDatabase();
+        this.collection = this.params.getCollection();
+        this.serializationSchema = new JsonSerializationSchema(rowType);
+    }
+
+    @Override
+    public void write(SeaTunnelRow rows) throws IOException {
+        byte[] serialize = serializationSchema.serialize(rows);
+        String content = new String(serialize);
+
+        this.client = MongoClients.create(params.getUri());

Review Comment:
   Why not use these two variables as class attributes, too? Each time a piece of data is written, a client object and a collection object are retrieved, this results in unnecessary method calls and resource consumption.
   
   
   
   



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

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] wuchunfu commented on a diff in pull request #2694: [Feature][Connector-V2] Add mongodb connecter sink

Posted by GitBox <gi...@apache.org>.
wuchunfu commented on code in PR #2694:
URL: https://github.com/apache/incubator-seatunnel/pull/2694#discussion_r966562063


##########
seatunnel-e2e/seatunnel-flink-connector-v2-e2e/connector-mongodb-flink-e2e/src/test/java/org/apache/seatunnel/e2e/flink/v2/mongodb/FakeSourceToMongodbIT.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.seatunnel.e2e.flink.v2.mongodb;
+
+import static java.net.HttpURLConnection.HTTP_OK;
+import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
+
+import org.apache.seatunnel.e2e.flink.FlinkContainer;
+
+import com.google.common.collect.Lists;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
+import org.testcontainers.lifecycle.Startables;
+import org.testcontainers.utility.DockerImageName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.stream.Stream;
+
+@Slf4j
+public class FakeSourceToMongodbIT extends FlinkContainer {
+
+    private static final String MONGODB_IMAGE = "mongo:latest";
+
+    private static final String MONGODB_CONTAINER_HOST = "flink_e2e_mongodb_sink";
+
+    private static final int MONGODB_PORT = 27017;
+
+    private GenericContainer<?> mongodbContainer;
+
+    @BeforeEach
+    public void startMongoContainer() {
+        DockerImageName imageName = DockerImageName.parse(MONGODB_IMAGE);
+        mongodbContainer = new GenericContainer<>(imageName)
+            .withNetwork(NETWORK)
+            .withNetworkAliases(MONGODB_CONTAINER_HOST)
+            .withExposedPorts(MONGODB_PORT)
+            .waitingFor(new HttpWaitStrategy()
+                .forPort(MONGODB_PORT)
+                .forStatusCodeMatching(response -> response == HTTP_OK || response == HTTP_UNAUTHORIZED)
+                .withStartupTimeout(Duration.ofMinutes(2)))
+            .withLogConsumer(new Slf4jLogConsumer(log));
+        mongodbContainer.setPortBindings(Lists.newArrayList(String.format("%s:%s", MONGODB_PORT, MONGODB_PORT)));
+        Startables.deepStart(Stream.of(mongodbContainer)).join();
+        log.info("Mongodb container started");
+    }
+
+    @Test
+    public void testMongodbSource() throws IOException, InterruptedException {
+        Container.ExecResult execResult = executeSeaTunnelFlinkJob("/mongodb/fake_to_mongodb.conf");
+        Assertions.assertEquals(0, execResult.getExitCode());
+    }

Review Comment:
   > You can refer the IOTDB Sink e2e
   
   OK, Thanks



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

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] TyrantLucifer commented on a diff in pull request #2694: [Feature][Connector-V2] Add mongodb connecter sink

Posted by GitBox <gi...@apache.org>.
TyrantLucifer commented on code in PR #2694:
URL: https://github.com/apache/incubator-seatunnel/pull/2694#discussion_r967624284


##########
seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/sink/MongodbSinkWriter.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.mongodb.sink;
+
+import org.apache.seatunnel.api.serialization.SerializationSchema;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import org.apache.seatunnel.connectors.seatunnel.mongodb.config.MongodbParameters;
+import org.apache.seatunnel.format.json.JsonSerializationSchema;
+
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import com.mongodb.client.MongoCollection;
+import org.bson.Document;
+
+import java.io.IOException;
+
+public class MongodbSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> {
+
+    private final SeaTunnelRowType rowType;
+
+    private final SerializationSchema serializationSchema;
+
+    private MongoClient client;
+
+    private final String database;
+
+    private final String collection;
+
+    public MongodbSinkWriter(SeaTunnelRowType rowType, MongodbParameters params) {
+        this.rowType = rowType;
+        this.database = params.getDatabase();
+        this.collection = params.getCollection();
+        this.client = MongoClients.create(params.getUri());
+        this.serializationSchema = new JsonSerializationSchema(rowType);
+    }
+
+    @Override
+    public void write(SeaTunnelRow rows) throws IOException {
+        byte[] serialize = serializationSchema.serialize(rows);
+        String content = new String(serialize);
+
+        MongoCollection<Document> mongoCollection = this.client

Review Comment:
   `MongoCollection<Document> mongoCollection` can be a class attribute too.



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

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] hailin0 commented on pull request #2694: [Feature][Connector-V2] Add mongodb connecter sink

Posted by GitBox <gi...@apache.org>.
hailin0 commented on PR #2694:
URL: https://github.com/apache/incubator-seatunnel/pull/2694#issuecomment-1241416849

   add spark e2e-testcase?


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

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] TyrantLucifer commented on a diff in pull request #2694: [Feature][Connector-V2] Add mongodb connecter sink

Posted by GitBox <gi...@apache.org>.
TyrantLucifer commented on code in PR #2694:
URL: https://github.com/apache/incubator-seatunnel/pull/2694#discussion_r967250387


##########
seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/sink/MongodbSinkWriter.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.mongodb.sink;
+
+import org.apache.seatunnel.api.serialization.SerializationSchema;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import org.apache.seatunnel.connectors.seatunnel.mongodb.config.MongodbParameters;
+import org.apache.seatunnel.format.json.JsonSerializationSchema;
+
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import com.mongodb.client.MongoCollection;
+import org.bson.Document;
+
+import java.io.IOException;
+
+public class MongodbSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> {
+
+    private final SeaTunnelRowType rowType;
+
+    private final MongodbParameters params;
+
+    private final SerializationSchema serializationSchema;
+
+    private MongoClient client;
+
+    public MongodbSinkWriter(SeaTunnelRowType rowType, MongodbParameters params) {
+        this.rowType = rowType;
+        this.params = params;
+        // TODO according to format to initialize serializationSchema
+        // Now temporary using json serializationSchema

Review Comment:
   MongoDB only support insert json, so this tips is useless.



##########
seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/sink/MongodbSinkWriter.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.mongodb.sink;
+
+import org.apache.seatunnel.api.serialization.SerializationSchema;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import org.apache.seatunnel.connectors.seatunnel.mongodb.config.MongodbParameters;
+import org.apache.seatunnel.format.json.JsonSerializationSchema;
+
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import com.mongodb.client.MongoCollection;
+import org.bson.Document;
+
+import java.io.IOException;
+
+public class MongodbSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> {
+
+    private final SeaTunnelRowType rowType;
+
+    private final MongodbParameters params;
+
+    private final SerializationSchema serializationSchema;
+
+    private MongoClient client;
+
+    public MongodbSinkWriter(SeaTunnelRowType rowType, MongodbParameters params) {
+        this.rowType = rowType;
+        this.params = params;
+        // TODO according to format to initialize serializationSchema
+        // Now temporary using json serializationSchema
+        this.serializationSchema = new JsonSerializationSchema(rowType);
+    }
+
+    @Override
+    public void write(SeaTunnelRow rows) throws IOException {
+        byte[] serialize = serializationSchema.serialize(rows);
+        String content = new String(serialize);
+
+        String database = this.params.getDatabase();

Review Comment:
   How about using these variables include `database` `collection` `client` as class attributes? These attributes can be initialized in constructor method.
   
   



##########
seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/sink/MongodbSinkWriter.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.mongodb.sink;
+
+import org.apache.seatunnel.api.serialization.SerializationSchema;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import org.apache.seatunnel.connectors.seatunnel.mongodb.config.MongodbParameters;
+import org.apache.seatunnel.format.json.JsonSerializationSchema;
+
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import com.mongodb.client.MongoCollection;
+import org.bson.Document;
+
+import java.io.IOException;
+
+public class MongodbSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> {
+
+    private final SeaTunnelRowType rowType;
+
+    private final MongodbParameters params;
+
+    private final SerializationSchema serializationSchema;
+
+    private MongoClient client;
+
+    public MongodbSinkWriter(SeaTunnelRowType rowType, MongodbParameters params) {
+        this.rowType = rowType;
+        this.params = params;
+        // TODO according to format to initialize serializationSchema
+        // Now temporary using json serializationSchema
+        this.serializationSchema = new JsonSerializationSchema(rowType);
+    }
+
+    @Override
+    public void write(SeaTunnelRow rows) throws IOException {
+        byte[] serialize = serializationSchema.serialize(rows);
+        String content = new String(serialize);
+
+        String database = this.params.getDatabase();
+        String collection = this.params.getCollection();
+        this.client = MongoClients.create(params.getUri());
+        MongoCollection<Document> mongoCollection = this.client
+            .getDatabase(database)
+            .getCollection(collection);
+
+        Document doc = Document.parse(content);
+        mongoCollection.insertOne(doc);
+    }
+
+    @Override
+    public void close() throws IOException {
+        if (client != null) {

Review Comment:
   Please double check mongoCollection whether need be closed.



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

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] hailin0 commented on a diff in pull request #2694: [Feature][Connector-V2] Add mongodb connecter sink

Posted by GitBox <gi...@apache.org>.
hailin0 commented on code in PR #2694:
URL: https://github.com/apache/incubator-seatunnel/pull/2694#discussion_r966591629


##########
seatunnel-e2e/seatunnel-flink-connector-v2-e2e/connector-mongodb-flink-e2e/src/test/resources/mongodb/fake_to_mongodb.conf:
##########
@@ -0,0 +1,61 @@
+#
+# 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.
+#
+######
+###### This config file is a demonstration of streaming processing in seatunnel config
+######
+
+env {
+  # You can set flink configuration here
+  execution.parallelism = 1
+  #job.mode = "BATCH"
+  #job.mode = "STREAMING"
+  #execution.checkpoint.interval = 10000
+  #execution.checkpoint.data-uri = "hdfs://localhost:9000/checkpoint"
+}
+
+source {
+  # This is a example source plugin **only for test and demonstrate the feature source plugin**
+    FakeSource {
+      result_table_name = "fake"
+      schema = {
+        fields {
+          id = "int"
+          name = "string"

Review Comment:
   test all datatypes?



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

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] wuchunfu commented on a diff in pull request #2694: [Feature][Connector-V2] Add mongodb connecter sink

Posted by GitBox <gi...@apache.org>.
wuchunfu commented on code in PR #2694:
URL: https://github.com/apache/incubator-seatunnel/pull/2694#discussion_r966648609


##########
docs/en/connector-v2/sink/MongoDB.md:
##########
@@ -0,0 +1,46 @@
+# MongoDb
+
+> MongoDB sink connector
+
+## Description
+
+Write data to `MongoDB`
+
+## Key features
+
+- [x] [batch](../../concept/connector-v2-features.md)
+- [ ] [stream](../../concept/connector-v2-features.md)

Review Comment:
   > In ours seatunnel sink api model, always support batch and stream
   
   Thanks for the reminder, I'll fix it



##########
seatunnel-e2e/seatunnel-flink-connector-v2-e2e/connector-mongodb-flink-e2e/src/test/resources/mongodb/fake_to_mongodb.conf:
##########
@@ -0,0 +1,61 @@
+#
+# 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.
+#
+######
+###### This config file is a demonstration of streaming processing in seatunnel config
+######
+
+env {
+  # You can set flink configuration here
+  execution.parallelism = 1
+  #job.mode = "BATCH"
+  #job.mode = "STREAMING"
+  #execution.checkpoint.interval = 10000
+  #execution.checkpoint.data-uri = "hdfs://localhost:9000/checkpoint"
+}
+
+source {
+  # This is a example source plugin **only for test and demonstrate the feature source plugin**
+    FakeSource {
+      result_table_name = "fake"
+      schema = {
+        fields {
+          id = "int"
+          name = "string"

Review Comment:
   > test all datatypes?
   
   Thanks for the reminder, I'll fix it



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

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] wuchunfu commented on a diff in pull request #2694: [Feature][Connector-V2] Add mongodb connecter sink

Posted by GitBox <gi...@apache.org>.
wuchunfu commented on code in PR #2694:
URL: https://github.com/apache/incubator-seatunnel/pull/2694#discussion_r967314387


##########
seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/sink/MongodbSinkWriter.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.mongodb.sink;
+
+import org.apache.seatunnel.api.serialization.SerializationSchema;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import org.apache.seatunnel.connectors.seatunnel.mongodb.config.MongodbParameters;
+import org.apache.seatunnel.format.json.JsonSerializationSchema;
+
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import com.mongodb.client.MongoCollection;
+import org.bson.Document;
+
+import java.io.IOException;
+
+public class MongodbSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> {
+
+    private final SeaTunnelRowType rowType;
+
+    private final MongodbParameters params;
+
+    private final SerializationSchema serializationSchema;
+
+    private MongoClient client;
+
+    public MongodbSinkWriter(SeaTunnelRowType rowType, MongodbParameters params) {
+        this.rowType = rowType;
+        this.params = params;
+        // TODO according to format to initialize serializationSchema
+        // Now temporary using json serializationSchema
+        this.serializationSchema = new JsonSerializationSchema(rowType);
+    }
+
+    @Override
+    public void write(SeaTunnelRow rows) throws IOException {
+        byte[] serialize = serializationSchema.serialize(rows);
+        String content = new String(serialize);
+
+        String database = this.params.getDatabase();
+        String collection = this.params.getCollection();
+        this.client = MongoClients.create(params.getUri());
+        MongoCollection<Document> mongoCollection = this.client
+            .getDatabase(database)
+            .getCollection(collection);
+
+        Document doc = Document.parse(content);
+        mongoCollection.insertOne(doc);
+    }
+
+    @Override
+    public void close() throws IOException {
+        if (client != null) {

Review Comment:
   > Please double check mongoCollection whether need be closed.
   
   mongoCollection has no close method



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

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] CalvinKirs commented on a diff in pull request #2694: [Feature][Connector-V2] Add mongodb connecter sink

Posted by GitBox <gi...@apache.org>.
CalvinKirs commented on code in PR #2694:
URL: https://github.com/apache/incubator-seatunnel/pull/2694#discussion_r966542741


##########
seatunnel-e2e/seatunnel-flink-connector-v2-e2e/connector-mongodb-flink-e2e/src/test/java/org/apache/seatunnel/e2e/flink/v2/mongodb/FakeSourceToMongodbIT.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.seatunnel.e2e.flink.v2.mongodb;
+
+import static java.net.HttpURLConnection.HTTP_OK;
+import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
+
+import org.apache.seatunnel.e2e.flink.FlinkContainer;
+
+import com.google.common.collect.Lists;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
+import org.testcontainers.lifecycle.Startables;
+import org.testcontainers.utility.DockerImageName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.stream.Stream;
+
+@Slf4j
+public class FakeSourceToMongodbIT extends FlinkContainer {
+
+    private static final String MONGODB_IMAGE = "mongo:latest";
+
+    private static final String MONGODB_CONTAINER_HOST = "flink_e2e_mongodb_sink";
+
+    private static final int MONGODB_PORT = 27017;
+
+    private GenericContainer<?> mongodbContainer;
+
+    @BeforeEach
+    public void startMongoContainer() {
+        DockerImageName imageName = DockerImageName.parse(MONGODB_IMAGE);
+        mongodbContainer = new GenericContainer<>(imageName)
+            .withNetwork(NETWORK)
+            .withNetworkAliases(MONGODB_CONTAINER_HOST)
+            .withExposedPorts(MONGODB_PORT)
+            .waitingFor(new HttpWaitStrategy()
+                .forPort(MONGODB_PORT)
+                .forStatusCodeMatching(response -> response == HTTP_OK || response == HTTP_UNAUTHORIZED)
+                .withStartupTimeout(Duration.ofMinutes(2)))
+            .withLogConsumer(new Slf4jLogConsumer(log));
+        mongodbContainer.setPortBindings(Lists.newArrayList(String.format("%s:%s", MONGODB_PORT, MONGODB_PORT)));
+        Startables.deepStart(Stream.of(mongodbContainer)).join();
+        log.info("Mongodb container started");
+    }
+
+    @Test
+    public void testMongodbSource() throws IOException, InterruptedException {
+        Container.ExecResult execResult = executeSeaTunnelFlinkJob("/mongodb/fake_to_mongodb.conf");
+        Assertions.assertEquals(0, execResult.getExitCode());
+    }

Review Comment:
   You can refer the IOTDB Sink e2e



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

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] Hisoka-X merged pull request #2694: [Feature][Connector-V2] Add mongodb connecter sink

Posted by GitBox <gi...@apache.org>.
Hisoka-X merged PR #2694:
URL: https://github.com/apache/incubator-seatunnel/pull/2694


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

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] CalvinKirs commented on a diff in pull request #2694: [Feature][Connector-V2] Add mongodb connecter sink

Posted by GitBox <gi...@apache.org>.
CalvinKirs commented on code in PR #2694:
URL: https://github.com/apache/incubator-seatunnel/pull/2694#discussion_r966532606


##########
seatunnel-e2e/seatunnel-flink-connector-v2-e2e/connector-mongodb-flink-e2e/src/test/java/org/apache/seatunnel/e2e/flink/v2/mongodb/FakeSourceToMongodbIT.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.seatunnel.e2e.flink.v2.mongodb;
+
+import static java.net.HttpURLConnection.HTTP_OK;
+import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
+
+import org.apache.seatunnel.e2e.flink.FlinkContainer;
+
+import com.google.common.collect.Lists;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
+import org.testcontainers.lifecycle.Startables;
+import org.testcontainers.utility.DockerImageName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.stream.Stream;
+
+@Slf4j
+public class FakeSourceToMongodbIT extends FlinkContainer {
+
+    private static final String MONGODB_IMAGE = "mongo:latest";
+
+    private static final String MONGODB_CONTAINER_HOST = "flink_e2e_mongodb_sink";
+
+    private static final int MONGODB_PORT = 27017;
+
+    private GenericContainer<?> mongodbContainer;
+
+    @BeforeEach
+    public void startMongoContainer() {
+        DockerImageName imageName = DockerImageName.parse(MONGODB_IMAGE);
+        mongodbContainer = new GenericContainer<>(imageName)
+            .withNetwork(NETWORK)
+            .withNetworkAliases(MONGODB_CONTAINER_HOST)
+            .withExposedPorts(MONGODB_PORT)
+            .waitingFor(new HttpWaitStrategy()
+                .forPort(MONGODB_PORT)
+                .forStatusCodeMatching(response -> response == HTTP_OK || response == HTTP_UNAUTHORIZED)
+                .withStartupTimeout(Duration.ofMinutes(2)))
+            .withLogConsumer(new Slf4jLogConsumer(log));
+        mongodbContainer.setPortBindings(Lists.newArrayList(String.format("%s:%s", MONGODB_PORT, MONGODB_PORT)));
+        Startables.deepStart(Stream.of(mongodbContainer)).join();
+        log.info("Mongodb container started");
+    }
+
+    @Test
+    public void testMongodbSource() throws IOException, InterruptedException {
+        Container.ExecResult execResult = executeSeaTunnelFlinkJob("/mongodb/fake_to_mongodb.conf");
+        Assertions.assertEquals(0, execResult.getExitCode());
+    }

Review Comment:
   Could you verify that the sink data is written as you expected?



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

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] Hisoka-X commented on a diff in pull request #2694: [Feature][Connector-V2] Add mongodb connecter sink

Posted by GitBox <gi...@apache.org>.
Hisoka-X commented on code in PR #2694:
URL: https://github.com/apache/incubator-seatunnel/pull/2694#discussion_r966580661


##########
docs/en/connector-v2/sink/MongoDB.md:
##########
@@ -0,0 +1,46 @@
+# MongoDb
+
+> MongoDB sink connector
+
+## Description
+
+Write data to `MongoDB`
+
+## Key features
+
+- [x] [batch](../../concept/connector-v2-features.md)
+- [ ] [stream](../../concept/connector-v2-features.md)

Review Comment:
   In ours seatunnel sink api model, always support batch and stream



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

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] wuchunfu commented on a diff in pull request #2694: [Feature][Connector-V2] Add mongodb connecter sink

Posted by GitBox <gi...@apache.org>.
wuchunfu commented on code in PR #2694:
URL: https://github.com/apache/incubator-seatunnel/pull/2694#discussion_r966538164


##########
seatunnel-e2e/seatunnel-flink-connector-v2-e2e/connector-mongodb-flink-e2e/src/test/java/org/apache/seatunnel/e2e/flink/v2/mongodb/FakeSourceToMongodbIT.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.seatunnel.e2e.flink.v2.mongodb;
+
+import static java.net.HttpURLConnection.HTTP_OK;
+import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
+
+import org.apache.seatunnel.e2e.flink.FlinkContainer;
+
+import com.google.common.collect.Lists;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
+import org.testcontainers.lifecycle.Startables;
+import org.testcontainers.utility.DockerImageName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.stream.Stream;
+
+@Slf4j
+public class FakeSourceToMongodbIT extends FlinkContainer {
+
+    private static final String MONGODB_IMAGE = "mongo:latest";
+
+    private static final String MONGODB_CONTAINER_HOST = "flink_e2e_mongodb_sink";
+
+    private static final int MONGODB_PORT = 27017;
+
+    private GenericContainer<?> mongodbContainer;
+
+    @BeforeEach
+    public void startMongoContainer() {
+        DockerImageName imageName = DockerImageName.parse(MONGODB_IMAGE);
+        mongodbContainer = new GenericContainer<>(imageName)
+            .withNetwork(NETWORK)
+            .withNetworkAliases(MONGODB_CONTAINER_HOST)
+            .withExposedPorts(MONGODB_PORT)
+            .waitingFor(new HttpWaitStrategy()
+                .forPort(MONGODB_PORT)
+                .forStatusCodeMatching(response -> response == HTTP_OK || response == HTTP_UNAUTHORIZED)
+                .withStartupTimeout(Duration.ofMinutes(2)))
+            .withLogConsumer(new Slf4jLogConsumer(log));
+        mongodbContainer.setPortBindings(Lists.newArrayList(String.format("%s:%s", MONGODB_PORT, MONGODB_PORT)));
+        Startables.deepStart(Stream.of(mongodbContainer)).join();
+        log.info("Mongodb container started");
+    }
+
+    @Test
+    public void testMongodbSource() throws IOException, InterruptedException {
+        Container.ExecResult execResult = executeSeaTunnelFlinkJob("/mongodb/fake_to_mongodb.conf");
+        Assertions.assertEquals(0, execResult.getExitCode());
+    }

Review Comment:
   > Could you verify that the sink data is written as you expected?
   
   I have verified locally, but I don't know how to verify with the program, can you provide some help?



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

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

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


[GitHub] [incubator-seatunnel] wuchunfu commented on a diff in pull request #2694: [Feature][Connector-V2] Add mongodb connecter sink

Posted by GitBox <gi...@apache.org>.
wuchunfu commented on code in PR #2694:
URL: https://github.com/apache/incubator-seatunnel/pull/2694#discussion_r967566189


##########
seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/sink/MongodbSinkWriter.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.mongodb.sink;
+
+import org.apache.seatunnel.api.serialization.SerializationSchema;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import org.apache.seatunnel.connectors.seatunnel.mongodb.config.MongodbParameters;
+import org.apache.seatunnel.format.json.JsonSerializationSchema;
+
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import com.mongodb.client.MongoCollection;
+import org.bson.Document;
+
+import java.io.IOException;
+
+public class MongodbSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> {
+
+    private final SeaTunnelRowType rowType;
+
+    private final MongodbParameters params;
+
+    private final SerializationSchema serializationSchema;
+
+    private MongoClient client;
+
+    private final String database;
+
+    private final String collection;
+
+    public MongodbSinkWriter(SeaTunnelRowType rowType, MongodbParameters params) {
+        this.rowType = rowType;
+        this.params = params;
+        this.database = this.params.getDatabase();
+        this.collection = this.params.getCollection();
+        this.serializationSchema = new JsonSerializationSchema(rowType);
+    }
+
+    @Override
+    public void write(SeaTunnelRow rows) throws IOException {
+        byte[] serialize = serializationSchema.serialize(rows);
+        String content = new String(serialize);
+
+        this.client = MongoClients.create(params.getUri());

Review Comment:
   > Why not use these two variables as class attributes, too? Each time a piece of data is written, a client object and a collection object are retrieved, this results in unnecessary method calls and resource consumption.
   
   Makes sense, I was negligent, thanks for the reminder



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

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

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