[enhancement](schema) dynamic_partition.time_unit support year (#19551)
dynamic_partition.time_unit support year
This commit is contained in:
@ -1125,7 +1125,7 @@ public enum ErrorCode {
|
||||
ERR_DYNAMIC_PARTITION_MUST_HAS_SAME_BUCKET_NUM_WITH_COLOCATE_TABLE(5063, new byte[]{'4', '2', '0', '0', '0'},
|
||||
"Dynamic partition buckets must equal the distribution buckets if creating a colocate table: %s"),
|
||||
ERROR_DYNAMIC_PARTITION_TIME_UNIT(5065, new byte[]{'4', '2', '0', '0', '0'},
|
||||
"Unsupported time unit %s. Expect HOUR/DAY/WEEK/MONTH."),
|
||||
"Unsupported time unit %s. Expect HOUR/DAY/WEEK/MONTH/YEAR."),
|
||||
ERROR_DYNAMIC_PARTITION_START_ZERO(5066, new byte[]{'4', '2', '0', '0', '0'},
|
||||
"Dynamic partition start must less than 0"),
|
||||
ERROR_DYNAMIC_PARTITION_START_FORMAT(5066, new byte[]{'4', '2', '0', '0', '0'},
|
||||
|
||||
@ -81,7 +81,8 @@ public class DynamicPartitionUtil {
|
||||
|| !(timeUnit.equalsIgnoreCase(TimeUnit.DAY.toString())
|
||||
|| timeUnit.equalsIgnoreCase(TimeUnit.HOUR.toString())
|
||||
|| timeUnit.equalsIgnoreCase(TimeUnit.WEEK.toString())
|
||||
|| timeUnit.equalsIgnoreCase(TimeUnit.MONTH.toString()))) {
|
||||
|| timeUnit.equalsIgnoreCase(TimeUnit.MONTH.toString())
|
||||
|| timeUnit.equalsIgnoreCase(TimeUnit.YEAR.toString()))) {
|
||||
ErrorReport.reportDdlException(ErrorCode.ERROR_DYNAMIC_PARTITION_TIME_UNIT, timeUnit);
|
||||
}
|
||||
Preconditions.checkState(partitionInfo instanceof RangePartitionInfo);
|
||||
@ -716,6 +717,8 @@ public class DynamicPartitionUtil {
|
||||
return formattedDateStr.substring(0, 8);
|
||||
} else if (timeUnit.equalsIgnoreCase(TimeUnit.MONTH.toString())) {
|
||||
return formattedDateStr.substring(0, 6);
|
||||
} else if (timeUnit.equalsIgnoreCase(TimeUnit.YEAR.toString())) {
|
||||
return formattedDateStr.substring(0, 4);
|
||||
} else if (timeUnit.equalsIgnoreCase(TimeUnit.HOUR.toString())) {
|
||||
return formattedDateStr.substring(0, 10);
|
||||
} else {
|
||||
@ -741,7 +744,6 @@ public class DynamicPartitionUtil {
|
||||
|
||||
// return the partition range date string formatted as yyyy-MM-dd[ HH:mm::ss]
|
||||
// add support: HOUR by caoyang10
|
||||
// TODO: support YEAR
|
||||
public static String getPartitionRangeString(DynamicPartitionProperty property, ZonedDateTime current,
|
||||
int offset, String format) {
|
||||
String timeUnit = property.getTimeUnit();
|
||||
@ -751,8 +753,10 @@ public class DynamicPartitionUtil {
|
||||
return getPartitionRangeOfWeek(current, offset, property.getStartOfWeek(), format);
|
||||
} else if (timeUnit.equalsIgnoreCase(TimeUnit.HOUR.toString())) {
|
||||
return getPartitionRangeOfHour(current, offset, format);
|
||||
} else { // MONTH
|
||||
} else if (timeUnit.equalsIgnoreCase(TimeUnit.MONTH.toString())) {
|
||||
return getPartitionRangeOfMonth(current, offset, property.getStartOfMonth(), format);
|
||||
} else { // YEAR
|
||||
return getPartitionRangeOfYear(current, offset, format);
|
||||
}
|
||||
}
|
||||
|
||||
@ -856,6 +860,11 @@ public class DynamicPartitionUtil {
|
||||
return getFormattedTimeWithoutHourMinuteSecond(resultTime, format);
|
||||
}
|
||||
|
||||
private static String getPartitionRangeOfYear(ZonedDateTime current, int offset, String format) {
|
||||
ZonedDateTime resultTime = current.plusYears(offset).withMonth(1).withDayOfMonth(1);
|
||||
return getFormattedTimeWithoutHourMinuteSecond(resultTime, format);
|
||||
}
|
||||
|
||||
private static String getFormattedTimeWithoutHourMinuteSecond(ZonedDateTime zonedDateTime, String format) {
|
||||
ZonedDateTime timeWithoutHourMinuteSecond = zonedDateTime.withHour(0).withMinute(0).withSecond(0);
|
||||
return DateTimeFormatter.ofPattern(format).format(timeWithoutHourMinuteSecond);
|
||||
|
||||
Reference in New Issue
Block a user