Skip to content

Commit ddbf1e5

Browse files
committed
naive WIP
1 parent f166f83 commit ddbf1e5

File tree

82 files changed

+3182
-1668
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+3182
-1668
lines changed

.github/workflows/test_common.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
python-version: "3.9"
3232
shell: bash
3333
- os: ubuntu-latest
34-
python-version: "3.11"
34+
python-version: "3.10"
3535
shell: bash
3636
- os: ubuntu-latest
3737
python-version: "3.11"

dlt/common/data_types/type_helpers.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@
33
import dataclasses
44
import datetime # noqa: I251
55
from collections.abc import Mapping as C_Mapping, Sequence as C_Sequence
6+
from functools import lru_cache
67
from typing import Any, Type, Union
78
from enum import Enum
89

910
from dlt.common.json import custom_pua_remove, json
1011
from dlt.common.json._simplejson import custom_encode as json_custom_encode
12+
from dlt.common.typing import copy_sig
1113
from dlt.common.wei import Wei
1214
from dlt.common.arithmetics import InvalidOperation, Decimal
1315
from dlt.common.data_types.typing import TDataType
1416
from dlt.common.time import (
15-
ensure_pendulum_datetime,
17+
ensure_pendulum_datetime_non_utc,
1618
ensure_pendulum_date,
1719
ensure_pendulum_time,
1820
)
1921
from dlt.common.utils import map_nested_in_place, str2bool
2022

2123

22-
def py_type_to_sc_type(t: Type[Any]) -> TDataType:
24+
def _py_type_to_sc_type(t: Type[Any]) -> TDataType:
2325
# start with most popular types
2426
if t is str:
2527
return "text"
@@ -68,14 +70,18 @@ def py_type_to_sc_type(t: Type[Any]) -> TDataType:
6870
raise TypeError(t)
6971

7072

73+
# preserves original signature which lru_cache destroys
74+
py_type_to_sc_type = copy_sig(_py_type_to_sc_type)(lru_cache(maxsize=None)(_py_type_to_sc_type))
75+
76+
7177
def json_to_str(value: Any) -> str:
7278
return json.dumps(map_nested_in_place(custom_pua_remove, value))
7379

7480

7581
def coerce_from_date_types(
7682
to_type: TDataType, value: datetime.datetime
7783
) -> Union[datetime.datetime, datetime.date, datetime.time, int, float, str]:
78-
v = ensure_pendulum_datetime(value)
84+
v = ensure_pendulum_datetime_non_utc(value)
7985
if to_type == "timestamp":
8086
return v
8187
if to_type == "text":
@@ -179,7 +185,7 @@ def coerce_value(to_type: TDataType, from_type: TDataType, value: Any) -> Any:
179185

180186
try:
181187
if to_type == "timestamp":
182-
return ensure_pendulum_datetime(value)
188+
return ensure_pendulum_datetime_non_utc(value)
183189

184190
if to_type == "date":
185191
return ensure_pendulum_date(value)

dlt/common/destination/capabilities.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ class DestinationCapabilitiesContext(ContainerInjectableContext):
172172
supports_truncate_command: bool = True
173173
schema_supports_numeric_precision: bool = True
174174
timestamp_precision: int = 6
175+
"""Default precision of the timestamp type"""
176+
175177
max_rows_per_insert: Optional[int] = None
176178
insert_values_writer_type: str = "default"
177179
supports_multiple_statements: bool = True
@@ -209,6 +211,9 @@ class DestinationCapabilitiesContext(ContainerInjectableContext):
209211
parquet_format: Optional[ParquetFormatConfiguration] = None
210212
"""Parquet format preferred by this destination"""
211213

214+
supports_naive_datetime: bool = True
215+
"""The destination can store datetime without timezone"""
216+
212217
def generates_case_sensitive_identifiers(self) -> bool:
213218
"""Tells if capabilities as currently adjusted, will generate case sensitive identifiers"""
214219
# must have case sensitive support and folding function must preserve casing

dlt/common/pendulum.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
from datetime import timedelta, timezone # noqa: I251
22
import pendulum # noqa: I251
33

4-
# force UTC as the local timezone to prevent local dates to be written to dbs
5-
pendulum.set_local_timezone(pendulum.timezone("UTC"))
6-
74

85
def __utcnow() -> pendulum.DateTime:
96
"""

dlt/common/pipeline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
)
5353
from dlt.common.storages.load_package import ParsedLoadJobFileName
5454
from dlt.common.storages.load_storage import LoadPackageInfo
55-
from dlt.common.time import ensure_pendulum_datetime, precise_time
55+
from dlt.common.time import ensure_pendulum_datetime_utc, precise_time
5656
from dlt.common.typing import DictStrAny, StrAny, SupportsHumanize, TColumnNames
5757
from dlt.common.data_writers.writers import TLoaderFileFormat
5858
from dlt.common.utils import RowCounts, merge_row_counts
@@ -413,8 +413,8 @@ def _step_info_complete_load_id(self, load_id: str, metrics: TStepMetrics) -> No
413413
f"Current load id mismatch {self._current_load_id} != {load_id} when completing step"
414414
" info"
415415
)
416-
metrics["started_at"] = ensure_pendulum_datetime(self._current_load_started)
417-
metrics["finished_at"] = ensure_pendulum_datetime(precise_time())
416+
metrics["started_at"] = ensure_pendulum_datetime_utc(self._current_load_started)
417+
metrics["finished_at"] = ensure_pendulum_datetime_utc(precise_time())
418418
self._load_id_metrics[load_id].append(metrics)
419419
self._current_load_id = None
420420
self._current_load_started = None

0 commit comments

Comments
 (0)