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/07 14:19:20 UTC

[GitHub] [incubator-seatunnel] hailin0 commented on a diff in pull request #2586: [SeaTunnel][Connector-v2][Doris]Support Doris Sink.

hailin0 commented on code in PR #2586:
URL: https://github.com/apache/incubator-seatunnel/pull/2586#discussion_r964851573


##########
seatunnel-examples/seatunnel-flink-connector-v2-example/pom.xml:
##########
@@ -32,6 +32,16 @@
         <flink.scope>compile</flink.scope>
     </properties>
 
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>commons-io</groupId>
+                <artifactId>commons-io</artifactId>
+                <version>2.8.0</version>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+

Review Comment:
   revert?



##########
pom.xml:
##########
@@ -277,6 +278,20 @@
                 <scope>test</scope>
             </dependency>
 
+            <dependency>
+                <groupId>org.junit.jupiter</groupId>
+                <artifactId>junit-jupiter</artifactId>
+                <version>${junit.version}</version>
+                <scope>test</scope>
+            </dependency>
+
+            <dependency>
+                <groupId>org.junit.jupiter</groupId>
+                <artifactId>junit-jupiter-api</artifactId>
+                <version>${junit.version}</version>
+                <scope>test</scope>
+            </dependency>
+

Review Comment:
   remove.
   
   waiting for dev branch fix



