Skip to content

Commit

Permalink
test: Test with singer-sdk @ main
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Nov 28, 2024
1 parent 7e7d194 commit a01f769
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
31 changes: 17 additions & 14 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ sqlalchemy = "2.0.36"
sshtunnel = "0.4.0"

[tool.poetry.dependencies.singer-sdk]
version = "~=0.42.1"
extras = ["faker"]
git = "https://github.com/meltano/sdk.git"

[tool.poetry.group.dev.dependencies]
faker = ">=18.5.1"
Expand All @@ -56,7 +55,7 @@ types-jsonschema = ">=4.19.0.3"
types-psycopg2 = ">=2.9.21.20240118"

[tool.poetry.dev-dependencies.singer-sdk]
version = "*"
git = "https://github.com/meltano/sdk.git"
extras = ["testing"]

[tool.mypy]
Expand Down
26 changes: 21 additions & 5 deletions tap_postgres/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from collections.abc import Iterable, Mapping

from singer_sdk.helpers.types import Context
from sqlalchemy.dialects import postgresql
from sqlalchemy.engine import Engine
from sqlalchemy.engine.reflection import Inspector

Expand All @@ -44,7 +43,24 @@ def __init__(self, dates_as_string: bool, json_as_object: bool, *args, **kwargs)
self.dates_as_string = dates_as_string
self.json_as_object = json_as_object

@SQLToJSONSchema.to_jsonschema.register # type: ignore[attr-defined]
@classmethod
def from_config(cls, config: dict) -> PostgresSQLToJSONSchema:
"""Instantiate the SQL to JSON Schema converter from a config dictionary."""
SQLToJSONSchema.from_config(config)
return cls(
dates_as_string=config["dates_as_string"],
json_as_object=config["json_as_object"],
)

@functools.singledispatchmethod
def to_jsonschema(self, column_type: Any) -> dict:
"""Override the default mapping for NUMERIC columns.
For example, a scale of 4 translates to a multipleOf 0.0001.
"""
return super().to_jsonschema(column_type)

@to_jsonschema.register # type: ignore[attr-defined]
def array_to_jsonschema(self, column_type: postgresql.ARRAY) -> dict:
"""Override the default mapping for NUMERIC columns.
Expand All @@ -55,21 +71,21 @@ def array_to_jsonschema(self, column_type: postgresql.ARRAY) -> dict:
"items": self.to_jsonschema(column_type.item_type),
}

@SQLToJSONSchema.to_jsonschema.register # type: ignore[attr-defined]
@to_jsonschema.register # type: ignore[attr-defined]
def json_to_jsonschema(self, column_type: postgresql.JSON) -> dict:
"""Override the default mapping for JSON and JSONB columns."""
if self.json_as_object:
return {"type": ["object", "null"]}
return {"type": ["string", "number", "integer", "array", "object", "boolean"]}

@SQLToJSONSchema.to_jsonschema.register # type: ignore[attr-defined]
@to_jsonschema.register # type: ignore[attr-defined]
def datetime_to_jsonschema(self, column_type: sqlalchemy.types.DateTime) -> dict:
"""Override the default mapping for DATETIME columns."""
if self.dates_as_string:
return {"type": ["string", "null"]}
return super().datetime_to_jsonschema(column_type)

@SQLToJSONSchema.to_jsonschema.register # type: ignore[attr-defined]
@to_jsonschema.register # type: ignore[attr-defined]
def date_to_jsonschema(self, column_type: sqlalchemy.types.Date) -> dict:
"""Override the default mapping for DATE columns."""
if self.dates_as_string:
Expand Down

0 comments on commit a01f769

Please sign in to comment.