Skip to content

Commit 4945757

Browse files
authored
Fix granularity subtraction (#41)
This PR fixes time subtraction when adjusting for OBJECT_STORE_DATA_GRANULARITY. By letting chrono subtract minutes from StorageSync time we can ensure right date and time for file URI Fixes #40
1 parent 97c6ad6 commit 4945757

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

server/src/storage.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::utils;
2424

2525
use async_trait::async_trait;
2626
use bytes::Bytes;
27-
use chrono::{Timelike, Utc};
27+
use chrono::{Duration, Timelike, Utc};
2828
use datafusion::arrow::record_batch::RecordBatch;
2929
use serde::Serialize;
3030

@@ -198,12 +198,13 @@ impl StorageSync {
198198
let _storage_path = format!("{}/", CONFIG.storage.bucket_name());
199199
let stream_name = self.path.replace(&local_path, "");
200200
let parquet_path = format!("{}/data.parquet", self.path);
201-
let uri = utils::date_to_prefix(self.time.date())
202-
+ &utils::hour_to_prefix(self.time.hour())
203-
// subtract OBJECT_STORE_DATA_GRANULARITY from current time here,
204-
// this is because, when we're creating this file
205-
// the data in the file is from OBJECT_STORE_DATA_GRANULARITY time ago.
206-
+ &utils::minute_to_prefix(self.time.minute()-OBJECT_STORE_DATA_GRANULARITY, OBJECT_STORE_DATA_GRANULARITY).unwrap();
201+
// subtract OBJECT_STORE_DATA_GRANULARITY from current time here,
202+
// this is because, when we're creating this file
203+
// the data in the file is from OBJECT_STORE_DATA_GRANULARITY time ago.
204+
let time = self.time - Duration::minutes(OBJECT_STORE_DATA_GRANULARITY as i64);
205+
let uri = utils::date_to_prefix(time.date())
206+
+ &utils::hour_to_prefix(time.hour())
207+
+ &utils::minute_to_prefix(time.minute(), OBJECT_STORE_DATA_GRANULARITY).unwrap();
207208

208209
let local_uri = str::replace(&uri, "/", ".");
209210

0 commit comments

Comments
 (0)