From 9f7565e21e25f5650b5e31a563c9e9cda7b06bbf Mon Sep 17 00:00:00 2001 From: Cynthia Yin Date: Tue, 19 Sep 2023 14:16:46 -0700 Subject: [PATCH] clean up --- .../bigquery/BigQueryReservedKeywords.java | 113 ------------------ .../snowflake/SnowflakeReservedKeywords.java | 113 ------------------ .../SnowflakeSqlGenerator.java | 14 ++- 3 files changed, 12 insertions(+), 228 deletions(-) delete mode 100644 airbyte-integrations/connectors/destination-bigquery/src/main/java/io/airbyte/integrations/destination/bigquery/BigQueryReservedKeywords.java delete mode 100644 airbyte-integrations/connectors/destination-snowflake/src/main/java/io/airbyte/integrations/destination/snowflake/SnowflakeReservedKeywords.java diff --git a/airbyte-integrations/connectors/destination-bigquery/src/main/java/io/airbyte/integrations/destination/bigquery/BigQueryReservedKeywords.java b/airbyte-integrations/connectors/destination-bigquery/src/main/java/io/airbyte/integrations/destination/bigquery/BigQueryReservedKeywords.java deleted file mode 100644 index 308a002244b7..000000000000 --- a/airbyte-integrations/connectors/destination-bigquery/src/main/java/io/airbyte/integrations/destination/bigquery/BigQueryReservedKeywords.java +++ /dev/null @@ -1,113 +0,0 @@ -package io.airbyte.integrations.destination.bigquery; - -import com.google.common.collect.ImmutableList; -import java.util.List; - -/** - * NOTE: This class is not used, but is created for completeness. - * See https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#reserved_keywords - * Copied from https://github.com/airbytehq/airbyte/blob/f226503bd1d4cd9c7412b04d47de584523988443/airbyte-integrations/bases/base-normalization/normalization/transform_catalog/reserved_keywords.py - */ -public class BigQueryReservedKeywords { - - public static final List RESERVED_KEYWORDS = ImmutableList.of( - "ALL", - "AND", - "ANY", - "ARRAY", - "AS", - "ASC", - "ASSERT_ROWS_MODIFIED", - "AT", - "BETWEEN", - "BY", - "CASE", - "CAST", - "COLLATE", - "CONTAINS", - "CREATE", - "CROSS", - "CUBE", - "CURRENT", - "CURRENT_DATE", - "CURRENT_TIME", - "CURRENT_TIMESTAMP", - "DEFAULT", - "DEFINE", - "DESC", - "DISTINCT", - "ELSE", - "END", - "ENUM", - "ESCAPE", - "EXCEPT", - "EXCLUDE", - "EXISTS", - "EXTRACT", - "FALSE", - "FETCH", - "FOLLOWING", - "FOR", - "FROM", - "FULL", - "GROUP", - "GROUPING", - "GROUPS", - "HASH", - "HAVING", - "IF", - "IGNORE", - "IN", - "INNER", - "INTERSECT", - "INTERVAL", - "INTO", - "IS", - "JOIN", - "LATERAL", - "LEFT", - "LIKE", - "LIMIT", - "LOOKUP", - "MERGE", - "NATURAL", - "NEW", - "NO", - "NOT", - "NULL", - "NULLS", - "OF", - "ON", - "OR", - "ORDER", - "OUTER", - "OVER", - "PARTITION", - "PRECEDING", - "PROTO", - "RANGE", - "RECURSIVE", - "RESPECT", - "RIGHT", - "ROLLUP", - "ROWS", - "SELECT", - "SET", - "SOME", - "STRUCT", - "TABLESAMPLE", - "THEN", - "TO", - "TREAT", - "TRUE", - "UNBOUNDED", - "UNION", - "UNNEST", - "USING", - "WHEN", - "WHERE", - "WINDOW", - "WITH", - "WITHIN"); - -} diff --git a/airbyte-integrations/connectors/destination-snowflake/src/main/java/io/airbyte/integrations/destination/snowflake/SnowflakeReservedKeywords.java b/airbyte-integrations/connectors/destination-snowflake/src/main/java/io/airbyte/integrations/destination/snowflake/SnowflakeReservedKeywords.java deleted file mode 100644 index 85ff6851b373..000000000000 --- a/airbyte-integrations/connectors/destination-snowflake/src/main/java/io/airbyte/integrations/destination/snowflake/SnowflakeReservedKeywords.java +++ /dev/null @@ -1,113 +0,0 @@ -package io.airbyte.integrations.destination.snowflake; - -import com.google.common.collect.ImmutableList; -import java.util.List; - -/** - * See https://docs.snowflake.com/en/sql-reference/reserved-keywords.html - * Copied from https://github.com/airbytehq/airbyte/blob/f226503bd1d4cd9c7412b04d47de584523988443/airbyte-integrations/bases/base-normalization/normalization/transform_catalog/reserved_keywords.py - */ -public class SnowflakeReservedKeywords { - - public static final List RESERVED_KEYWORDS = ImmutableList.of( - "ALL", - "ALTER", - "AND", - "ANY", - "AS", - "BETWEEN", - "BY", - "CASE", - "CAST", - "CHECK", - "COLUMN", - "CONNECT", - "CONNECTION", - "CONSTRAINT", - "CREATE", - "CROSS", - "CURRENT", - "CURRENT_DATE", - "CURRENT_TIME", - "CURRENT_TIMESTAMP", - "CURRENT_USER", - "DATABASE", - "DEFAULT", - "DELETE", - "DISTINCT", - "DROP", - "ELSE", - "EXISTS", - "FALSE", - "FOLLOWING", - "FOR", - "FROM", - "FULL", - "GRANT", - "GROUP", - "GSCLUSTER", - "HAVING", - "ILIKE", - "IN", - "INCREMENT", - "INNER", - "INSERT", - "INTERSECT", - "INTO", - "IS", - "ISSUE", - "JOIN", - "LATERAL", - "LEFT", - "LIKE", - "LOCALTIME", - "LOCALTIMESTAMP", - "MINUS", - "NATURAL", - "NOT", - "NULL", - "OF", - "ON", - "OR", - "ORDER", - "ORGANIZATION", - "QUALIFY", - "REGEXP", - "REVOKE", - "RIGHT", - "RLIKE", - "ROW", - "ROWS", - "SAMPLE", - "SCHEMA", - "SELECT", - "SET", - "SOME", - "START", - "TABLE", - "TABLESAMPLE", - "THEN", - "TO", - "TRIGGER", - "TRUE", - "TRY_CAST", - "UNION", - "UNIQUE", - "UPDATE", - "USING", - "VALUES", - "VIEW", - "WHEN", - "WHENEVER", - "WHERE", - "WITH"); - - public static final List RESERVED_COLUMN_NAMES = ImmutableList.of( - "CURRENT_DATE", - "CURRENT_TIME", - "CURRENT_TIMESTAMP", - "CURRENT_USER", - "LOCALTIME", - "LOCALTIMESTAMP"); - -} diff --git a/airbyte-integrations/connectors/destination-snowflake/src/main/java/io/airbyte/integrations/destination/snowflake/typing_deduping/SnowflakeSqlGenerator.java b/airbyte-integrations/connectors/destination-snowflake/src/main/java/io/airbyte/integrations/destination/snowflake/typing_deduping/SnowflakeSqlGenerator.java index 57ca3db3a7f4..7138ce1abb4d 100644 --- a/airbyte-integrations/connectors/destination-snowflake/src/main/java/io/airbyte/integrations/destination/snowflake/typing_deduping/SnowflakeSqlGenerator.java +++ b/airbyte-integrations/connectors/destination-snowflake/src/main/java/io/airbyte/integrations/destination/snowflake/typing_deduping/SnowflakeSqlGenerator.java @@ -7,6 +7,7 @@ import static java.util.stream.Collectors.joining; import com.google.common.annotations.VisibleForTesting; +import com.google.common.collect.ImmutableList; import io.airbyte.integrations.base.JavaBaseConstants; import io.airbyte.integrations.base.destination.typing_deduping.AirbyteProtocolType; import io.airbyte.integrations.base.destination.typing_deduping.AirbyteType; @@ -19,7 +20,6 @@ import io.airbyte.integrations.base.destination.typing_deduping.TableNotMigratedException; import io.airbyte.integrations.base.destination.typing_deduping.Union; import io.airbyte.integrations.base.destination.typing_deduping.UnsupportedOneOf; -import io.airbyte.integrations.destination.snowflake.SnowflakeReservedKeywords; import io.airbyte.protocol.models.v0.DestinationSyncMode; import java.util.Arrays; import java.util.LinkedHashMap; @@ -35,6 +35,16 @@ public class SnowflakeSqlGenerator implements SqlGenerator RESERVED_COLUMN_NAMES = ImmutableList.of( + "CURRENT_DATE", + "CURRENT_TIME", + "CURRENT_TIMESTAMP", + "CURRENT_USER", + "LOCALTIME", + "LOCALTIMESTAMP"); + @Override public StreamId buildStreamId(final String namespace, final String name, final String rawNamespaceOverride) { // No escaping needed, as far as I can tell. We quote all our identifier names. @@ -582,7 +592,7 @@ public static String escapeSqlIdentifier(String identifier) { } private static String prefixReservedColumnName(final String columnName) { - return SnowflakeReservedKeywords.RESERVED_COLUMN_NAMES.stream().anyMatch(k -> k.equalsIgnoreCase(columnName)) ? + return RESERVED_COLUMN_NAMES.stream().anyMatch(k -> k.equalsIgnoreCase(columnName)) ? "_" + columnName : columnName; }