From bf9a407fceb4729a8497d0377f49484de34f70e7 Mon Sep 17 00:00:00 2001 From: Pat Nadolny Date: Fri, 26 Jul 2024 12:40:49 -0400 Subject: [PATCH] add test to alter a table using a reserved word --- tests/core.py | 28 +++++++++++++++++++ .../existing_reserved_name_table_alter.singer | 2 ++ 2 files changed, 30 insertions(+) create mode 100644 tests/target_test_streams/existing_reserved_name_table_alter.singer diff --git a/tests/core.py b/tests/core.py index ec5db3f..f7cfb78 100644 --- a/tests/core.py +++ b/tests/core.py @@ -456,6 +456,33 @@ def setup(self) -> None: """, ) +class SnowflakeTargetExistingReservedNameTableAlter(SnowflakeTargetExistingTable): + name = "existing_reserved_name_table_alter" + # This sends a schema that will request altering from TIMESTAMP_NTZ to VARCHAR + + def setup(self) -> None: + connector = self.target.default_sink_class.connector_class(self.target.config) + table = f'{self.target.config['database']}.{self.target.config['default_target_schema']}."ORDER"'.upper() + connector.connection.execute( + f""" + CREATE OR REPLACE TABLE {table} ( + ID VARCHAR(16777216), + COL_STR VARCHAR(16777216), + COL_TS TIMESTAMP_NTZ(9), + COL_INT STRING, + COL_BOOL BOOLEAN, + COL_VARIANT VARIANT, + _SDC_BATCHED_AT TIMESTAMP_NTZ(9), + _SDC_DELETED_AT VARCHAR(16777216), + _SDC_EXTRACTED_AT TIMESTAMP_NTZ(9), + _SDC_RECEIVED_AT TIMESTAMP_NTZ(9), + _SDC_SEQUENCE NUMBER(38,0), + _SDC_TABLE_VERSION NUMBER(38,0), + PRIMARY KEY (ID) + ) + """, + ) + class SnowflakeTargetTypeEdgeCasesTest(TargetFileTestTemplate): name = "type_edge_cases" @@ -539,6 +566,7 @@ def singer_filepath(self) -> Path: SnowflakeTargetColonsInColName, SnowflakeTargetExistingTable, SnowflakeTargetExistingTableAlter, + SnowflakeTargetExistingReservedNameTableAlter, SnowflakeTargetTypeEdgeCasesTest, SnowflakeTargetColumnOrderMismatch, ], diff --git a/tests/target_test_streams/existing_reserved_name_table_alter.singer b/tests/target_test_streams/existing_reserved_name_table_alter.singer new file mode 100644 index 0000000..a79e5d2 --- /dev/null +++ b/tests/target_test_streams/existing_reserved_name_table_alter.singer @@ -0,0 +1,2 @@ +{ "type": "SCHEMA", "stream": "ORDER", "schema": { "properties": { "id": { "type": [ "string", "null" ] }, "col_str": { "type": [ "string", "null" ] }, "col_ts": { "format": "date-time", "type": [ "string", "null" ] }, "col_int": { "type": "integer" }, "col_bool": { "type": [ "boolean", "null" ] }, "col_variant": {"type": "object"} }, "type": "object" }, "key_properties": [ "id" ], "bookmark_properties": [ "col_ts" ] } +{ "type": "RECORD", "stream": "ORDER", "record": { "id": "123", "col_str": "foo", "col_ts": "2023-06-13 11:50:04.072", "col_int": 5, "col_bool": true, "col_variant": {"key": "val"} }, "time_extracted": "2023-06-14T18:08:23.074716+00:00" }