Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use context manager to read gzip batch files #2628

Merged
merged 2 commits into from
Aug 26, 2024
Merged
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
20 changes: 11 additions & 9 deletions singer_sdk/sinks/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@

# SDK developer overrides:

def preprocess_record(self, record: dict, context: dict) -> dict: # noqa: ARG002, PLR6301
def preprocess_record(self, record: dict, context: dict) -> dict: # noqa: PLR6301, ARG002
"""Process incoming record and return a modified result.

Args:
Expand Down Expand Up @@ -743,12 +743,15 @@
tail,
mode="rb",
) as file:
context_file = (
gzip_open(file) if encoding.compression == "gzip" else file
)
context = {
"records": [deserialize_json(line) for line in context_file] # type: ignore[attr-defined]
}
if encoding.compression == "gzip":
with gzip_open(file) as context_file:
context = {
"records": [
deserialize_json(line) for line in context_file
]
}
else:
context = {"records": [deserialize_json(line) for line in file]}

Check warning on line 754 in singer_sdk/sinks/core.py

View check run for this annotation

Codecov / codecov/patch

singer_sdk/sinks/core.py#L754

Added line #L754 was not covered by tests
self.process_batch(context)
elif (
importlib.util.find_spec("pyarrow")
Expand All @@ -760,8 +763,7 @@
tail,
mode="rb",
) as file:
context_file = file
table = pq.read_table(context_file)
table = pq.read_table(file)
context = {"records": table.to_pylist()}
self.process_batch(context)
else:
Expand Down
Loading