@@ -23,7 +23,6 @@ use relative_path::RelativePathBuf;
23
23
24
24
use crate :: {
25
25
catalog:: manifest:: Manifest ,
26
- event:: DEFAULT_TIMESTAMP_KEY ,
27
26
query:: PartialTimeFilter ,
28
27
storage:: { ObjectStorage , ObjectStorageError } ,
29
28
} ;
@@ -70,46 +69,25 @@ impl ManifestFile for manifest::File {
70
69
}
71
70
}
72
71
73
- fn get_file_bounds (
74
- file : & manifest:: File ,
75
- partition_column : String ,
76
- ) -> ( DateTime < Utc > , DateTime < Utc > ) {
77
- if partition_column == DEFAULT_TIMESTAMP_KEY {
78
- match file
79
- . columns ( )
80
- . iter ( )
81
- . find ( |col| col. name == partition_column)
82
- . unwrap ( )
83
- . stats
84
- . as_ref ( )
85
- . unwrap ( )
86
- {
87
- column:: TypedStatistics :: Int ( stats) => (
88
- NaiveDateTime :: from_timestamp_millis ( stats. min )
89
- . unwrap ( )
90
- . and_utc ( ) ,
91
- NaiveDateTime :: from_timestamp_millis ( stats. max )
92
- . unwrap ( )
93
- . and_utc ( ) ,
94
- ) ,
95
- _ => unreachable ! ( ) ,
96
- }
97
- } else {
98
- match file
99
- . columns ( )
100
- . iter ( )
101
- . find ( |col| col. name == partition_column)
102
- . unwrap ( )
103
- . stats
104
- . as_ref ( )
105
- . unwrap ( )
106
- {
107
- column:: TypedStatistics :: String ( stats) => (
108
- stats. min . parse :: < DateTime < Utc > > ( ) . unwrap ( ) ,
109
- stats. max . parse :: < DateTime < Utc > > ( ) . unwrap ( ) ,
110
- ) ,
111
- _ => unreachable ! ( ) ,
112
- }
72
+ fn get_file_bounds ( file : & manifest:: File ) -> ( DateTime < Utc > , DateTime < Utc > ) {
73
+ match file
74
+ . columns ( )
75
+ . iter ( )
76
+ . find ( |col| col. name == "p_timestamp" )
77
+ . unwrap ( )
78
+ . stats
79
+ . clone ( )
80
+ . unwrap ( )
81
+ {
82
+ column:: TypedStatistics :: Int ( stats) => (
83
+ NaiveDateTime :: from_timestamp_millis ( stats. min )
84
+ . unwrap ( )
85
+ . and_utc ( ) ,
86
+ NaiveDateTime :: from_timestamp_millis ( stats. max )
87
+ . unwrap ( )
88
+ . and_utc ( ) ,
89
+ ) ,
90
+ _ => unreachable ! ( ) ,
113
91
}
114
92
}
115
93
@@ -121,17 +99,8 @@ pub async fn update_snapshot(
121
99
// get current snapshot
122
100
let mut meta = storage. get_object_store_format ( stream_name) . await ?;
123
101
let manifests = & mut meta. snapshot . manifest_list ;
124
- let time_partition = meta. time_partition ;
125
- let lower_bound = match time_partition {
126
- Some ( time_partition) => {
127
- let ( lower_bound, _) = get_file_bounds ( & change, time_partition) ;
128
- lower_bound
129
- }
130
- None => {
131
- let ( lower_bound, _) = get_file_bounds ( & change, DEFAULT_TIMESTAMP_KEY . to_string ( ) ) ;
132
- lower_bound
133
- }
134
- } ;
102
+
103
+ let ( lower_bound, _) = get_file_bounds ( & change) ;
135
104
let pos = manifests. iter ( ) . position ( |item| {
136
105
item. time_lower_bound <= lower_bound && lower_bound < item. time_upper_bound
137
106
} ) ;
@@ -140,18 +109,16 @@ pub async fn update_snapshot(
140
109
// This updates an existing file so there is no need to create a snapshot entry.
141
110
if let Some ( pos) = pos {
142
111
let info = & mut manifests[ pos] ;
143
- let manifest_path =
144
- partition_path ( stream_name, info. time_lower_bound , info. time_upper_bound ) ;
145
-
146
- let Some ( mut manifest) = storage. get_manifest ( & manifest_path) . await ? else {
112
+ let path = partition_path ( stream_name, info. time_lower_bound , info. time_upper_bound ) ;
113
+ let Some ( mut manifest) = storage. get_manifest ( & path) . await ? else {
147
114
return Err ( ObjectStorageError :: UnhandledError (
148
115
"Manifest found in snapshot but not in object-storage"
149
116
. to_string ( )
150
117
. into ( ) ,
151
118
) ) ;
152
119
} ;
153
120
manifest. apply_change ( change) ;
154
- storage. put_manifest ( & manifest_path , manifest) . await ?;
121
+ storage. put_manifest ( & path , manifest) . await ?;
155
122
} else {
156
123
let lower_bound = lower_bound. date_naive ( ) . and_time ( NaiveTime :: MIN ) . and_utc ( ) ;
157
124
let upper_bound = lower_bound
@@ -210,7 +177,6 @@ pub async fn get_first_event(
210
177
// get current snapshot
211
178
let mut meta = storage. get_object_store_format ( stream_name) . await ?;
212
179
let manifests = & mut meta. snapshot . manifest_list ;
213
- let time_partition = meta. time_partition ;
214
180
if manifests. is_empty ( ) {
215
181
log:: info!( "No manifest found for stream {stream_name}" ) ;
216
182
return Err ( ObjectStorageError :: Custom ( "No manifest found" . to_string ( ) ) ) ;
@@ -232,15 +198,9 @@ pub async fn get_first_event(
232
198
} ;
233
199
234
200
if let Some ( first_event) = manifest. files . first ( ) {
235
- if let Some ( time_partition) = time_partition {
236
- let ( lower_bound, _) = get_file_bounds ( first_event, time_partition) ;
237
- let first_event_at = lower_bound. with_timezone ( & Local ) . to_rfc3339 ( ) ;
238
- return Ok ( Some ( first_event_at) ) ;
239
- } else {
240
- let ( lower_bound, _) = get_file_bounds ( first_event, DEFAULT_TIMESTAMP_KEY . to_string ( ) ) ;
241
- let first_event_at = lower_bound. with_timezone ( & Local ) . to_rfc3339 ( ) ;
242
- return Ok ( Some ( first_event_at) ) ;
243
- }
201
+ let ( lower_bound, _) = get_file_bounds ( first_event) ;
202
+ let first_event_at = lower_bound. with_timezone ( & Local ) . to_rfc3339 ( ) ;
203
+ return Ok ( Some ( first_event_at) ) ;
244
204
}
245
205
Ok ( None )
246
206
}
0 commit comments