Skip to content

Commit b32deed

Browse files
committed
Fix redshift column comparison
1 parent 7c154fe commit b32deed

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

target_sql/target_redshift.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def __init__(self, config, *args, **kwargs):
1616

1717
super(TargetRedshift, self).__init__(config, *args, **kwargs)
1818

19+
def compare_column_names(self, col_a, col_b):
20+
# redshift lowercases column names
21+
return col_a.lower() == col_b.lower()
22+
1923
def sql_to_json_schema(self, sql_type, nullable):
2024
_format = None
2125
if sql_type == 'timestamp with time zone':

target_sql/target_sql.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,9 @@ def get_sql_datetime(self, *args):
633633
parsed_datetime = arrow.get() # defaults to UTC now
634634
return parsed_datetime.format('YYYY-MM-DD HH:mm:ss.SSSSZZ')
635635

636+
def compare_column_names(self, col_a, col_b):
637+
return col_a == col_b
638+
636639
def create_table(self, cur, table_schema, table_name, schema, key_properties, table_version):
637640
create_table_sql = sql.SQL('CREATE TABLE {}.{}').format(
638641
sql.Identifier(table_schema),
@@ -752,7 +755,13 @@ def merge_put_schemas(self, cur, table_schema, table_name, existing_schema, new_
752755
new_properties = new_schema['properties']
753756
existing_properties = existing_schema['properties']
754757
for prop, json_schema in new_properties.items():
755-
if prop not in existing_properties:
758+
prop_exists = False
759+
for existing_prop in existing_properties:
760+
if self.compare_column_names(prop, existing_prop):
761+
prop_exists = True
762+
break
763+
764+
if not prop_exists:
756765
existing_properties[prop] = new_properties[prop]
757766
data_type = self.json_schema_to_sql(new_properties[prop])
758767
default_value = self.get_null_default(prop, new_properties[prop])

0 commit comments

Comments
 (0)