From 7924641d939cdf486f9c048f224a1ee6ddc5ee03 Mon Sep 17 00:00:00 2001 From: nidhi-akkio <132295233+nidhi-akkio@users.noreply.github.com> Date: Thu, 7 Dec 2023 10:57:52 -0800 Subject: [PATCH] fix: Emit date columns in the appropriate (not datetime-like) format (#34) For more context look at this bug thread: https://github.com/meltano/sdk/issues/1831 Co-authored-by: Nidhi Kakulawaram --- tap_snowflake/client.py | 21 +++++++++++++++++++++ tests/catalog.json | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tap_snowflake/client.py b/tap_snowflake/client.py index 977c8d6..3f693a3 100644 --- a/tap_snowflake/client.py +++ b/tap_snowflake/client.py @@ -11,14 +11,35 @@ from pathlib import Path from typing import Any, Iterable, List, Tuple from uuid import uuid4 +import datetime import sqlalchemy from singer_sdk import SQLConnector, SQLStream, metrics from singer_sdk.helpers._batch import BaseBatchFileEncoding, BatchConfig from singer_sdk.streams.core import REPLICATION_FULL_TABLE, REPLICATION_INCREMENTAL +import singer_sdk.helpers._typing from snowflake.sqlalchemy import URL from sqlalchemy.sql import text +unpatched_conform = singer_sdk.helpers._typing._conform_primitive_property + + +def patched_conform( + elem: Any, + property_schema: dict, +) -> Any: + """Overrides Singer SDK type conformance to prevent dates turning into datetimes. + Converts a primitive (i.e. not object or array) to a json compatible type. + Returns: + The appropriate json compatible type. + """ + if isinstance(elem, datetime.date): + return elem.isoformat() + return unpatched_conform(elem=elem, property_schema=property_schema) + + +singer_sdk.helpers._typing._conform_primitive_property = patched_conform + class ProfileStats(Enum): """Profile Statistics Enum.""" diff --git a/tests/catalog.json b/tests/catalog.json index c3f4c5f..62e5e69 100644 --- a/tests/catalog.json +++ b/tests/catalog.json @@ -378,7 +378,7 @@ "type": ["number"] }, "o_orderdate": { - "format": "date-time", + "format": "date", "type": ["string"] }, "o_orderpriority": {