Skip to content

Commit

Permalink
test: Test the case where no handler for the x-sql-datatype is available
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Jan 15, 2025
1 parent 70a395e commit bddbfe4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion singer_sdk/connectors/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,16 @@ def _get_type_from_schema(self, schema: dict) -> sa.types.TypeEngine | None:
SQL type if one can be determined, None otherwise.
"""
# Check x-sql-datatype first
if x_sql_datatype := schema.get("x-sql-datatype"): # noqa: SIM102
if x_sql_datatype := schema.get("x-sql-datatype"):
if handler := self._sql_datatype_mapping.get(x_sql_datatype):
return self._invoke_handler(handler, schema)

warnings.warn(
f"This target does not support the x-sql-datatype '{x_sql_datatype}'",
UserWarning,
stacklevel=2,
)

# Check if this is a string with format then
if schema.get("type") == "string" and "format" in schema: # noqa: SIM102
if (format_type := self._handle_format(schema)) is not None:
Expand Down
9 changes: 9 additions & 0 deletions tests/core/test_connector_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,15 @@ def test_annotation_sql_datatype(self):
result = json_schema_to_sql.to_sql_type(jsonschema_type)
assert isinstance(result, sa.types.JSON)

unknown_type = {"type": ["string"], "x-sql-datatype": "unknown"}
with pytest.warns(
UserWarning,
match="This target does not support the x-sql-datatype",
):
result = json_schema_to_sql.to_sql_type(unknown_type)

assert isinstance(result, sa.types.VARCHAR)


def test_bench_discovery(benchmark, tmp_path: Path):
def _discover_catalog(connector):
Expand Down

0 comments on commit bddbfe4

Please sign in to comment.