Skip to content

Commit

Permalink
Merge branch 'main' into feature/support_headers_when_requesting_oaut…
Browse files Browse the repository at this point in the history
…h_token
  • Loading branch information
edgarrmondragon authored Jul 10, 2023
2 parents baec032 + 8fb30f3 commit 067a7e0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion poetry.lock

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

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ python-dotenv = ">=0.20,<0.22"
typing-extensions = "^4.2.0"
simplejson = "^3.17.6"
jsonschema = "^4.16.0"
packaging = ">=23.1"
pytz = ">=2022.2.1,<2024.0.0"
PyYAML = "^6.0"
# urllib3 2.0 is not compatible with botocore
Expand Down
3 changes: 2 additions & 1 deletion singer_sdk/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def get_batches(
mode="wb",
) as gz:
gz.writelines(
(json.dumps(record) + "\n").encode() for record in chunk
(json.dumps(record, default=str) + "\n").encode()
for record in chunk
)
file_url = fs.geturl(filename)
yield [file_url]
30 changes: 30 additions & 0 deletions tests/core/test_batch.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from __future__ import annotations

import decimal
import re
from dataclasses import asdict

import pytest

from singer_sdk.batch import JSONLinesBatcher
from singer_sdk.helpers._batch import (
BaseBatchFileEncoding,
BatchConfig,
JSONLinesEncoding,
StorageTarget,
)
Expand Down Expand Up @@ -95,3 +99,29 @@ def test_storage_from_url(file_url: str, root: str):
def test_storage_split_url(file_url: str, expected: tuple):
"""Test storage target split URL."""
assert StorageTarget.split_url(file_url) == expected


def test_json_lines_batcher():
batcher = JSONLinesBatcher(
"tap-test",
"stream-test",
batch_config=BatchConfig(
encoding=JSONLinesEncoding("gzip"),
storage=StorageTarget("file:///tmp/sdk-batches"),
batch_size=2,
),
)
records = [
{"id": 1, "numeric": decimal.Decimal("1.0")},
{"id": 2, "numeric": decimal.Decimal("2.0")},
{"id": 3, "numeric": decimal.Decimal("3.0")},
]

batches = list(batcher.get_batches(records))
assert len(batches) == 2
assert all(len(batch) == 1 for batch in batches)
assert all(
re.match(r".*tap-test--stream-test-.*\.json.gz", filepath)
for batch in batches
for filepath in batch
)

0 comments on commit 067a7e0

Please sign in to comment.