Skip to content

Commit 0a47738

Browse files
authored
Update redis.py
sub-second precision when returning timestamps to client
1 parent 13c751c commit 0a47738

File tree

1 file changed

+5
-5
lines changed
  • sdk/python/feast/infra/online_stores

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,21 +306,19 @@ def online_write_batch(
306306
):
307307
# Convert incoming timestamp to millisecond-aware datetime
308308
aware_ts = utils.make_tzaware(timestamp)
309-
309+
310310
# Build protobuf timestamp with nanos
311311
ts = Timestamp()
312312
ts.FromDatetime(aware_ts)
313-
313+
314314
# New timestamp in nanoseconds
315315
new_total_nanos = ts.seconds * 1_000_000_000 + ts.nanos
316316

317317
# Compare against existing timestamp (nanosecond precision)
318318
if prev_event_time:
319319
prev_ts = Timestamp()
320320
prev_ts.ParseFromString(prev_event_time)
321-
322321
prev_total_nanos = prev_ts.seconds * 1_000_000_000 + prev_ts.nanos
323-
324322
# Skip only if older OR exact same instant
325323
if prev_total_nanos and new_total_nanos <= prev_total_nanos:
326324
if progress:
@@ -465,5 +463,7 @@ def _get_features_for_entity(
465463
if not res:
466464
return None, None
467465
else:
468-
timestamp = datetime.fromtimestamp(res_ts.seconds, tz=timezone.utc)
466+
# reconstruct full timestamp including nanos
467+
total_seconds = res_ts.seconds + res_ts.nanos / 1_000_000_000.0
468+
timestamp = datetime.fromtimestamp(total_seconds, tz=timezone.utc)
469469
return timestamp, res

0 commit comments

Comments
 (0)