Skip to content
Open
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
15 changes: 14 additions & 1 deletion target_gcs/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from io import FileIO
from typing import Optional

import decimal

import orjson
import smart_open
from google.cloud.storage import Client
Expand Down Expand Up @@ -82,5 +84,16 @@ def process_record(self, record: dict, context: dict) -> None:
passed `context` dict from the current batch.
"""
self.gcs_write_handle.write(
orjson.dumps(record, option=orjson.OPT_APPEND_NEWLINE)
orjson.dumps(
record,
option=orjson.OPT_APPEND_NEWLINE,
default=_default_serializer,
)
)


def _default_serializer(obj):
"""Handle types that orjson cannot serialize natively."""
if isinstance(obj, decimal.Decimal):
return float(obj)
raise TypeError(f"Type is not JSON serializable: {type(obj)}")