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

[INLONG-6373][Sort] Fix the time value when data type is datetime and timestamp #6403

Merged
merged 1 commit into from
Nov 4, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.debezium.time.NanoTimestamp;
import io.debezium.time.Timestamp;
import io.debezium.time.ZonedTimestamp;
import java.time.ZonedDateTime;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.table.data.DecimalData;
import org.apache.flink.table.data.GenericRowData;
Expand Down Expand Up @@ -81,6 +82,7 @@ public final class RowDataDebeziumDeserializeSchema

private static final DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_TIME;

private static final ZoneId ZONE_UTC = ZoneId.of("UTC");
/**
* TypeInformation of the produced {@link RowData}. *
*/
Expand Down Expand Up @@ -634,12 +636,13 @@ private Object getValueWithSchema(Object fieldValue, String schemaName) {
fieldValue = dateFormatter.format(LocalDate.ofEpochDay((Integer) fieldValue));
break;
case ZonedTimestamp.SCHEMA_NAME:
// by default the field value is zoned timestamp, no need to convert
ZonedDateTime zonedDateTime = ZonedDateTime.parse((CharSequence) fieldValue);
fieldValue = zonedDateTime.withZoneSameInstant(serverTimeZone).toLocalDateTime()
.atZone(ZONE_UTC).format(DateTimeFormatter.ISO_INSTANT);
break;
case Timestamp.SCHEMA_NAME:
Instant instantTime = Instant.ofEpochMilli((Long) fieldValue);
fieldValue = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(LocalDateTime.ofInstant(instantTime,
serverTimeZone));
fieldValue = LocalDateTime.ofInstant(instantTime, ZONE_UTC).toString();
break;
case Decimal.LOGICAL_NAME:
// no need to transfer decimal type since the value is already decimal
Expand Down