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 4f4b9c7 commit dcd7ec4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
28 changes: 17 additions & 11 deletions poetry.lock

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

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ sqlalchemy = "~=2.0"
sshtunnel = "0.4.0"

[tool.poetry.dependencies.singer-sdk]
version = "~=0.42.0b1"
git = "https://github.com/meltano/sdk.git"
branch = "edgarrmondragon/refactor/jsonschematosql-fromconfig"

[tool.poetry.extras]
faker = ["faker"]
Expand Down
24 changes: 11 additions & 13 deletions target_postgres/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def __init__(self, *, content_encoding: bool = True) -> None:
super().__init__()
self.content_encoding = content_encoding

@classmethod
def from_config(
cls: type[JSONSchemaToPostgres],
config: dict,
) -> JSONSchemaToPostgres:
"""Create a JSONSchemaToPostgres instance from a configuration."""
return cls(content_encoding=config.get("interpret_content_encoding", False))

def handle_raw_string(self, schema):
"""Handle a raw string type."""
if self.content_encoding and schema.get("contentEncoding") == "base16":
Expand All @@ -63,6 +71,8 @@ class PostgresConnector(SQLConnector):
allow_merge_upsert: bool = True # Whether MERGE UPSERT is supported.
allow_temp_tables: bool = True # Whether temp tables are supported.

jsonschema_to_sql_converter = JSONSchemaToPostgres

def __init__(self, config: dict) -> None:
"""Initialize a connector to a Postgres database.
Expand Down Expand Up @@ -100,18 +110,6 @@ def __init__(self, config: dict) -> None:
sqlalchemy_url=url.render_as_string(hide_password=False),
)

@cached_property
def interpret_content_encoding(self) -> bool:
"""Whether to interpret schema contentEncoding to set the column type.
It is an opt-in feature because it might result in data loss if the
actual data does not match the schema's advertised encoding.
Returns:
True if the feature is enabled, False otherwise.
"""
return self.config.get("interpret_content_encoding", False)

def prepare_table( # type: ignore[override] # noqa: PLR0913
self,
full_table_name: str | FullyQualifiedName,
Expand Down Expand Up @@ -258,7 +256,7 @@ def _handle_array_type(self, jsonschema: dict) -> ARRAY | JSONB:
@cached_property
def jsonschema_to_sql(self) -> JSONSchemaToSQL:
"""Return a JSONSchemaToSQL instance with custom type handling."""
to_sql = JSONSchemaToPostgres(content_encoding=self.interpret_content_encoding)
to_sql = JSONSchemaToPostgres.from_config(self.config)
to_sql.fallback_type = TEXT
to_sql.register_type_handler("integer", BIGINT)
to_sql.register_type_handler("object", JSONB)
Expand Down

0 comments on commit dcd7ec4

Please sign in to comment.