Skip to content

Commit

Permalink
[fix](create table) Enhance the robustness of time zone handling duri…
Browse files Browse the repository at this point in the history
…ng table creation apache#41926 (apache#42389)

cherry pick from apache#41926
  • Loading branch information
deardeng authored Oct 28, 2024
1 parent ddef515 commit 86ce3f8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,13 @@ public static DataProperty analyzeDataProperty(Map<String, String> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit 86ce3f8

Please sign in to comment.