[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);
|
||||
|
||||
@ -827,6 +827,35 @@ public class DynamicPartitionTableTest {
|
||||
Assert.assertEquals(7, partitionName.length());
|
||||
}
|
||||
|
||||
createOlapTblStmt = "CREATE TABLE test.`year_dynamic_partition` (\n"
|
||||
+ " `k1` datetime NULL COMMENT \"\",\n"
|
||||
+ " `k2` int NULL COMMENT \"\"\n"
|
||||
+ ") ENGINE=OLAP\n"
|
||||
+ "PARTITION BY RANGE(`k1`)\n"
|
||||
+ "()\n"
|
||||
+ "DISTRIBUTED BY HASH(`k2`) BUCKETS 3\n"
|
||||
+ "PROPERTIES (\n"
|
||||
+ "\"replication_num\" = \"1\",\n"
|
||||
+ "\"dynamic_partition.enable\" = \"true\",\n"
|
||||
+ "\"dynamic_partition.start\" = \"-3\",\n"
|
||||
+ "\"dynamic_partition.end\" = \"3\",\n"
|
||||
+ "\"dynamic_partition.create_history_partition\" = \"true\",\n"
|
||||
+ "\"dynamic_partition.time_unit\" = \"year\",\n"
|
||||
+ "\"dynamic_partition.prefix\" = \"p\",\n"
|
||||
+ "\"dynamic_partition.buckets\" = \"1\"\n"
|
||||
+ ");";
|
||||
createTable(createOlapTblStmt);
|
||||
emptyDynamicTable = (OlapTable) Env.getCurrentInternalCatalog()
|
||||
.getDbOrAnalysisException("default_cluster:test")
|
||||
.getTableOrAnalysisException("year_dynamic_partition");
|
||||
Assert.assertEquals(7, emptyDynamicTable.getAllPartitions().size());
|
||||
|
||||
partitionIterator = emptyDynamicTable.getAllPartitions().iterator();
|
||||
while (partitionIterator.hasNext()) {
|
||||
String partitionName = partitionIterator.next().getName();
|
||||
Assert.assertEquals(5, partitionName.length());
|
||||
}
|
||||
|
||||
createOlapTblStmt = "CREATE TABLE test.`int_dynamic_partition_day` (\n"
|
||||
+ " `k1` int NULL COMMENT \"\",\n"
|
||||
+ " `k2` int NULL COMMENT \"\"\n"
|
||||
|
||||
Reference in New Issue
Block a user