lvyanquan commented on code in PR #4495:
URL: https://github.com/apache/flink-cdc/pull/4495#discussion_r3742484826
##########
flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/functions/impl/TemporalFunctions.java:
##########
@@ -71,6 +76,94 @@ public static LocalDate currentDate(long epochTime, String
timezone) {
return localtimestamp(epochTime, timezone).toLocalDate();
}
+ public static Long extract(String unit, TemporalAccessor temporal, String
timezone) {
+ if (temporal == null) {
+ return null;
+ }
+ if (temporal instanceof Instant) {
+ temporal = ((Instant) temporal).atZone(ZoneId.of(timezone));
+ }
+ switch (unit) {
+ case "YEAR":
+ return getTemporalField(temporal, ChronoField.YEAR, unit);
+ case "QUARTER":
+ return getTemporalField(temporal, IsoFields.QUARTER_OF_YEAR,
unit);
+ case "MONTH":
+ return getTemporalField(temporal, ChronoField.MONTH_OF_YEAR,
unit);
+ case "WEEK":
+ return getTemporalField(temporal,
IsoFields.WEEK_OF_WEEK_BASED_YEAR, unit);
+ case "DAY":
+ return getTemporalField(temporal, ChronoField.DAY_OF_MONTH,
unit);
+ case "DOY":
+ return getTemporalField(temporal, ChronoField.DAY_OF_YEAR,
unit);
+ case "DOW":
+ // SQL DOW starts with Sunday as 1, while ISO starts with
Monday as 1.
+ return getTemporalField(temporal, ChronoField.DAY_OF_WEEK,
unit) % 7 + 1;
+ case "HOUR":
+ return getTemporalField(temporal, ChronoField.HOUR_OF_DAY,
unit);
+ case "MINUTE":
+ return getTemporalField(temporal, ChronoField.MINUTE_OF_HOUR,
unit);
+ case "SECOND":
+ return getTemporalField(temporal,
ChronoField.SECOND_OF_MINUTE, unit);
+ default:
+ throw new IllegalArgumentException("Unsupported EXTRACT unit:
" + unit);
+ }
+ }
+
+ private static long getTemporalField(
+ TemporalAccessor temporal, java.time.temporal.TemporalField field,
String unit) {
Review Comment:
Avoid using fully qualified names.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]