Skip to content

Commit

Permalink
fix conform name logic (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
keyn4 authored Sep 18, 2024
1 parent dd198ea commit e6c930c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion target_mssql/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import sqlalchemy
from singer_sdk.sinks import SQLSink
from sqlalchemy import Column
import re
from singer_sdk.helpers._conformers import replace_leading_digit, snakecase

from target_mssql.connector import mssqlConnector

Expand Down Expand Up @@ -70,8 +72,9 @@ def preprocess_record(self, record: dict, context: dict) -> dict:
def check_string_key_properties(self):
isnumeric = True
if self.key_properties:
schema = self.conform_schema(self.schema)
for prop in self.key_properties:
isnumeric = ("string" not in self.schema['properties'][prop]['type']) and isnumeric
isnumeric = ("string" not in schema['properties'][prop]['type']) and isnumeric

return self.key_properties and isnumeric

Expand Down Expand Up @@ -266,3 +269,20 @@ def merge_upsert_from_table(
self.connection.execute(f"SET IDENTITY_INSERT { to_table_name } OFF")

self.connection.execute("COMMIT")

def conform_name(self, name: str, object_type: Optional[str] = None) -> str:
"""Conform a stream property name to one suitable for the target system.
Transforms names to snake case, applicable to most common DBMSs'.
Developers may override this method to apply custom transformations
to database/schema/table/column names.
"""
# strip non-alphanumeric characters, keeping - . _ and spaces
name = re.sub(r"[^a-zA-Z0-9_\-\.\s]", "", name)
# convert to snakecase
if name.isupper():
name = name.lower()
else:
name = snakecase(name)
# replace leading digit
return replace_leading_digit(name)

0 comments on commit e6c930c

Please sign in to comment.