-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Model Deprecation #7562
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
Model Deprecation #7562
Changes from 2 commits
7cc1d74
55debbe
9ca7d37
fd88586
7842dca
37c8361
ccd73b0
8277e8c
0637591
d9a4cc2
ed443da
e64efb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| from copy import deepcopy | ||
| from dataclasses import dataclass | ||
| from dataclasses import field | ||
| from datetime import datetime | ||
| import datetime | ||
| import os | ||
| import traceback | ||
| from typing import ( | ||
|
|
@@ -22,6 +22,7 @@ | |
| from dbt.events.base_types import EventLevel | ||
| import json | ||
| import pprint | ||
| import msgpack | ||
|
|
||
| import dbt.exceptions | ||
| import dbt.tracking | ||
|
|
@@ -125,6 +126,36 @@ | |
| PERF_INFO_FILE_NAME = "perf_info.json" | ||
|
|
||
|
|
||
| def extended_mashumaro_encoder(data): | ||
| return msgpack.packb(data, default=extended_msgpack_encoder, use_bin_type=True) | ||
|
|
||
|
|
||
| def extended_msgpack_encoder(obj): | ||
| if type(obj) is datetime.date: | ||
| date_bytes = msgpack.ExtType(1, obj.isoformat().encode()) | ||
| return date_bytes | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The msgpack docs outline an alternative method to encoding custom types by returning something more like: {'__datetime__': True, 'as_str': obj.strftime("%Y%m%dT%H:%M:%S.%f")}It looks to be interchangeable with |
||
| elif type(obj) is datetime.datetime: | ||
| datetime_bytes = msgpack.ExtType(2, obj.isoformat().encode()) | ||
| return datetime_bytes | ||
|
|
||
| return obj | ||
|
|
||
|
|
||
| def extended_mashumuro_decoder(data): | ||
| return msgpack.unpackb(data, ext_hook=extended_msgpack_decoder, raw=False) | ||
|
|
||
|
|
||
| def extended_msgpack_decoder(code, data): | ||
| if code == 1: | ||
| d = datetime.date.fromisoformat(data.decode()) | ||
| return d | ||
| elif code == 2: | ||
| dt = datetime.datetiem.fromisoformat(data.decode()) | ||
peterallenwebb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return dt | ||
| else: | ||
| return msgpack.ExtType(code, data) | ||
|
|
||
|
|
||
| class ReparseReason(StrEnum): | ||
| version_mismatch = "01_version_mismatch" | ||
| file_not_found = "02_file_not_found" | ||
|
|
@@ -644,7 +675,7 @@ def write_manifest_for_partial_parse(self): | |
| UnableToPartialParse(reason="saved manifest contained the wrong version") | ||
| ) | ||
| self.manifest.metadata.dbt_version = __version__ | ||
| manifest_msgpack = self.manifest.to_msgpack() | ||
| manifest_msgpack = self.manifest.to_msgpack(extended_mashumaro_encoder) | ||
| make_directory(os.path.dirname(path)) | ||
| with open(path, "wb") as fp: | ||
| fp.write(manifest_msgpack) | ||
|
|
@@ -867,14 +898,14 @@ def read_manifest_for_partial_parse(self) -> Optional[Manifest]: | |
| try: | ||
| with open(path, "rb") as fp: | ||
| manifest_mp = fp.read() | ||
| manifest: Manifest = Manifest.from_msgpack(manifest_mp) # type: ignore | ||
| manifest: Manifest = Manifest.from_msgpack(manifest_mp, decoder=extended_mashumuro_decoder) # type: ignore | ||
| # keep this check inside the try/except in case something about | ||
| # the file has changed in weird ways, perhaps due to being a | ||
| # different version of dbt | ||
| is_partial_parsable, reparse_reason = self.is_partial_parsable(manifest) | ||
| if is_partial_parsable: | ||
| # We don't want to have stale generated_at dates | ||
| manifest.metadata.generated_at = datetime.utcnow() | ||
| manifest.metadata.generated_at = datetime.datetime.utcnow() | ||
peterallenwebb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # or invocation_ids | ||
| manifest.metadata.invocation_id = get_invocation_id() | ||
| return manifest | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| from __future__ import annotations | ||
| from typing import Any, Callable, Dict, List, Optional, Tuple | ||
| from msgpack.exceptions import ( | ||
| BufferFull, | ||
| ExtraData, | ||
| FormatError, | ||
| OutOfData, | ||
| PackException, | ||
| PackOverflowError, | ||
| PackValueError, | ||
| StackError, | ||
| UnpackException, | ||
| UnpackValueError, | ||
| ) | ||
| from typing_extensions import Protocol | ||
| from msgpack.fallback import Packer, Unpacker, unpackb | ||
| from msgpack import exceptions | ||
| from msgpack.ext import ExtType | ||
| from msgpack import ext | ||
|
|
||
| class _Stream(Protocol): | ||
| def read(self) -> bytes: ... | ||
|
|
||
| class _FileLike(Protocol): | ||
| def read(self, n: int) -> bytes: ... | ||
|
|
||
| def pack( | ||
| o: Any, | ||
| stream: _Stream, | ||
| default: Optional[Callable[[Any], Any]] = ..., | ||
| use_single_float: bool = ..., | ||
| autoreset: bool = ..., | ||
| use_bin_type: bool = ..., | ||
| strict_types: bool = ..., | ||
| datetime: bool = ..., | ||
| unicode_errors: Optional[str] = ..., | ||
| ) -> None: ... | ||
| def packb( | ||
| o: Any, | ||
| default: Optional[Callable[[Any], Any]] = ..., | ||
| use_single_float: bool = ..., | ||
| autoreset: bool = ..., | ||
| use_bin_type: bool = ..., | ||
| strict_types: bool = ..., | ||
| datetime: bool = ..., | ||
| unicode_errors: Optional[str] = ..., | ||
| ) -> bytes: ... | ||
| def unpack( | ||
| stream: _Stream, | ||
| file_like: Optional[_FileLike] = ..., | ||
| read_size: int = ..., | ||
| use_list: bool = ..., | ||
| raw: bool = ..., | ||
| timestamp: int = ..., | ||
| strict_map_key: bool = ..., | ||
| object_hook: Optional[Callable[[Dict[Any, Any]], Any]] = ..., | ||
| object_pairs_hook: Optional[Callable[[List[Tuple[Any, Any]]], Any]] = ..., | ||
| list_hook: Optional[Callable[[List[Any]], Any]] = ..., | ||
| unicode_errors: Optional[str] = ..., | ||
| max_buffer_size: int = ..., | ||
| ext_hook: Callable[[int, bytes], Any] = ..., | ||
| max_str_len: int = ..., | ||
| max_bin_len: int = ..., | ||
| max_array_len: int = ..., | ||
| max_map_len: int = ..., | ||
| max_ext_len: int = ..., | ||
| ) -> Any: ... | ||
|
|
||
| load = unpack | ||
| loads = unpackb | ||
|
|
||
| dump = pack | ||
| dumps = packb | ||
|
|
||
| __all__ = [ | ||
| "BufferFull", | ||
| "ExtType", | ||
| "ExtraData", | ||
| "FormatError", | ||
| "OutOfData", | ||
| "PackException", | ||
| "PackOverflowError", | ||
| "PackValueError", | ||
| "Packer", | ||
| "StackError", | ||
| "UnpackException", | ||
| "UnpackValueError", | ||
| "Unpacker", | ||
| "dump", | ||
| "dumps", | ||
| "exceptions", | ||
| "ext", | ||
| "load", | ||
| "loads", | ||
| "pack", | ||
| "packb", | ||
| "unpack", | ||
| "unpackb", | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from typing import Tuple | ||
|
|
||
| version: Tuple[int, int, int] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| from typing import Any | ||
|
|
||
| class UnpackException(Exception): ... | ||
| class BufferFull(UnpackException): ... | ||
| class OutOfData(UnpackException): ... | ||
| class FormatError(ValueError, UnpackException): ... | ||
| class StackError(ValueError, UnpackException): ... | ||
|
|
||
| UnpackValueError = ValueError | ||
|
|
||
| class ExtraData(UnpackValueError): | ||
| def __init__(self, unpacked: Any, exta: Any) -> None: ... | ||
|
|
||
| PackException = Exception | ||
| PackValueError = ValueError | ||
| PackOverflowError = OverflowError |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| from __future__ import annotations | ||
| from typing import NamedTuple | ||
| import datetime | ||
|
|
||
| class _ExtType(NamedTuple): | ||
| code: int | ||
| data: bytes | ||
|
|
||
| class ExtType(_ExtType): ... | ||
|
|
||
| class TimeStamp: | ||
| def __init__(self, seconds: int, nanoseconds: int = ...) -> None: ... | ||
| def __eq__(self, o: object) -> bool: ... | ||
| def __ne__(self, o: object) -> bool: ... | ||
| @staticmethod | ||
| def from_bytes(b: bytes) -> TimeStamp: ... | ||
| @staticmethod | ||
| def to_bytes(self) -> bytes: ... | ||
| @staticmethod | ||
| def from_unix(self, unix_sec: float) -> TimeStamp: ... | ||
| def to_unix(self) -> float: ... | ||
| @staticmethod | ||
| def from_unix_nano(unix_ns: int) -> TimeStamp: ... | ||
| @staticmethod | ||
| def to_unix_nano(self) -> int: ... | ||
| def to_datetime(self) -> datetime.datetime: ... | ||
| @staticmethod | ||
| def from_datetime(dt: datetime.datetime) -> TimeStamp: ... |
Uh oh!
There was an error while loading. Please reload this page.