Skip to content

Commit

Permalink
fix(targets): Quote add-column-ddl with column starting with _ (und…
Browse files Browse the repository at this point in the history
…erscore) based on engine (#2583)

* fix column quoting and add tests

* remove mypy ignore

---------

Co-authored-by: Edgar Ramírez Mondragón <16805946+edgarrmondragon@users.noreply.github.com>
  • Loading branch information
haleemur and edgarrmondragon authored Aug 5, 2024
1 parent 278fde4 commit 81d91f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion singer_sdk/connectors/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ def get_column_add_ddl(
column_type,
),
)
compiled = create_column_clause.compile(self._engine)
compiled = create_column_clause.compile(self._engine).string
return sa.DDL(
"ALTER TABLE %(table_name)s ADD COLUMN %(create_column_clause)s",
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{"type": "SCHEMA", "stream": "ForecastingTypeToCategory", "schema": {"properties": {"Id": {"type": "string"}, "IsDeleted": {"type": ["null", "boolean"]}, "CreatedDate": {"anyOf": [{"type": "string", "format": "date-time"}, {"type": ["string", "null"]}]}, "CreatedById": {"type": ["null", "string"]}, "LastModifiedDate": {"anyOf": [{"type": "string", "format": "date-time"}, {"type": ["string", "null"]}]}, "LastModifiedById": {"type": ["null", "string"]}, "SystemModstamp": {"anyOf": [{"type": "string", "format": "date-time"}, {"type": ["string", "null"]}]}, "ForecastingTypeId": {"type": ["null", "string"]}, "ForecastingItemCategory": {"type": ["null", "string"]}, "DisplayPosition": {"type": ["null", "integer"]}, "IsAdjustable": {"type": ["null", "boolean"]}, "IsOwnerAdjustable": {"type": ["null", "boolean"]}}, "type": "object", "additionalProperties": false}, "key_properties": ["Id"]}
{"type": "SCHEMA", "stream": "ForecastingTypeToCategory", "schema": {"properties": {"Id": {"type": "string"}, "IsDeleted": {"type": ["null", "boolean"]}, "CreatedDate": {"anyOf": [{"type": "string", "format": "date-time"}, {"type": ["string", "null"]}]}, "CreatedById": {"type": ["null", "string"]}, "LastModifiedDate": {"anyOf": [{"type": "string", "format": "date-time"}, {"type": ["string", "null"]}]}, "LastModifiedById": {"type": ["null", "string"]}, "SystemModstamp": {"anyOf": [{"type": "string", "format": "date-time"}, {"type": ["string", "null"]}]}, "ForecastingTypeId": {"type": ["null", "string"]}, "ForecastingItemCategory": {"type": ["null", "string"]}, "DisplayPosition": {"type": ["null", "integer"]}, "IsAdjustable": {"type": ["null", "boolean"]}, "IsOwnerAdjustable": {"type": ["null", "boolean"]}, "age": {"type": "integer"}, "NewCamelCasedAttribute": {"type": "string"}}, "type": "object", "additionalProperties": false}, "key_properties": ["Id"]}
{"type": "SCHEMA", "stream": "ForecastingTypeToCategory", "schema": {"properties": {"Id": {"type": "string"}, "IsDeleted": {"type": ["null", "boolean"]}, "CreatedDate": {"anyOf": [{"type": "string", "format": "date-time"}, {"type": ["string", "null"]}]}, "CreatedById": {"type": ["null", "string"]}, "LastModifiedDate": {"anyOf": [{"type": "string", "format": "date-time"}, {"type": ["string", "null"]}]}, "LastModifiedById": {"type": ["null", "string"]}, "SystemModstamp": {"anyOf": [{"type": "string", "format": "date-time"}, {"type": ["string", "null"]}]}, "ForecastingTypeId": {"type": ["null", "string"]}, "ForecastingItemCategory": {"type": ["null", "string"]}, "DisplayPosition": {"type": ["null", "integer"]}, "IsAdjustable": {"type": ["null", "boolean"]}, "IsOwnerAdjustable": {"type": ["null", "boolean"]}, "age": {"type": "integer"}, "NewCamelCasedAttribute": {"type": "string"}, "_attribute_startswith_underscore": {"type": "string"}}, "type": "object", "additionalProperties": false}, "key_properties": ["Id"]}
18 changes: 16 additions & 2 deletions tests/samples/test_target_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ def test_sqlite_column_addition(sqlite_sample_target: SQLTarget):
props_a: dict[str, dict] = {"col_a": th.StringType().to_dict()}
props_b = deepcopy(props_a)
props_b["col_b"] = th.IntegerType().to_dict()
schema_msg_a, schema_msg_b = (
props_c = deepcopy(props_b)
props_c["_col_c"] = th.IntegerType().to_dict()
schema_msg_a, schema_msg_b, schema_msg_c = (
{
"type": "SCHEMA",
"stream": test_tbl,
Expand All @@ -191,7 +193,7 @@ def test_sqlite_column_addition(sqlite_sample_target: SQLTarget):
"properties": props,
},
}
for props in [props_a, props_b]
for props in [props_a, props_b, props_c]
)
tap_output_a = "\n".join(
json.dumps(msg)
Expand All @@ -211,8 +213,20 @@ def test_sqlite_column_addition(sqlite_sample_target: SQLTarget):
},
]
)
tap_output_c = "\n".join(
json.dumps(msg)
for msg in [
schema_msg_c,
{
"type": "RECORD",
"stream": test_tbl,
"record": {"col_a": "samplerow2", "col_b": 2, "_col_c": 3},
},
]
)
target_sync_test(sqlite_sample_target, input=StringIO(tap_output_a), finalize=True)
target_sync_test(sqlite_sample_target, input=StringIO(tap_output_b), finalize=True)
target_sync_test(sqlite_sample_target, input=StringIO(tap_output_c), finalize=True)


def test_sqlite_activate_version(
Expand Down

0 comments on commit 81d91f3

Please sign in to comment.