@@ -20,8 +20,7 @@ use risingwave_common::array::{ListValue, StructValue};
20
20
use risingwave_common:: error:: ErrorCode :: { InternalError , ProtocolError } ;
21
21
use risingwave_common:: error:: { Result , RwError } ;
22
22
use risingwave_common:: types:: {
23
- DataType , Datum , IntervalUnit , NaiveDateTimeWrapper , NaiveDateWrapper , OrderedF32 , OrderedF64 ,
24
- ScalarImpl ,
23
+ DataType , Datum , IntervalUnit , NaiveDateWrapper , OrderedF32 , OrderedF64 , ScalarImpl ,
25
24
} ;
26
25
use risingwave_pb:: plan_common:: ColumnDesc ;
27
26
@@ -74,8 +73,8 @@ fn avro_type_mapping(schema: &Schema) -> Result<DataType> {
74
73
Schema :: Double => DataType :: Float64 ,
75
74
Schema :: Decimal { .. } => DataType :: Decimal ,
76
75
Schema :: Date => DataType :: Date ,
77
- Schema :: TimestampMillis => DataType :: Timestamp ,
78
- Schema :: TimestampMicros => DataType :: Timestamp ,
76
+ Schema :: TimestampMillis => DataType :: Timestamptz ,
77
+ Schema :: TimestampMicros => DataType :: Timestamptz ,
79
78
Schema :: Duration => DataType :: Interval ,
80
79
Schema :: Enum { .. } => DataType :: Varchar ,
81
80
Schema :: Record { fields, .. } => {
@@ -281,32 +280,13 @@ pub(crate) fn from_avro_value(value: Value, value_schema: &Schema) -> Result<Dat
281
280
RwError :: from ( InternalError ( err_msg) )
282
281
} ) ?,
283
282
) ,
284
- Value :: TimestampMillis ( millis) => ScalarImpl :: NaiveDateTime (
285
- NaiveDateTimeWrapper :: with_secs_nsecs (
286
- millis / 1_000 ,
287
- ( millis % 1_000 ) as u32 * 1_000_000 ,
288
- )
289
- . map_err ( |e| {
290
- let err_msg = format ! (
291
- "avro parse error.wrong timestamp millis value {}, err {:?}" ,
292
- millis, e
293
- ) ;
294
- RwError :: from ( InternalError ( err_msg) )
295
- } ) ?,
296
- ) ,
297
- Value :: TimestampMicros ( micros) => ScalarImpl :: NaiveDateTime (
298
- NaiveDateTimeWrapper :: with_secs_nsecs (
299
- micros / 1_000_000 ,
300
- ( micros % 1_000_000 ) as u32 * 1_000 ,
301
- )
302
- . map_err ( |e| {
303
- let err_msg = format ! (
304
- "avro parse error.wrong timestamp micros value {}, err {:?}" ,
305
- micros, e
306
- ) ;
307
- RwError :: from ( InternalError ( err_msg) )
308
- } ) ?,
309
- ) ,
283
+ Value :: TimestampMicros ( us) => ScalarImpl :: Int64 ( us) ,
284
+ Value :: TimestampMillis ( ms) => ScalarImpl :: Int64 ( ms. checked_mul ( 1000 ) . ok_or_else ( || {
285
+ RwError :: from ( InternalError ( format ! (
286
+ "avro parse millis overflow, value: {}" ,
287
+ ms
288
+ ) ) )
289
+ } ) ?) ,
310
290
Value :: Duration ( duration) => {
311
291
let months = u32:: from ( duration. months ( ) ) as i32 ;
312
292
let days = u32:: from ( duration. days ( ) ) as i32 ;
@@ -364,4 +344,16 @@ mod tests {
364
344
let rust_decimal = avro_decimal_to_rust_decimal ( avro_decimal, 28 , 1 ) . unwrap ( ) ;
365
345
assert_eq ! ( rust_decimal, rust_decimal:: Decimal :: from_f32( 28.1 ) . unwrap( ) ) ;
366
346
}
347
+
348
+ #[ test]
349
+ fn test_avro_timestamp_micros ( ) {
350
+ let v1 = Value :: TimestampMicros ( 1620000000000 ) ;
351
+ let v2 = Value :: TimestampMillis ( 1620000000 ) ;
352
+ let value_schema1 = Schema :: TimestampMicros ;
353
+ let value_schema2 = Schema :: TimestampMillis ;
354
+ let datum1 = from_avro_value ( v1, & value_schema1) . unwrap ( ) ;
355
+ let datum2 = from_avro_value ( v2, & value_schema2) . unwrap ( ) ;
356
+ assert_eq ! ( datum1, Some ( ScalarImpl :: Int64 ( 1620000000000 ) ) ) ;
357
+ assert_eq ! ( datum2, Some ( ScalarImpl :: Int64 ( 1620000000000 ) ) ) ;
358
+ }
367
359
}
0 commit comments