Skip to content

Commit e198b17

Browse files
authored
fix: Add adapters for sqlite datetime conversion (#4797)
* fix: sqlite adapter deprecation warning Signed-off-by: Matt Green <emgeee@users.noreply.github.com> * fix: remove duplicate folder definition in ruff config Signed-off-by: Matt Green <emgeee@users.noreply.github.com> * update minimum ruff version and format files Signed-off-by: Matt Green <emgeee@users.noreply.github.com> --------- Signed-off-by: Matt Green <emgeee@users.noreply.github.com>
1 parent f09339e commit e198b17

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

sdk/python/feast/infra/online_stores/sqlite.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import sqlite3
1818
import struct
1919
import sys
20-
from datetime import datetime
20+
from datetime import date, datetime
2121
from pathlib import Path
2222
from typing import Any, Callable, Dict, List, Literal, Optional, Sequence, Tuple, Union
2323

@@ -39,6 +39,46 @@
3939
from feast.utils import _build_retrieve_online_document_record, to_naive_utc
4040

4141

42+
def adapt_date_iso(val: date):
43+
"""Adapt datetime.date to ISO 8601 date."""
44+
return val.isoformat()
45+
46+
47+
def adapt_datetime_iso(val: datetime):
48+
"""Adapt datetime.datetime to timezone-naive ISO 8601 date."""
49+
return val.isoformat()
50+
51+
52+
def adapt_datetime_epoch(val: datetime):
53+
"""Adapt datetime.datetime to Unix timestamp."""
54+
return int(val.timestamp())
55+
56+
57+
sqlite3.register_adapter(date, adapt_date_iso)
58+
sqlite3.register_adapter(datetime, adapt_datetime_iso)
59+
sqlite3.register_adapter(datetime, adapt_datetime_epoch)
60+
61+
62+
def convert_date(val: bytes):
63+
"""Convert ISO 8601 date to datetime.date object."""
64+
return date.fromisoformat(val.decode())
65+
66+
67+
def convert_datetime(val: bytes):
68+
"""Convert ISO 8601 datetime to datetime.datetime object."""
69+
return datetime.fromisoformat(val.decode())
70+
71+
72+
def convert_timestamp(val: bytes):
73+
"""Convert Unix epoch timestamp to datetime.datetime object."""
74+
return datetime.fromtimestamp(int(val))
75+
76+
77+
sqlite3.register_converter("date", convert_date)
78+
sqlite3.register_converter("datetime", convert_datetime)
79+
sqlite3.register_converter("timestamp", convert_timestamp)
80+
81+
4282
class SqliteOnlineStoreConfig(FeastConfigBaseModel, VectorStoreConfig):
4383
"""Online store config for local (SQLite-based) store"""
4484

sdk/python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ select = ["E","F","W","I"]
66
ignore = ["E203", "E266", "E501", "E721"]
77

88
[tool.ruff.lint.isort]
9-
known-first-party = ["feast", "feast", "feast_serving_server", "feast_core_server"]
9+
known-first-party = ["feast", "feast_serving_server", "feast_core_server"]
1010
default-section = "third-party"
1111

1212
[tool.mypy]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
"build",
156156
"virtualenv==20.23.0",
157157
"cryptography>=35.0,<43",
158-
"ruff>=0.3.3",
158+
"ruff>=0.8.0",
159159
"mypy-protobuf>=3.1",
160160
"grpcio-tools>=1.56.2,<2",
161161
"grpcio-testing>=1.56.2,<2",

0 commit comments

Comments
 (0)