[improvement](dynamic partition) Fix dynamic partition no bucket (#18300)
Signed-off-by: Jack Drogon <jack.xsuperman@gmail.com>
This commit is contained in:
@ -1755,7 +1755,7 @@ public class SchemaChangeHandler extends AlterHandler {
|
||||
if (!olapTable.dynamicPartitionExists()) {
|
||||
try {
|
||||
DynamicPartitionUtil.checkInputDynamicPartitionProperties(properties,
|
||||
olapTable.getPartitionInfo());
|
||||
olapTable);
|
||||
} catch (DdlException e) {
|
||||
// This table is not a dynamic partition table
|
||||
// and didn't supply all dynamic partition properties
|
||||
|
||||
@ -20,6 +20,7 @@ package org.apache.doris.common.util;
|
||||
import org.apache.doris.analysis.TimestampArithmeticExpr.TimeUnit;
|
||||
import org.apache.doris.catalog.Column;
|
||||
import org.apache.doris.catalog.Database;
|
||||
import org.apache.doris.catalog.DistributionInfo;
|
||||
import org.apache.doris.catalog.DynamicPartitionProperty;
|
||||
import org.apache.doris.catalog.Env;
|
||||
import org.apache.doris.catalog.OlapTable;
|
||||
@ -399,10 +400,12 @@ public class DynamicPartitionUtil {
|
||||
// Check if all requried properties has been set.
|
||||
// And also check all optional properties, if not set, set them to default value.
|
||||
public static boolean checkInputDynamicPartitionProperties(Map<String, String> properties,
|
||||
PartitionInfo partitionInfo) throws DdlException {
|
||||
OlapTable olapTable) throws DdlException {
|
||||
if (properties == null || properties.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PartitionInfo partitionInfo = olapTable.getPartitionInfo();
|
||||
if (partitionInfo.getType() != PartitionType.RANGE || partitionInfo.isMultiColumnPartition()) {
|
||||
throw new DdlException("Dynamic partition only support single-column range partition");
|
||||
}
|
||||
@ -443,7 +446,9 @@ public class DynamicPartitionUtil {
|
||||
throw new DdlException("Must assign dynamic_partition.end properties");
|
||||
}
|
||||
if (Strings.isNullOrEmpty(buckets)) {
|
||||
throw new DdlException("Must assign dynamic_partition.buckets properties");
|
||||
DistributionInfo distributionInfo = olapTable.getDefaultDistributionInfo();
|
||||
buckets = String.valueOf(distributionInfo.getBucketNum());
|
||||
properties.put(DynamicPartitionProperty.BUCKETS, buckets);
|
||||
}
|
||||
if (Strings.isNullOrEmpty(timeZone)) {
|
||||
properties.put(DynamicPartitionProperty.TIME_ZONE, TimeUtils.getSystemTimeZone().getID());
|
||||
@ -506,6 +511,7 @@ public class DynamicPartitionUtil {
|
||||
properties.remove(DynamicPartitionProperty.BUCKETS);
|
||||
analyzedProperties.put(DynamicPartitionProperty.BUCKETS, bucketsValue);
|
||||
}
|
||||
|
||||
if (properties.containsKey(DynamicPartitionProperty.ENABLE)) {
|
||||
String enableValue = properties.get(DynamicPartitionProperty.ENABLE);
|
||||
checkEnable(enableValue);
|
||||
@ -675,7 +681,7 @@ public class DynamicPartitionUtil {
|
||||
*/
|
||||
public static void checkAndSetDynamicPartitionProperty(OlapTable olapTable, Map<String, String> properties,
|
||||
Database db) throws UserException {
|
||||
if (DynamicPartitionUtil.checkInputDynamicPartitionProperties(properties, olapTable.getPartitionInfo())) {
|
||||
if (DynamicPartitionUtil.checkInputDynamicPartitionProperties(properties, olapTable)) {
|
||||
Map<String, String> dynamicPartitionProperties =
|
||||
DynamicPartitionUtil.analyzeDynamicPartition(properties, olapTable, db);
|
||||
TableProperty tableProperty = olapTable.getTableProperty();
|
||||
|
||||
@ -258,7 +258,7 @@ public class DynamicPartitionTableTest {
|
||||
|
||||
@Test
|
||||
public void testMissBuckets() throws Exception {
|
||||
String createOlapTblStmt = "CREATE TABLE test.`dynamic_partition_buckets` (\n"
|
||||
String createOlapTblStmt = "CREATE TABLE test.`dynamic_partition_miss_buckets` (\n"
|
||||
+ " `k1` date NULL COMMENT \"\",\n"
|
||||
+ " `k2` int NULL COMMENT \"\",\n"
|
||||
+ " `k3` smallint NULL COMMENT \"\",\n"
|
||||
@ -282,14 +282,12 @@ public class DynamicPartitionTableTest {
|
||||
+ "\"dynamic_partition.time_unit\" = \"day\",\n"
|
||||
+ "\"dynamic_partition.prefix\" = \"p\"\n"
|
||||
+ ");";
|
||||
expectedException.expect(DdlException.class);
|
||||
expectedException.expectMessage("errCode = 2, detailMessage = Must assign dynamic_partition.buckets properties");
|
||||
createTable(createOlapTblStmt);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotAllowed() throws Exception {
|
||||
String createOlapTblStmt = "CREATE TABLE test.`dynamic_partition_buckets` (\n"
|
||||
String createOlapTblStmt = "CREATE TABLE test.`dynamic_partition_not_allowed` (\n"
|
||||
+ " `k1` date NULL COMMENT \"\",\n"
|
||||
+ " `k2` int NULL COMMENT \"\",\n"
|
||||
+ " `k3` smallint NULL COMMENT \"\",\n"
|
||||
|
||||
Reference in New Issue
Block a user