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

test: Test with singer-sdk @ main #236

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
30 changes: 17 additions & 13 deletions poetry.lock

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

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

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

[tool.poetry.group.dev.dependencies]
Expand All @@ -57,7 +57,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
22 changes: 12 additions & 10 deletions tap_postgres/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,20 @@
class PostgresSQLToJSONSchema(SQLToJSONSchema):
"""Custom SQL to JSON Schema conversion for Postgres."""

def __init__(self, dates_as_string: bool, json_as_object: bool, *args, **kwargs):
def __init__(self, *, dates_as_string: bool, json_as_object: bool, **kwargs):
"""Initialize the SQL to JSON Schema converter."""
super().__init__(*args, **kwargs)
super().__init__(**kwargs)
self.dates_as_string = dates_as_string
self.json_as_object = json_as_object

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

@functools.singledispatchmethod
def to_jsonschema(self, column_type: t.Any) -> dict:
"""Customize the JSON Schema for Postgres types."""
Expand Down Expand Up @@ -132,6 +140,8 @@ def patched_conform(elem: t.Any, property_schema: dict) -> t.Any:
class PostgresConnector(SQLConnector):
"""Connects to the Postgres SQL source."""

sql_to_jsonschema_converter = PostgresSQLToJSONSchema

def __init__(
self,
config: dict | None = None,
Expand Down Expand Up @@ -160,14 +170,6 @@ def __init__(

super().__init__(config=config, sqlalchemy_url=sqlalchemy_url)

@functools.cached_property
def sql_to_jsonschema(self):
"""Return a mapping of SQL types to JSON Schema types."""
return PostgresSQLToJSONSchema(
dates_as_string=self.config["dates_as_string"],
json_as_object=self.config["json_as_object"],
)

def get_schema_names(self, engine: Engine, inspected: Inspector) -> list[str]:
"""Return a list of schema names in DB, or overrides with user-provided values.

Expand Down
11 changes: 10 additions & 1 deletion tap_postgres/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class TapPostgres(SQLTap):
name = "tap-postgres"
default_stream_class = PostgresStream

exclude_schemas = (
"information_schema",
"pg_catalog",
)

def __init__(
self,
*args,
Expand Down Expand Up @@ -547,7 +552,11 @@ def catalog_dict(self) -> dict:
return self.input_catalog.to_dict()

result: dict[str, list[dict]] = {"streams": []}
result["streams"].extend(self.connector.discover_catalog_entries())
result["streams"].extend(
self.connector.discover_catalog_entries(
exclude_schemas=self.exclude_schemas,
)
)

self._catalog_dict: dict = result
return self._catalog_dict
Expand Down
Loading