Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: timestamptz type mismatch #9090

Merged
merged 5 commits into from
Apr 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions src/connector/src/sink/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,10 @@ fn datum_to_json_object(field: &Field, datum: DatumRef<'_>) -> ArrayResult<Value
(DataType::Decimal, ScalarRefImpl::Decimal(v)) => {
json!(v.to_text())
}
(DataType::Timestamptz, ScalarRefImpl::Timestamp(v)) => {
json!(v.0.and_local_timezone(chrono::Utc).unwrap().to_rfc3339())
(DataType::Timestamptz, ScalarRefImpl::Int64(v)) => {
// risingwave's timestamp with timezone is stored in UTC and does not maintain the
// timezone info and the time is in microsecond.
json!(v)
}
(DataType::Time, ScalarRefImpl::Time(v)) => {
// todo: just ignore the nanos part to avoid leap second complex
Expand Down Expand Up @@ -341,11 +343,10 @@ fn datum_to_json_object(field: &Field, datum: DatumRef<'_>) -> ArrayResult<Value
}
json!(map)
}
_ => {
return Err(ArrayError::internal(format!(
"datum_to_json_object: unsupported data type {:?}, {:?}",
field.data_type, scalar_ref,
)));
(data_type, scalar_ref) => {
return Err(ArrayError::internal(
format!("datum_to_json_object: unsupported data type: field name: {:?}, logical type: {:?}, physical type: {:?}", field.name, data_type, scalar_ref),
));
}
};

Expand All @@ -356,6 +357,7 @@ fn datum_to_json_object(field: &Field, datum: DatumRef<'_>) -> ArrayResult<Value
mod tests {

use risingwave_common::types::{Interval, ScalarImpl, Time, Timestamp};
use risingwave_expr::vector_op::cast::str_with_time_zone_to_timestamptz;

use super::*;
#[test]
Expand Down Expand Up @@ -401,23 +403,15 @@ mod tests {

// https://github.com/debezium/debezium/blob/main/debezium-core/src/main/java/io/debezium/time/ZonedTimestamp.java
let tstz_str = "2018-01-26T18:30:09.453Z";
let tstz_value = datum_to_json_object(
let tstz_inner = str_with_time_zone_to_timestamptz(tstz_str).unwrap();
datum_to_json_object(
&Field {
data_type: DataType::Timestamptz,
..mock_field.clone()
},
Some(
ScalarImpl::Timestamp(
chrono::DateTime::parse_from_rfc3339(tstz_str)
.unwrap()
.naive_utc()
.into(),
)
.as_scalar_ref_impl(),
),
Some(ScalarImpl::Int64(tstz_inner).as_scalar_ref_impl()),
)
.unwrap();
chrono::DateTime::parse_from_rfc3339(tstz_value.as_str().unwrap_or_default()).unwrap();

let ts_value = datum_to_json_object(
&Field {
Expand Down