@@ -175,74 +175,58 @@ pub(crate) fn stats_min_value_to_pg_str(
175175
176176 let converted_type = column_descriptor. converted_type ( ) ;
177177
178- let is_string = matches ! ( logical_type, Some ( LogicalType :: String ) )
179- || matches ! ( converted_type, ConvertedType :: UTF8 ) ;
180-
181- let is_json = matches ! ( logical_type, Some ( LogicalType :: Json ) )
182- || matches ! ( converted_type, ConvertedType :: JSON ) ;
183-
184- let is_uuid = matches ! ( logical_type, Some ( LogicalType :: Uuid ) ) ;
185-
186- let is_date = matches ! ( logical_type, Some ( LogicalType :: Date ) )
187- || matches ! ( converted_type, ConvertedType :: DATE ) ;
188-
189- let is_timestamp = matches ! (
190- logical_type,
191- Some ( LogicalType :: Timestamp {
192- is_adjusted_to_u_t_c,
193- ..
194- } ) if !is_adjusted_to_u_t_c
195- ) ;
196-
197- let is_timestamptz = matches ! (
198- logical_type,
199- Some ( LogicalType :: Timestamp {
200- is_adjusted_to_u_t_c,
201- ..
202- } ) if is_adjusted_to_u_t_c
203- ) ;
204-
205- let is_time = matches ! (
206- logical_type,
207- Some ( LogicalType :: Time {
208- is_adjusted_to_u_t_c,
209- ..
210- } ) if !is_adjusted_to_u_t_c
211- ) ;
212-
213- let is_timetz = matches ! (
214- logical_type,
215- Some ( LogicalType :: Time {
216- is_adjusted_to_u_t_c,
217- ..
218- } ) if is_adjusted_to_u_t_c
219- ) ;
220-
221- let is_numeric = matches ! ( logical_type, Some ( LogicalType :: Decimal { .. } ) )
222- || matches ! ( converted_type, ConvertedType :: DECIMAL ) ;
223-
224178 match statistics {
225179 Statistics :: Boolean ( statistics) => statistics. min_opt ( ) . map ( |v| v. to_string ( ) ) ,
226180 Statistics :: Int32 ( statistics) => statistics. min_opt ( ) . map ( |v| {
227- if is_date {
181+ if matches ! ( logical_type, Some ( LogicalType :: Date ) )
182+ || matches ! ( converted_type, ConvertedType :: DATE )
183+ {
228184 pg_format ( i32_to_date ( * v) )
229- } else if is_numeric {
185+ } else if matches ! ( logical_type, Some ( LogicalType :: Decimal { .. } ) )
186+ || matches ! ( converted_type, ConvertedType :: DECIMAL )
187+ {
230188 pg_format_numeric ( * v as i128 , column_descriptor)
231189 } else {
232190 v. to_string ( )
233191 }
234192 } ) ,
235193 Statistics :: Int64 ( statistics) => statistics. min_opt ( ) . map ( |v| {
236- if is_timestamp {
237- pg_format ( i64_to_timestamp ( * v) )
238- } else if is_timestamptz {
194+ if matches ! (
195+ logical_type,
196+ Some ( LogicalType :: Timestamp {
197+ is_adjusted_to_u_t_c,
198+ ..
199+ } ) if is_adjusted_to_u_t_c
200+ ) {
239201 pg_format ( i64_to_timestamptz ( * v, "UTC" ) )
240- } else if is_numeric {
202+ } else if matches ! (
203+ logical_type,
204+ Some ( LogicalType :: Timestamp {
205+ is_adjusted_to_u_t_c,
206+ ..
207+ } ) if !is_adjusted_to_u_t_c || matches!( converted_type, ConvertedType :: TIMESTAMP_MICROS )
208+ ) {
209+ pg_format ( i64_to_timestamp ( * v) )
210+ } else if matches ! ( logical_type, Some ( LogicalType :: Decimal { .. } ) )
211+ || matches ! ( converted_type, ConvertedType :: DECIMAL )
212+ {
241213 pg_format_numeric ( * v as i128 , column_descriptor)
242- } else if is_time {
243- pg_format ( i64_to_time ( * v) )
244- } else if is_timetz {
214+ } else if matches ! (
215+ logical_type,
216+ Some ( LogicalType :: Time {
217+ is_adjusted_to_u_t_c,
218+ ..
219+ } ) if is_adjusted_to_u_t_c
220+ ) {
245221 pg_format ( i64_to_timetz ( * v) )
222+ } else if matches ! (
223+ logical_type,
224+ Some ( LogicalType :: Time {
225+ is_adjusted_to_u_t_c,
226+ ..
227+ } ) if !is_adjusted_to_u_t_c || matches!( converted_type, ConvertedType :: TIME_MICROS )
228+ ) {
229+ pg_format ( i64_to_time ( * v) )
246230 } else {
247231 v. to_string ( )
248232 }
@@ -251,7 +235,11 @@ pub(crate) fn stats_min_value_to_pg_str(
251235 Statistics :: Float ( statistics) => statistics. min_opt ( ) . map ( |v| v. to_string ( ) ) ,
252236 Statistics :: Double ( statistics) => statistics. min_opt ( ) . map ( |v| v. to_string ( ) ) ,
253237 Statistics :: ByteArray ( statistics) => statistics. min_opt ( ) . map ( |v| {
254- if is_string || is_json {
238+ if matches ! ( logical_type, Some ( LogicalType :: String ) )
239+ || matches ! ( converted_type, ConvertedType :: UTF8 )
240+ || matches ! ( logical_type, Some ( LogicalType :: Json ) )
241+ || matches ! ( converted_type, ConvertedType :: JSON )
242+ {
255243 v. as_utf8 ( )
256244 . unwrap_or_else ( |e| panic ! ( "cannot convert stats to utf8 {e}" ) )
257245 . to_string ( )
@@ -260,11 +248,15 @@ pub(crate) fn stats_min_value_to_pg_str(
260248 }
261249 } ) ,
262250 Statistics :: FixedLenByteArray ( statistics) => statistics. min_opt ( ) . map ( |v| {
263- if is_string {
251+ if matches ! ( logical_type, Some ( LogicalType :: String ) )
252+ || matches ! ( converted_type, ConvertedType :: UTF8 )
253+ {
264254 v. as_utf8 ( )
265255 . unwrap_or_else ( |e| panic ! ( "cannot convert stats to utf8 {e}" ) )
266256 . to_string ( )
267- } else if is_numeric {
257+ } else if matches ! ( logical_type, Some ( LogicalType :: Decimal { .. } ) )
258+ || matches ! ( converted_type, ConvertedType :: DECIMAL )
259+ {
268260 let mut numeric_bytes: [ u8 ; 16 ] = [ 0 ; 16 ] ;
269261
270262 let offset = numeric_bytes. len ( ) - v. data ( ) . len ( ) ;
@@ -273,7 +265,7 @@ pub(crate) fn stats_min_value_to_pg_str(
273265 let numeric = i128:: from_be_bytes ( numeric_bytes) ;
274266
275267 pg_format_numeric ( numeric, column_descriptor)
276- } else if is_uuid {
268+ } else if matches ! ( logical_type , Some ( LogicalType :: Uuid ) ) {
277269 let uuid = Uuid :: from_slice ( v. data ( ) ) . expect ( "Invalid Uuid" ) ;
278270
279271 pg_format ( uuid)
@@ -292,74 +284,58 @@ pub(crate) fn stats_max_value_to_pg_str(
292284
293285 let converted_type = column_descriptor. converted_type ( ) ;
294286
295- let is_string = matches ! ( logical_type, Some ( LogicalType :: String ) )
296- || matches ! ( converted_type, ConvertedType :: UTF8 ) ;
297-
298- let is_json = matches ! ( logical_type, Some ( LogicalType :: Json ) )
299- || matches ! ( converted_type, ConvertedType :: JSON ) ;
300-
301- let is_uuid = matches ! ( logical_type, Some ( LogicalType :: Uuid ) ) ;
302-
303- let is_date = matches ! ( logical_type, Some ( LogicalType :: Date ) )
304- || matches ! ( converted_type, ConvertedType :: DATE ) ;
305-
306- let is_timestamp = matches ! (
307- logical_type,
308- Some ( LogicalType :: Timestamp {
309- is_adjusted_to_u_t_c,
310- ..
311- } ) if !is_adjusted_to_u_t_c
312- ) ;
313-
314- let is_timestamptz = matches ! (
315- logical_type,
316- Some ( LogicalType :: Timestamp {
317- is_adjusted_to_u_t_c,
318- ..
319- } ) if is_adjusted_to_u_t_c
320- ) ;
321-
322- let is_time = matches ! (
323- logical_type,
324- Some ( LogicalType :: Time {
325- is_adjusted_to_u_t_c,
326- ..
327- } ) if !is_adjusted_to_u_t_c
328- ) ;
329-
330- let is_timetz = matches ! (
331- logical_type,
332- Some ( LogicalType :: Time {
333- is_adjusted_to_u_t_c,
334- ..
335- } ) if is_adjusted_to_u_t_c
336- ) ;
337-
338- let is_numeric = matches ! ( logical_type, Some ( LogicalType :: Decimal { .. } ) )
339- || matches ! ( converted_type, ConvertedType :: DECIMAL ) ;
340-
341287 match statistics {
342288 Statistics :: Boolean ( statistics) => statistics. max_opt ( ) . map ( |v| v. to_string ( ) ) ,
343289 Statistics :: Int32 ( statistics) => statistics. max_opt ( ) . map ( |v| {
344- if is_date {
290+ if matches ! ( logical_type, Some ( LogicalType :: Date ) )
291+ || matches ! ( converted_type, ConvertedType :: DATE )
292+ {
345293 pg_format ( i32_to_date ( * v) )
346- } else if is_numeric {
294+ } else if matches ! ( logical_type, Some ( LogicalType :: Decimal { .. } ) )
295+ || matches ! ( converted_type, ConvertedType :: DECIMAL )
296+ {
347297 pg_format_numeric ( * v as i128 , column_descriptor)
348298 } else {
349299 v. to_string ( )
350300 }
351301 } ) ,
352302 Statistics :: Int64 ( statistics) => statistics. max_opt ( ) . map ( |v| {
353- if is_timestamp {
354- pg_format ( i64_to_timestamp ( * v) )
355- } else if is_timestamptz {
303+ if matches ! (
304+ logical_type,
305+ Some ( LogicalType :: Timestamp {
306+ is_adjusted_to_u_t_c,
307+ ..
308+ } ) if is_adjusted_to_u_t_c
309+ ) {
356310 pg_format ( i64_to_timestamptz ( * v, "UTC" ) )
357- } else if is_numeric {
311+ } else if matches ! (
312+ logical_type,
313+ Some ( LogicalType :: Timestamp {
314+ is_adjusted_to_u_t_c,
315+ ..
316+ } ) if !is_adjusted_to_u_t_c || matches!( converted_type, ConvertedType :: TIMESTAMP_MICROS )
317+ ) {
318+ pg_format ( i64_to_timestamp ( * v) )
319+ } else if matches ! ( logical_type, Some ( LogicalType :: Decimal { .. } ) )
320+ || matches ! ( converted_type, ConvertedType :: DECIMAL )
321+ {
358322 pg_format_numeric ( * v as i128 , column_descriptor)
359- } else if is_time {
360- pg_format ( i64_to_time ( * v) )
361- } else if is_timetz {
323+ } else if matches ! (
324+ logical_type,
325+ Some ( LogicalType :: Time {
326+ is_adjusted_to_u_t_c,
327+ ..
328+ } ) if is_adjusted_to_u_t_c
329+ ) {
362330 pg_format ( i64_to_timetz ( * v) )
331+ } else if matches ! (
332+ logical_type,
333+ Some ( LogicalType :: Time {
334+ is_adjusted_to_u_t_c,
335+ ..
336+ } ) if !is_adjusted_to_u_t_c || matches!( converted_type, ConvertedType :: TIME_MICROS )
337+ ) {
338+ pg_format ( i64_to_time ( * v) )
363339 } else {
364340 v. to_string ( )
365341 }
@@ -368,7 +344,11 @@ pub(crate) fn stats_max_value_to_pg_str(
368344 Statistics :: Float ( statistics) => statistics. max_opt ( ) . map ( |v| v. to_string ( ) ) ,
369345 Statistics :: Double ( statistics) => statistics. max_opt ( ) . map ( |v| v. to_string ( ) ) ,
370346 Statistics :: ByteArray ( statistics) => statistics. max_opt ( ) . map ( |v| {
371- if is_string || is_json {
347+ if matches ! ( logical_type, Some ( LogicalType :: String ) )
348+ || matches ! ( converted_type, ConvertedType :: UTF8 )
349+ || matches ! ( logical_type, Some ( LogicalType :: Json ) )
350+ || matches ! ( converted_type, ConvertedType :: JSON )
351+ {
372352 v. as_utf8 ( )
373353 . unwrap_or_else ( |e| panic ! ( "cannot convert stats to utf8 {e}" ) )
374354 . to_string ( )
@@ -377,11 +357,15 @@ pub(crate) fn stats_max_value_to_pg_str(
377357 }
378358 } ) ,
379359 Statistics :: FixedLenByteArray ( statistics) => statistics. max_opt ( ) . map ( |v| {
380- if is_string {
360+ if matches ! ( logical_type, Some ( LogicalType :: String ) )
361+ || matches ! ( converted_type, ConvertedType :: UTF8 )
362+ {
381363 v. as_utf8 ( )
382364 . unwrap_or_else ( |e| panic ! ( "cannot convert stats to utf8 {e}" ) )
383365 . to_string ( )
384- } else if is_numeric {
366+ } else if matches ! ( logical_type, Some ( LogicalType :: Decimal { .. } ) )
367+ || matches ! ( converted_type, ConvertedType :: DECIMAL )
368+ {
385369 let mut numeric_bytes: [ u8 ; 16 ] = [ 0 ; 16 ] ;
386370
387371 let offset = numeric_bytes. len ( ) - v. data ( ) . len ( ) ;
@@ -390,7 +374,7 @@ pub(crate) fn stats_max_value_to_pg_str(
390374 let numeric = i128:: from_be_bytes ( numeric_bytes) ;
391375
392376 pg_format_numeric ( numeric, column_descriptor)
393- } else if is_uuid {
377+ } else if matches ! ( logical_type , Some ( LogicalType :: Uuid ) ) {
394378 let uuid = Uuid :: from_slice ( v. data ( ) ) . expect ( "Invalid Uuid" ) ;
395379
396380 pg_format ( uuid)
0 commit comments