Skip to content

Commit

Permalink
Set datetime, date, time and timestamp columns to Nullable to avoid N…
Browse files Browse the repository at this point in the history
…ULL cast to epoch (#142)

* Fix lint

* Fix lint
  • Loading branch information
BTheunissen authored Mar 17, 2024
1 parent 887eb86 commit 148f563
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "shaped-target-clickhouse"
version = "0.2.3"
version = "0.2.4"
description = "`target-clickhouse` is a Singer target for clickhouse, built with the Meltano Singer SDK."
readme = "README.md"
authors = ["Ben Theunissen"]
Expand Down
8 changes: 8 additions & 0 deletions target_clickhouse/connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ def to_sql_type(self, jsonschema_type: dict) -> sqlalchemy.types.TypeEngine:
sql_type = typing.cast(
sqlalchemy.types.TypeEngine, clickhouse_sqlalchemy_types.Int64(),
)
# All date and time types should be flagged as Nullable to allow for NULL value.
elif type(sql_type) in [
sqlalchemy.types.DATE,
sqlalchemy.types.TIMESTAMP,
sqlalchemy.types.TIME,
sqlalchemy.types.DATETIME,
]:
sql_type = clickhouse_sqlalchemy_types.Nullable(sql_type)

return sql_type

Expand Down
7 changes: 6 additions & 1 deletion tests/target_test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
logger = logging.getLogger(__name__)

class TestDateTypeTargetClickhouse(TargetClickhouseFileTestTemplate):
"""Test date type can be ingested into Clickhouse."""
"""Test date type, and null date type can be ingested into Clickhouse."""

name = "date_type"

Expand All @@ -30,6 +30,11 @@ def validate(self) -> None:
record for record in result if record[0] == record_id_2
]))
assert record_2[1] == datetime.date(2024, 3, 16)
record_id_3 = 3
record_3 = next(iter([
record for record in result if record[0] == record_id_3
]))
assert record_3[1] is None

custom_target_test_suite = TestSuite(
kind="target",
Expand Down

0 comments on commit 148f563

Please sign in to comment.