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/08/19 02:38:08 UTC

[GitHub] [incubator-seatunnel] ic4y commented on a diff in pull request #2429: [Connector-V2][JDBC] Support database: greenplum

ic4y commented on code in PR #2429:
URL: https://github.com/apache/incubator-seatunnel/pull/2429#discussion_r949745863


##########
docs/en/connector-v2/sink/Greenplum.md:
##########
@@ -0,0 +1,17 @@
+# Greenplum
+
+> Greenplum sink connector

Review Comment:
   Need to indicate whether two-phase commit is supported, which is related to exactly-once semantics.
   How to configure `xa_data_source_class_name` if you perform a two-phase commit.
   It's better to add a job configuration example.



##########
seatunnel-e2e/seatunnel-flink-connector-v2-e2e/src/test/java/org/apache/seatunnel/e2e/flink/v2/jdbc/JdbcGreenplumIT.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.jdbc;
+
+import static org.testcontainers.shaded.org.awaitility.Awaitility.given;
+
+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.lifecycle.Startables;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+
+@Slf4j
+public class JdbcGreenplumIT extends FlinkContainer {
+
+    private static final String GREENPLUM_IMAGE = "datagrip/greenplum:6.8";
+    private static final String GREENPLUM_CONTAINER_HOST = "flink_e2e_greenplum";
+    private static final int GREENPLUM_CONTAINER_PORT = 5432;
+    private static final String GREENPLUM_HOST = "localhost";
+    private static final int GREENPLUM_PORT = 5435;
+    private static final String GREENPLUM_USER = "tester";
+    private static final String GREENPLUM_PASSWORD = "pivotal";
+    private static final String GREENPLUM_DRIVER = "org.postgresql.Driver";
+    private static final String GREENPLUM_JDBC_URL = String.format(
+            "jdbc:postgresql://%s:%s/testdb", GREENPLUM_HOST, GREENPLUM_PORT);
+
+    private GenericContainer<?> greenplumServer;
+    private Connection jdbcConnection;
+
+    @BeforeEach
+    public void startGreenplumContainer() throws ClassNotFoundException, SQLException {
+        greenplumServer = new GenericContainer<>(GREENPLUM_IMAGE)
+                .withNetwork(NETWORK)
+                .withNetworkAliases(GREENPLUM_CONTAINER_HOST)
+                .withLogConsumer(new Slf4jLogConsumer(log));
+        greenplumServer.setPortBindings(Lists.newArrayList(
+                String.format("%s:%s", GREENPLUM_PORT, GREENPLUM_CONTAINER_PORT)));
+        Startables.deepStart(Stream.of(greenplumServer)).join();
+        log.info("Greenplum container started");
+        // wait for Greenplum fully start
+        Class.forName(GREENPLUM_DRIVER);
+        given().ignoreExceptions()
+                .await()
+                .atMost(180, TimeUnit.SECONDS)
+                .untilAsserted(() -> initializeJdbcConnection());
+        initializeJdbcTable();
+        batchInsertData();
+    }
+
+    @Test
+    public void testJdbcGreenplumSourceAndSink() throws IOException, InterruptedException, SQLException {
+        Container.ExecResult execResult = executeSeaTunnelFlinkJob("/jdbc/jdbc_greenplum_source_and_sink.conf");
+        Assertions.assertEquals(0, execResult.getExitCode());
+
+        // query result
+        String sql = "select age, name from sink";
+        List<Object> result = new ArrayList<>();
+        try (Statement statement = jdbcConnection.createStatement()) {
+            ResultSet resultSet = statement.executeQuery(sql);
+            while (resultSet.next()) {
+                result.add(Arrays.asList(
+                        resultSet.getInt("age"),
+                        resultSet.getString("name")));
+            }
+        }
+        Assertions.assertEquals(100, result.size());

Review Comment:
   Only check the amount of data ? Is it possible to add data type and value validation



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