Skip to content

Commit

Permalink
fix: Emit date columns in the appropriate (not datetime-like) format (#…
Browse files Browse the repository at this point in the history
…34)

For more context look at this bug thread:
meltano/sdk#1831

Co-authored-by: Nidhi Kakulawaram <nidhikakulawaram@Nidhis-MacBook-Pro.local>
  • Loading branch information
nidhi-akkio and Nidhi Kakulawaram authored Dec 7, 2023
1 parent 59287ca commit 7924641
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions tap_snowflake/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion tests/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@
"type": ["number"]
},
"o_orderdate": {
"format": "date-time",
"format": "date",
"type": ["string"]
},
"o_orderpriority": {
Expand Down

0 comments on commit 7924641

Please sign in to comment.