Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove SQLSink snakecase conform in favor of simpler transformations #1342

Merged
merged 3 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions singer_sdk/sinks/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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("-", "_")
kgpayne marked this conversation as resolved.
Show resolved Hide resolved
.replace(" ", "_")
)
# replace leading digit
return replace_leading_digit(name)

Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_",
}