-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: replace plaintext formatter with jsonl
- Loading branch information
Showing
4 changed files
with
37 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from datetime import datetime | ||
|
||
from bson import ObjectId | ||
from simplejson import JSONEncoder, dumps | ||
|
||
from target_s3.formats.format_base import FormatBase | ||
|
||
|
||
class JsonSerialize(JSONEncoder): | ||
def default(self, obj: any) -> any: | ||
if isinstance(obj, ObjectId): | ||
return str(obj) | ||
if isinstance(obj, datetime): | ||
return obj.isoformat() | ||
else: | ||
raise TypeError(f"Type {type(obj)} not serializable") | ||
|
||
|
||
class FormatJsonl(FormatBase): | ||
def __init__(self, config, context) -> None: | ||
super().__init__(config, context, "jsonl") | ||
pass | ||
|
||
def _prepare_records(self): | ||
# use default behavior, no additional prep needed | ||
return super()._prepare_records() | ||
|
||
def _write(self) -> None: | ||
return super()._write('\n'.join(map(dumps, self.records))) | ||
|
||
def run(self) -> None: | ||
# use default behavior, no additional run steps needed | ||
return super().run(self.context["records"]) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters