From d5b2b8b1672acc152174c288d7ab1814eac3aac5 Mon Sep 17 00:00:00 2001 From: Ken Payne Date: Tue, 24 Jan 2023 13:19:16 +0000 Subject: [PATCH] remove snakecase in favour of simpler transformations --- singer_sdk/sinks/sql.py | 16 ++++++++++++---- tests/core/test_sqlite.py | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/singer_sdk/sinks/sql.py b/singer_sdk/sinks/sql.py index 1b991c7f0..e4cdc6571 100644 --- a/singer_sdk/sinks/sql.py +++ b/singer_sdk/sinks/sql.py @@ -13,7 +13,7 @@ from singer_sdk.connectors import SQLConnector from singer_sdk.exceptions import ConformedNameClashException -from singer_sdk.helpers._conformers import replace_leading_digit, snakecase +from singer_sdk.helpers._conformers import replace_leading_digit from singer_sdk.plugin_base import PluginBase from singer_sdk.sinks.batch import BatchSink @@ -150,10 +150,18 @@ def conform_name(self, name: str, object_type: Optional[str] = None) -> str: Returns: The name transformed to snake case. """ - # strip non-alphanumeric characters, keeping - . _ and spaces + # strip non-alphanumeric characters name = re.sub(r"[^a-zA-Z0-9_\-\.\s]", "", name) - # convert to snakecase - name = snakecase(name) + # strip leading/trailing whitespace, + # transform to lowercase and replace - . and spaces to _ + name = ( + name.lower() + .lstrip() + .rstrip() + .replace(".", "_") + .replace("-", "_") + .replace(" ", "_") + ) # replace leading digit return replace_leading_digit(name) diff --git a/tests/core/test_sqlite.py b/tests/core/test_sqlite.py index 8c714dfcd..d1529fa92 100644 --- a/tests/core/test_sqlite.py +++ b/tests/core/test_sqlite.py @@ -600,11 +600,11 @@ def test_hostile_to_sqlite( columns = {res[0] for res in cursor.fetchall()} assert columns == { "name_with_spaces", - "name_is_camel_case", + "nameiscamelcase", "name_with_dashes", "name_with_dashes_and_mixed_cases", "gname_starts_with_number", "fname_starts_with_number", "hname_starts_with_number", - "name_with_emoji", + "name_with_emoji_", }