From d85ec1fea198c808f1aa30ff6a761b346d4c5615 Mon Sep 17 00:00:00 2001 From: deardeng <565620795@qq.com> Date: Tue, 15 Oct 2024 19:49:56 +0800 Subject: [PATCH 1/2] [fix](create table) Enhance the robustness of time zone handling during table creation --- .../doris/common/util/PropertyAnalyzer.java | 9 ++++-- .../catalog/DynamicPartitionTableTest.java | 30 +++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/util/PropertyAnalyzer.java b/fe/fe-core/src/main/java/org/apache/doris/common/util/PropertyAnalyzer.java index 8e1a05c9de5417..238250ab37a398 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/common/util/PropertyAnalyzer.java +++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/PropertyAnalyzer.java @@ -344,8 +344,13 @@ public static DataProperty analyzeDataProperty(Map properties, f throw new AnalysisException("Invalid storage medium: " + value); } } else if (key.equalsIgnoreCase(PROPERTIES_STORAGE_COOLDOWN_TIME)) { - DateLiteral dateLiteral = new DateLiteral(value, ScalarType.getDefaultDateType(Type.DATETIME)); - cooldownTimestamp = dateLiteral.unixTimestamp(TimeUtils.getTimeZone()); + try { + DateLiteral dateLiteral = new DateLiteral(value, ScalarType.getDefaultDateType(Type.DATETIME)); + cooldownTimestamp = dateLiteral.unixTimestamp(TimeUtils.getTimeZone()); + } catch (AnalysisException e) { + LOG.warn("dateLiteral failed, use max cool down time", e); + cooldownTimestamp = DataProperty.MAX_COOLDOWN_TIME_MS; + } } else if (key.equalsIgnoreCase(PROPERTIES_STORAGE_POLICY)) { hasStoragePolicy = true; newStoragePolicy = value; diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/DynamicPartitionTableTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/DynamicPartitionTableTest.java index 2ae051e4f2518e..4bde8576d01ea9 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/DynamicPartitionTableTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/DynamicPartitionTableTest.java @@ -1677,7 +1677,7 @@ public void testNoPartition() throws AnalysisException { @Test public void testHourUnitWithDateType() throws AnalysisException { - String createOlapTblStmt = "CREATE TABLE if not exists test.hour_with_date (\n" + String createOlapTblStmt = "CREATE TABLE if not exists test.hour_with_date1 (\n" + " `days` DATEV2 NOT NULL,\n" + " `hours` char(2) NOT NULL,\n" + " `positionID` char(20)\n" @@ -1703,7 +1703,7 @@ public void testHourUnitWithDateType() throws AnalysisException { "could not be HOUR when type of partition column days is DATE or DATEV2", () -> createTable(createOlapTblStmt)); - String createOlapTblStmt2 = "CREATE TABLE if not exists test.hour_with_date (\n" + String createOlapTblStmt2 = "CREATE TABLE if not exists test.hour_with_date2 (\n" + " `days` DATETIMEV2 NOT NULL,\n" + " `hours` char(2) NOT NULL,\n" + " `positionID` char(20)\n" @@ -1726,6 +1726,32 @@ public void testHourUnitWithDateType() throws AnalysisException { + "\"dynamic_partition.create_history_partition\" = \"true\"\n" + ");"; ExceptionChecker.expectThrowsNoException(() -> createTable(createOlapTblStmt2)); + + connectContext.getSessionVariable().setTimeZone("Asia/Tokyo"); + String createOlapTblStmt3 = "CREATE TABLE if not exists test.hour_with_date3 (\n" + + " `days` DATETIMEV2 NOT NULL,\n" + + " `hours` char(2) NOT NULL,\n" + + " `positionID` char(20)\n" + + " )\n" + + "UNIQUE KEY(`days`,`hours`,`positionID`)\n" + + "PARTITION BY RANGE(`days`) ()\n" + + "DISTRIBUTED BY HASH(`positionID`) BUCKETS AUTO\n" + + "PROPERTIES (\n" + + "\"replication_num\" = \"1\",\n" + + "\"compression\" = \"zstd\",\n" + + "\"enable_unique_key_merge_on_write\" = \"true\",\n" + + "\"light_schema_change\" = \"true\",\n" + + "\"dynamic_partition.enable\" = \"true\",\n" + + "\"dynamic_partition.time_unit\" = \"HOUR\",\n" + + "\"dynamic_partition.start\" = \"-24\",\n" + + "\"dynamic_partition.end\" = \"24\",\n" + + "\"dynamic_partition.prefix\" = \"p\",\n" + + "\"dynamic_partition.buckets\" = \"2\",\n" + + "\"dynamic_partition.hot_partition_num\" = \"0\",\n" + + "\"dynamic_partition.storage_medium\" = \"HDD\", \n" + + "\"dynamic_partition.create_history_partition\" = \"true\"\n" + + ");"; + ExceptionChecker.expectThrowsNoException(() -> createTable(createOlapTblStmt3)); } @Test From 5e14fa7f92895776d1a8caecbd3e74d36b7bce30 Mon Sep 17 00:00:00 2001 From: deardeng <565620795@qq.com> Date: Wed, 16 Oct 2024 12:02:10 +0800 Subject: [PATCH 2/2] fix compile --- .../catalog/DynamicPartitionTableTest.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/DynamicPartitionTableTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/DynamicPartitionTableTest.java index 4bde8576d01ea9..4217342133b9ab 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/DynamicPartitionTableTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/DynamicPartitionTableTest.java @@ -1729,28 +1729,28 @@ public void testHourUnitWithDateType() throws AnalysisException { connectContext.getSessionVariable().setTimeZone("Asia/Tokyo"); String createOlapTblStmt3 = "CREATE TABLE if not exists test.hour_with_date3 (\n" - + " `days` DATETIMEV2 NOT NULL,\n" - + " `hours` char(2) NOT NULL,\n" - + " `positionID` char(20)\n" - + " )\n" - + "UNIQUE KEY(`days`,`hours`,`positionID`)\n" - + "PARTITION BY RANGE(`days`) ()\n" - + "DISTRIBUTED BY HASH(`positionID`) BUCKETS AUTO\n" - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\",\n" - + "\"compression\" = \"zstd\",\n" - + "\"enable_unique_key_merge_on_write\" = \"true\",\n" - + "\"light_schema_change\" = \"true\",\n" - + "\"dynamic_partition.enable\" = \"true\",\n" - + "\"dynamic_partition.time_unit\" = \"HOUR\",\n" - + "\"dynamic_partition.start\" = \"-24\",\n" - + "\"dynamic_partition.end\" = \"24\",\n" - + "\"dynamic_partition.prefix\" = \"p\",\n" - + "\"dynamic_partition.buckets\" = \"2\",\n" - + "\"dynamic_partition.hot_partition_num\" = \"0\",\n" - + "\"dynamic_partition.storage_medium\" = \"HDD\", \n" - + "\"dynamic_partition.create_history_partition\" = \"true\"\n" - + ");"; + + " `days` DATETIMEV2 NOT NULL,\n" + + " `hours` char(2) NOT NULL,\n" + + " `positionID` char(20)\n" + + " )\n" + + "UNIQUE KEY(`days`,`hours`,`positionID`)\n" + + "PARTITION BY RANGE(`days`) ()\n" + + "DISTRIBUTED BY HASH(`positionID`) BUCKETS AUTO\n" + + "PROPERTIES (\n" + + "\"replication_num\" = \"1\",\n" + + "\"compression\" = \"zstd\",\n" + + "\"enable_unique_key_merge_on_write\" = \"true\",\n" + + "\"light_schema_change\" = \"true\",\n" + + "\"dynamic_partition.enable\" = \"true\",\n" + + "\"dynamic_partition.time_unit\" = \"HOUR\",\n" + + "\"dynamic_partition.start\" = \"-24\",\n" + + "\"dynamic_partition.end\" = \"24\",\n" + + "\"dynamic_partition.prefix\" = \"p\",\n" + + "\"dynamic_partition.buckets\" = \"2\",\n" + + "\"dynamic_partition.hot_partition_num\" = \"0\",\n" + + "\"dynamic_partition.storage_medium\" = \"HDD\", \n" + + "\"dynamic_partition.create_history_partition\" = \"true\"\n" + + ");"; ExceptionChecker.expectThrowsNoException(() -> createTable(createOlapTblStmt3)); }