You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "eskabetxe (via GitHub)" <gi...@apache.org> on 2023/04/26 08:45:38 UTC

[GitHub] [flink-connector-jdbc] eskabetxe commented on a diff in pull request #33: [FLINK-27429] Add Vertica JDBC dialect

eskabetxe commented on code in PR #33:
URL: https://github.com/apache/flink-connector-jdbc/pull/33#discussion_r1177531154


##########
flink-connector-jdbc/src/main/java/org/apache/flink/connector/jdbc/dialect/vertica/VerticaDialect.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.flink.connector.jdbc.dialect.vertica;
+
+import org.apache.flink.connector.jdbc.converter.JdbcRowConverter;
+import org.apache.flink.connector.jdbc.dialect.AbstractDialect;
+import org.apache.flink.connector.jdbc.internal.converter.VerticaRowConverter;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+import org.apache.flink.table.types.logical.RowType;
+
+import java.util.EnumSet;
+import java.util.Optional;
+import java.util.Set;
+
+/** JDBC dialect for Vertica. */
+public class VerticaDialect extends AbstractDialect {
+
+    private static final long serialVersionUID = 1L;
+
+    // Define MAX/MIN precision of TIMESTAMP type according to Vertica docs:
+    // https://www.vertica.com/docs/12.0.x/HTML/Content/Authoring/SQLReferenceManual/DataTypes/Date-Time/DateTimeDataTypes.htm
+    private static final int MAX_TIMESTAMP_PRECISION = 6;
+    private static final int MIN_TIMESTAMP_PRECISION = 0;
+
+    // Define MAX/MIN precision of DECIMAL type according to Vertica docs:
+    // https://www.vertica.com/docs/12.0.x/HTML/Content/Authoring/SQLReferenceManual/DataTypes/Numeric/NUMERIC.htm
+    private static final int MAX_DECIMAL_PRECISION = 1024;
+    private static final int MIN_DECIMAL_PRECISION = 1;
+
+    @Override
+    public Set<LogicalTypeRoot> supportedTypes() {
+        // List of Vertica data types:
+        // https://www.vertica.com/docs/12.0.x/HTML/Content/Authoring/SQLReferenceManual/DataTypes/SQLDataTypes.htm
+        // https://www.vertica.com/docs/12.0.x/HTML/Content/Authoring/ConnectingToVertica/ClientJDBC/JDBCDataTypes.htm
+
+        return EnumSet.of(
+                LogicalTypeRoot.BINARY,
+                LogicalTypeRoot.VARBINARY,
+                LogicalTypeRoot.BOOLEAN,
+                LogicalTypeRoot.CHAR,
+                LogicalTypeRoot.VARCHAR,
+                LogicalTypeRoot.DATE,
+                LogicalTypeRoot.TIME_WITHOUT_TIME_ZONE,
+                LogicalTypeRoot.TIMESTAMP_WITH_TIME_ZONE,
+                LogicalTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE,
+                LogicalTypeRoot.DOUBLE,
+                LogicalTypeRoot.DECIMAL,
+                LogicalTypeRoot.BIGINT,
+                LogicalTypeRoot.ARRAY);
+    }
+
+    @Override
+    public String dialectName() {
+        return "Vertica";
+    }
+
+    @Override
+    public JdbcRowConverter getRowConverter(RowType rowType) {
+        return new VerticaRowConverter(rowType);
+    }
+
+    @Override
+    public String getLimitClause(long limit) {
+        return "LIMIT " + limit;
+    }
+
+    @Override
+    public Optional<String> defaultDriverName() {
+        return Optional.of("com.vertica.jdbc.Driver");
+    }
+
+    @Override
+    public String quoteIdentifier(String identifier) {
+        return "\"" + identifier + "\"";
+    }
+
+    @Override
+    public Optional<Range> decimalPrecisionRange() {
+        return Optional.of(Range.of(MIN_DECIMAL_PRECISION, MAX_DECIMAL_PRECISION));
+    }
+
+    @Override
+    public Optional<Range> timestampPrecisionRange() {
+        return Optional.of(Range.of(MIN_TIMESTAMP_PRECISION, MAX_TIMESTAMP_PRECISION));
+    }
+
+    @Override
+    public Optional<String> getUpsertStatement(
+            String tableName, String[] fieldNames, String[] uniqueKeyFields) {
+        throw new UnsupportedOperationException(

Review Comment:
   we could use a MERGE no?
   https://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/SQLReferenceManual/Statements/MERGE.htm
   
   see OracleDialect for example..



##########
docs/content.zh/docs/connectors/table/jdbc.md:
##########
@@ -663,20 +668,22 @@ Flink 支持连接到多个使用方言(dialect)的数据库,如 MySQL、O
         <code>BIGINT</code><br>
         <code>BIGSERIAL</code></td>
       <td><code>BIGINT</code></td>
+      <td>
+        <code>INTEGER</code><br>
+        <code>INT</code><br>
+        <code>BIGINT</code><br>
+        <code>INT8</code><br>
+        <code>SMALLINT</code><br>
+        <code>TINYINT</code></td>
       <td><code>BIGINT</code></td>
     </tr>
    <tr>
       <td><code>BIGINT UNSIGNED</code></td>
       <td></td>
       <td></td>
       <td></td>
-      <td><code>DECIMAL(20, 0)</code></td>

Review Comment:
   Why we are removing this?



##########
flink-connector-jdbc/src/test/java/org/apache/flink/connector/jdbc/databases/vertica/VerticaDatabase.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.flink.connector.jdbc.databases.vertica;
+
+import org.apache.flink.connector.jdbc.databases.DatabaseMetadata;
+import org.apache.flink.connector.jdbc.databases.DatabaseTest;
+
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.utility.DockerImageName;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+/** A Vertica database for testing. */
+@Testcontainers
+public interface VerticaDatabase extends DatabaseTest {
+
+    DockerImageName VERTICA_CE = DockerImageName.parse("vertica/vertica-ce");
+
+    @Container
+    GenericContainer<?> CONTAINER = new GenericContainer<>(VERTICA_CE).withExposedPorts(5433);
+
+    @Override
+    default DatabaseMetadata getMetadata() {
+        return new VerticaMetadata(CONTAINER);
+    }
+
+    static Connection getConnection() throws SQLException, ClassNotFoundException {

Review Comment:
   DatabaseMetadata already have a getConnection, is really needed this?



-- 
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: issues-unsubscribe@flink.apache.org

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