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

Support last_update_time in nanoseconds #960

Merged
merged 1 commit into from
Mar 15, 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
18 changes: 12 additions & 6 deletions weaviate/collections/queries/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ def __init__(
validate_arguments=self._validate_arguments,
)

def __retrieve_timestamp(
self,
timestamp: int,
) -> datetime.datetime:
# Handle the case in which last_update_time_unix is in nanoseconds or milliseconds, issue #958
if len(str(timestamp)) <= 13:
return datetime.datetime.fromtimestamp(timestamp / 1000, tz=datetime.timezone.utc)
else:
return datetime.datetime.fromtimestamp(timestamp / 1e9, tz=datetime.timezone.utc)

def __extract_metadata_for_object(
self,
add_props: "search_get_pb2.MetadataResult",
Expand All @@ -102,16 +112,12 @@ def __extract_metadata_for_object(
distance=add_props.distance if add_props.distance_present else None,
certainty=add_props.certainty if add_props.certainty_present else None,
creation_time=(
datetime.datetime.fromtimestamp(
add_props.creation_time_unix / 1000, tz=datetime.timezone.utc
)
self.__retrieve_timestamp(add_props.creation_time_unix)
if add_props.creation_time_unix_present
else None
),
last_update_time=(
datetime.datetime.fromtimestamp(
add_props.last_update_time_unix / 1000, tz=datetime.timezone.utc
)
self.__retrieve_timestamp(add_props.last_update_time_unix)
if add_props.last_update_time_unix_present
else None
),
Expand Down