##########
seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/common/HttpClient.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.doris.common;
+
+import com.google.common.io.Closeables;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpHead;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
+import org.apache.http.impl.client.DefaultRedirectStrategy;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.util.EntityUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.IOException;
+
+public class HttpClient {
+    private static final Logger LOG = LoggerFactory.getLogger(HttpClient.class);
+
+    private CloseableHttpClient client;
+    private PoolingHttpClientConnectionManager connectionManager;
+
+    public HttpClient(DorisOptions dorisOptions) {

Review Comment:
   reference
   https://github.com/apache/incubator-seatunnel/pull/2536#discussion_r956830723



##########
seatunnel-e2e/seatunnel-spark-connector-v2-e2e/connector-doris-spark-e2e/src/test/java/org/apache/seatunnel/e2e/spark/v2/doris/FakeSourceToDorisIT.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.spark.v2.doris;
+
+import org.apache.seatunnel.e2e.spark.SparkContainer;
+
+import org.apache.commons.compress.utils.Lists;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;
+import org.testcontainers.lifecycle.Startables;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+
+public class FakeSourceToDorisIT extends SparkContainer {
+    private static final Logger LOG = LoggerFactory.getLogger(FakeSourceToDorisIT.class);
+
+    private static final String DORIS_DRIVER = "com.mysql.cj.jdbc.Driver";
+    private static final String DORIS_CONNECTION_URL = "jdbc:mysql://localhost:9030?rewriteBatchedStatements=true";
+    private static final String DORIS_PASSWD = "";
+    private static final String DORIS_USERNAME = "root";
+
+    private static final String DORIS_DATABASE = "test";
+    private static final String DORIS_TABLE = "seatunnel";
+    private static final String DORIS_DATABASE_DDL = "CREATE DATABASE IF NOT EXISTS `" + DORIS_DATABASE + "`";
+    private static final String DORIS_USE_DATABASE = "USE `" + DORIS_DATABASE + "`";
+    private static final String DORIS_TABLE_DDL = "CREATE TABLE " +
+        "IF NOT EXISTS `" + DORIS_TABLE + "` " +
+        "(`name` varchar(255) NULL ) " +
+        "ENGINE=OLAP AGGREGATE KEY(`name`) " +
+        "DISTRIBUTED BY HASH(`name`) " +
+        "BUCKETS 1 " +
+        "PROPERTIES " +
+        "( 'replication_allocation' = 'tag.location.default: 1', 'in_memory' = 'false');";
+
+    private static final String DORIS_TABLE_TRUNCATE_TABLE = "TRUNCATE TABLE `" + DORIS_TABLE + "`";
+
+    //thanks zhaomin1432 provided the doris images.
+    private static final String DORIS_IMAGE_NAME = "zhaomin1423/doris:1.0.0-b2";
+    private static final int DORIS_FE_PORT = 8030;
+    private static final int DORIS_QUERY_PORT = 8040;
+    private static final int DORIS_BE_PORT = 9030;
+
+    private GenericContainer<?> dorisStandaloneServer;
+    private Connection connection;
+
+    @BeforeEach
+    public void before() throws InterruptedException {
+        super.before();
+        dorisStandaloneServer = new GenericContainer<>(DORIS_IMAGE_NAME)
+            .withNetwork(NETWORK)
+            .withNetworkAliases("seatunnel-doris-network")
+            .withLogConsumer(new Slf4jLogConsumer(LOG));
+        List<String> portBindings = Lists.newArrayList();
+        portBindings.add(String.format("%s:%s", DORIS_FE_PORT, DORIS_FE_PORT));
+        portBindings.add(String.format("%s:%s", DORIS_QUERY_PORT, DORIS_QUERY_PORT));
+        portBindings.add(String.format("%s:%s", DORIS_BE_PORT, DORIS_BE_PORT));
+        dorisStandaloneServer.setPortBindings(portBindings);
+        Startables.deepStart(Stream.of(dorisStandaloneServer)).join();
+        Thread.sleep(TimeUnit.MINUTES.toMillis(1));
+        dorisStandaloneServer.waitingFor(new HostPortWaitStrategy());
+        LOG.info("Doris frontend endpoint and backend endpoint started.");
+        initializeDoris();
+    }
+
+    private void initializeDoris() {
+        try {
+            connection = getDorisConnection();
+            Statement statement = connection.createStatement();
+            statement.execute(DORIS_DATABASE_DDL);
+            statement.execute(DORIS_USE_DATABASE);
+            statement.execute(DORIS_TABLE_DDL);
+            statement.execute(DORIS_TABLE_TRUNCATE_TABLE);
+            statement.close();
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    private static Connection getDorisConnection() throws ClassNotFoundException, SQLException {
+        Class.forName(DORIS_DRIVER);
+        return DriverManager.getConnection(DORIS_CONNECTION_URL, DORIS_USERNAME, DORIS_PASSWD);
+    }
+
+    @AfterEach
+    public void after() throws SQLException {
+        if (Objects.nonNull(connection)) {
+            connection.close();
+        }
+        if (Objects.nonNull(dorisStandaloneServer)) {
+            dorisStandaloneServer.close();
+        }
+        super.close();
+    }
+
+    //Caused by some reasons, doris image can't run in Mac M1.
+    @Test
+    public void testFakeSourceToConsoleSink() throws IOException, InterruptedException {
+        Container.ExecResult execResult = executeSeaTunnelSparkJob("/doris/fakesource_to_doris.conf");
+        Assertions.assertEquals(0, execResult.getExitCode());

Review Comment:
   Read doris data to validate?



##########
seatunnel-examples/seatunnel-flink-connector-v2-example/pom.xml:
##########
@@ -76,6 +86,11 @@
             <artifactId>connector-dingtalk</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.seatunnel</groupId>
+            <artifactId>connector-datahub</artifactId>
+            <version>${project.version}</version>
+        </dependency>

Review Comment:
   revert?



##########
seatunnel-connectors-v2/connector-doris/pom.xml:
##########
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>seatunnel-connectors-v2</artifactId>
+        <groupId>org.apache.seatunnel</groupId>
+        <version>${revision}</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>connector-doris</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.seatunnel</groupId>
+            <artifactId>connector-common</artifactId>
+            <version>${revision}</version>

Review Comment:
   add <scope>provided</scope>



##########
seatunnel-e2e/seatunnel-spark-connector-v2-e2e/connector-doris-spark-e2e/src/test/resources/doris/fakesource_to_doris.conf:
##########
@@ -0,0 +1,64 @@
+#
+# 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"
+  #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 {
+        name = "string"

Review Comment:
   test all datatypes?



##########
seatunnel-e2e/seatunnel-spark-connector-v2-e2e/connector-doris-spark-e2e/src/test/java/org/apache/seatunnel/e2e/spark/v2/doris/FakeSourceToDorisIT.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.spark.v2.doris;
+
+import org.apache.seatunnel.e2e.spark.SparkContainer;
+
+import org.apache.commons.compress.utils.Lists;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;
+import org.testcontainers.lifecycle.Startables;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+
+public class FakeSourceToDorisIT extends SparkContainer {
+    private static final Logger LOG = LoggerFactory.getLogger(FakeSourceToDorisIT.class);
+
+    private static final String DORIS_DRIVER = "com.mysql.cj.jdbc.Driver";
+    private static final String DORIS_CONNECTION_URL = "jdbc:mysql://localhost:9030?rewriteBatchedStatements=true";
+    private static final String DORIS_PASSWD = "";
+    private static final String DORIS_USERNAME = "root";
+
+    private static final String DORIS_DATABASE = "test";
+    private static final String DORIS_TABLE = "seatunnel";
+    private static final String DORIS_DATABASE_DDL = "CREATE DATABASE IF NOT EXISTS `" + DORIS_DATABASE + "`";
+    private static final String DORIS_USE_DATABASE = "USE `" + DORIS_DATABASE + "`";
+    private static final String DORIS_TABLE_DDL = "CREATE TABLE " +
+        "IF NOT EXISTS `" + DORIS_TABLE + "` " +
+        "(`name` varchar(255) NULL ) " +
+        "ENGINE=OLAP AGGREGATE KEY(`name`) " +
+        "DISTRIBUTED BY HASH(`name`) " +
+        "BUCKETS 1 " +
+        "PROPERTIES " +
+        "( 'replication_allocation' = 'tag.location.default: 1', 'in_memory' = 'false');";
+
+    private static final String DORIS_TABLE_TRUNCATE_TABLE = "TRUNCATE TABLE `" + DORIS_TABLE + "`";
+
+    //thanks zhaomin1432 provided the doris images.
+    private static final String DORIS_IMAGE_NAME = "zhaomin1423/doris:1.0.0-b2";
+    private static final int DORIS_FE_PORT = 8030;
+    private static final int DORIS_QUERY_PORT = 8040;
+    private static final int DORIS_BE_PORT = 9030;
+
+    private GenericContainer<?> dorisStandaloneServer;
+    private Connection connection;
+
+    @BeforeEach
+    public void before() throws InterruptedException {
+        super.before();
+        dorisStandaloneServer = new GenericContainer<>(DORIS_IMAGE_NAME)
+            .withNetwork(NETWORK)
+            .withNetworkAliases("seatunnel-doris-network")
+            .withLogConsumer(new Slf4jLogConsumer(LOG));
+        List<String> portBindings = Lists.newArrayList();
+        portBindings.add(String.format("%s:%s", DORIS_FE_PORT, DORIS_FE_PORT));
+        portBindings.add(String.format("%s:%s", DORIS_QUERY_PORT, DORIS_QUERY_PORT));
+        portBindings.add(String.format("%s:%s", DORIS_BE_PORT, DORIS_BE_PORT));
+        dorisStandaloneServer.setPortBindings(portBindings);
+        Startables.deepStart(Stream.of(dorisStandaloneServer)).join();
+        Thread.sleep(TimeUnit.MINUTES.toMillis(1));
+        dorisStandaloneServer.waitingFor(new HostPortWaitStrategy());
+        LOG.info("Doris frontend endpoint and backend endpoint started.");
+        initializeDoris();
+    }
+
+    private void initializeDoris() {
+        try {
+            connection = getDorisConnection();
+            Statement statement = connection.createStatement();
+            statement.execute(DORIS_DATABASE_DDL);
+            statement.execute(DORIS_USE_DATABASE);
+            statement.execute(DORIS_TABLE_DDL);
+            statement.execute(DORIS_TABLE_TRUNCATE_TABLE);
+            statement.close();
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    private static Connection getDorisConnection() throws ClassNotFoundException, SQLException {
+        Class.forName(DORIS_DRIVER);
+        return DriverManager.getConnection(DORIS_CONNECTION_URL, DORIS_USERNAME, DORIS_PASSWD);
+    }
+
+    @AfterEach
+    public void after() throws SQLException {
+        if (Objects.nonNull(connection)) {
+            connection.close();
+        }
+        if (Objects.nonNull(dorisStandaloneServer)) {
+            dorisStandaloneServer.close();
+        }
+        super.close();
+    }
+
+    //Caused by some reasons, doris image can't run in Mac M1.
+    @Test
+    public void testFakeSourceToConsoleSink() throws IOException, InterruptedException {

Review Comment:
   rename to `testFakeSourceToDorisSink`



##########
seatunnel-e2e/seatunnel-spark-connector-v2-e2e/connector-spark-e2e-base/src/test/java/org/apache/seatunnel/e2e/spark/SparkContainer.java:
##########
@@ -63,7 +63,7 @@ public abstract class SparkContainer {
     private static final int WAIT_SPARK_JOB_SUBMIT = 5000;
 
     @BeforeEach
-    public void before() {
+    public void before() throws InterruptedException {

Review Comment:
   revert?



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