Skip to content

Commit

Permalink
feat: unit test and doc for snowflake dialect
Browse files Browse the repository at this point in the history
  • Loading branch information
boris-snyk committed May 1, 2024
1 parent 7a3b94a commit d5c7126
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 3 deletions.
43 changes: 40 additions & 3 deletions docs/content/docs/connectors/table/jdbc.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ A driver dependency is also required to connect to a specified database. Here ar
| CrateDB | `io.crate` | `crate-jdbc` | [Download](https://repo1.maven.org/maven2/io/crate/crate-jdbc/) |
| Db2 | `com.ibm.db2.jcc` | `db2jcc` | [Download](https://www.ibm.com/support/pages/download-db2-fix-packs-version-db2-linux-unix-and-windows) |
| Trino | `io.trino` | `trino-jdbc` | [Download](https://repo1.maven.org/maven2/io/trino/trino-jdbc/) |
| OceanBase | `com.oceanbase` | `oceanbase-client` | [Download](https://repo1.maven.org/maven2/com/oceanbase/oceanbase-client/) |

| OceanBase | `com.oceanbase` | `oceanbase-client` | [Download](https://repo1.maven.org/maven2/net/snowflake/snowflake-jdbc/)

JDBC connector and drivers are not part of Flink's binary distribution. See how to link with them for cluster execution [here]({{< ref "docs/dev/configuration/overview" >}}).

Expand Down Expand Up @@ -433,6 +432,13 @@ As there is no standard syntax for upsert, the following table describes the dat
WHEN NOT MATCHED THEN INSERT (..) <br>
VALUES (..)</td>
</tr>
<tr>
<td>Snowflake</td>
<td>MERGE INTO .. USING (..) ON (..) <br>
WHEN MATCHED THEN UPDATE SET (..) <br>
WHEN NOT MATCHED THEN INSERT (..) <br>
VALUES (..)</td>
</tr>
</tbody>
</table>

Expand Down Expand Up @@ -670,6 +676,7 @@ Flink supports connect to several databases which uses dialect like MySQL, Oracl
<th class="text-left"><a href="https://trino.io/docs/current/language/types.html">Trino type</a></th>
<th class="text-left"><a href="https://en.oceanbase.com/docs/common-oceanbase-database-10000000001106898">OceanBase MySQL mode type</a></th>
<th class="text-left"><a href="https://en.oceanbase.com/docs/common-oceanbase-database-10000000001107076">OceanBase Oracle mode type</a></th>
<th class="text-left"><a href="https://docs.snowflake.com/en/sql-reference-data-types">Snowflake</a></th>
<th class="text-left"><a href="{{< ref "docs/dev/table/types" >}}">Flink SQL type</a></th>
</tr>
</thead>
Expand All @@ -684,6 +691,7 @@ Flink supports connect to several databases which uses dialect like MySQL, Oracl
<td><code>TINYINT</code></td>
<td><code>TINYINT</code></td>
<td></td>
<td></td>
<td><code>TINYINT</code></td>
</tr>
<tr>
Expand All @@ -706,6 +714,7 @@ Flink supports connect to several databases which uses dialect like MySQL, Oracl
<code>SMALLINT</code><br>
<code>TINYINT UNSIGNED</code></td>
<td></td>
<td>SMALLINT</td>
<td><code>SMALLINT</code></td>
</tr>
<tr>
Expand All @@ -728,6 +737,7 @@ Flink supports connect to several databases which uses dialect like MySQL, Oracl
<code>MEDIUMINT</code><br>
<code>SMALLINT UNSIGNED</code></td>
<td></td>
<td>INT</td>
<td><code>INT</code></td>
</tr>
<tr>
Expand All @@ -748,6 +758,7 @@ Flink supports connect to several databases which uses dialect like MySQL, Oracl
<code>BIGINT</code><br>
<code>INT UNSIGNED</code></td>
<td></td>
<td>BIGINT</td>
<td><code>BIGINT</code></td>
</tr>
<tr>
Expand All @@ -760,6 +771,7 @@ Flink supports connect to several databases which uses dialect like MySQL, Oracl
<td></td>
<td><code>BIGINT UNSIGNED</code></td>
<td></td>
<td></td>
<td><code>DECIMAL(20, 0)</code></td>
</tr>
<tr>
Expand All @@ -778,6 +790,9 @@ Flink supports connect to several databases which uses dialect like MySQL, Oracl
<td><code>FLOAT</code></td>
<td>
<code>BINARY_FLOAT</code></td>
<td>
<code>REAL</code><br>
<code>FLOAT</code></td>
<td><code>FLOAT</code></td>
</tr>
<tr>
Expand All @@ -796,6 +811,9 @@ Flink supports connect to several databases which uses dialect like MySQL, Oracl
<td><code>DOUBLE</code></td>
<td><code>DOUBLE</code></td>
<td><code>BINARY_DOUBLE</code></td>
<td>
<code>DOUBLE</code><br>
<code>DOUBLE PRECISION</code></td>
<td><code>DOUBLE</code></td>
</tr>
<tr>
Expand Down Expand Up @@ -824,6 +842,7 @@ Flink supports connect to several databases which uses dialect like MySQL, Oracl
<td>
<code>FLOAT(s)</code><br>
<code>NUMBER(p, s)</code></td>
<td><code>NUMERIC(p, s)</code></td>
<td><code>DECIMAL(p, s)</code></td>
</tr>
<tr>
Expand All @@ -841,6 +860,7 @@ Flink supports connect to several databases which uses dialect like MySQL, Oracl
<code>TINYINT(1)</code></td>
<td></td>
<td><code>BOOLEAN</code></td>
<td><code>BOOLEAN</code></td>
</tr>
<tr>
<td><code>DATE</code></td>
Expand All @@ -853,6 +873,7 @@ Flink supports connect to several databases which uses dialect like MySQL, Oracl
<td><code>DATE</code></td>
<td><code>DATE</code></td>
<td><code>DATE</code></td>
<td><code>DATE</code></td>
</tr>
<tr>
<td><code>TIME [(p)]</code></td>
Expand All @@ -864,6 +885,7 @@ Flink supports connect to several databases which uses dialect like MySQL, Oracl
<td><code>TIME_WITHOUT_TIME_ZONE</code></td>
<td><code>TIME [(p)]</code></td>
<td><code>DATE</code></td>
<td><code>DATE</code></td>
<td><code>TIME [(p)] [WITHOUT TIMEZONE]</code></td>
</tr>
<tr>
Expand All @@ -880,6 +902,7 @@ Flink supports connect to several databases which uses dialect like MySQL, Oracl
<td><code>DATETIME [(p)]</code></td>
<td><code>TIMESTAMP [(p)] [WITHOUT TIMEZONE]</code></td>
<td><code>TIMESTAMP [(p)] [WITHOUT TIMEZONE]</code></td>
<td><code>TIMESTAMP [(p)] [WITHOUT TIMEZONE]</code></td>
</tr>
<tr>
<td>
Expand Down Expand Up @@ -927,6 +950,14 @@ Flink supports connect to several databases which uses dialect like MySQL, Oracl
<code>NCHAR(n)</code><br>
<code>VARCHAR2(n)</code><br>
<code>CLOB</code></td>
<td>
<code>CHAR(n)</code><br>
<code>CHARACTER(n)</code><br>
<code>VARCHAR(n)</code><br>
<code>CHARACTER VARYING(n)</code><br>
<code>TEXT</code>
<code>STRING</code>
</td>
<td><code>STRING</code></td>
</tr>
<tr>
Expand All @@ -951,7 +982,12 @@ Flink supports connect to several databases which uses dialect like MySQL, Oracl
<code>BLOB</code></td>
<td>
<code>RAW(s)</code><br>
<code>BLOB</code></td>
<code>BLOB</code>
</td>
<td>
<code>BINARY(n)</code><br>
<code>VARBINARY(n)</code><br>
</td>
<td><code>BYTES</code></td>
</tr>
<tr>
Expand All @@ -965,6 +1001,7 @@ Flink supports connect to several databases which uses dialect like MySQL, Oracl
<td></td>
<td></td>
<td><code>ARRAY</code></td>
<td><code>ARRAY</code></td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.snowflake.dialect;

import org.apache.flink.connector.jdbc.dialect.JdbcDialectTypeTest;

import java.util.Arrays;
import java.util.List;

/** Tests for all DataTypes and Dialects of JDBC Snowflake connector. */
public class SnowflakeDialectTypeTest extends JdbcDialectTypeTest {
@Override
protected String testDialect() {
return "snowflake";
}

@Override
protected List<JdbcDialectTypeTest.TestItem> testData() {
return Arrays.asList(
createTestItem("BOOLEAN"),

createTestItem("TINYINT"),
createTestItem("SMALLINT"),
createTestItem("BIGINT"),
createTestItem("INT"),
createTestItem("INTEGER"),

createTestItem("DECIMAL"),
createTestItem("NUMERIC"),

createTestItem("DOUBLE"),
createTestItem("FLOAT"),

createTestItem("DECIMAL(10, 4)"),
createTestItem("DECIMAL(38, 18)"),
createTestItem("VARCHAR"),
createTestItem("CHAR"),
createTestItem("VARBINARY"),
createTestItem("DATE"),
createTestItem("TIME"),
createTestItem("TIMESTAMP(3)"),
createTestItem("TIMESTAMP WITHOUT TIME ZONE"),
createTestItem("TIMESTAMP(1) WITHOUT TIME ZONE"),
// Not valid data
createTestItem("TIMESTAMP_LTZ(3)", "Unsupported type:TIMESTAMP_LTZ(3)"));
}
}

0 comments on commit d5c7126

Please sign in to comment.