From f6d98a6061ae7d7e720d6d5f381a1706b4622e4f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 2 Jan 2025 16:38:55 +0800 Subject: [PATCH] branch-2.1: [Bug](auto-partition) fix auto partition could set storage_medium properties #45955 (#46260) Cherry-picked from #45955 Co-authored-by: zhangstar333 --- .../doris/analysis/PartitionExprUtil.java | 9 +++- .../service/FrontendServiceImplTest.java | 51 ++++++++++++++++++- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionExprUtil.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionExprUtil.java index 420bee53e18293..30c3636434e17a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionExprUtil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionExprUtil.java @@ -18,11 +18,13 @@ package org.apache.doris.analysis; import org.apache.doris.catalog.Column; +import org.apache.doris.catalog.DataProperty; import org.apache.doris.catalog.OlapTable; import org.apache.doris.catalog.PartitionInfo; import org.apache.doris.catalog.PartitionType; import org.apache.doris.catalog.Type; import org.apache.doris.common.AnalysisException; +import org.apache.doris.common.util.PropertyAnalyzer; import org.apache.doris.thrift.TNullableStringLiteral; import com.google.common.collect.Maps; @@ -186,7 +188,12 @@ public static Map getAddPartitionClauseFromPartition SinglePartitionDesc singleRangePartitionDesc = new SinglePartitionDesc(true, partitionName, partitionKeyDesc, partitionProperties); - + // iff table's storage medium is not equal default storage medium, + // should add storage medium in partition properties + if (!DataProperty.DEFAULT_STORAGE_MEDIUM.equals(olapTable.getStorageMedium())) { + partitionProperties.put(PropertyAnalyzer.PROPERTIES_STORAGE_MEDIUM, + olapTable.getStorageMedium().name()); + } AddPartitionClause addPartitionClause = new AddPartitionClause(singleRangePartitionDesc, distributionDesc, partitionProperties, false); result.put(partitionName, addPartitionClause); diff --git a/fe/fe-core/src/test/java/org/apache/doris/service/FrontendServiceImplTest.java b/fe/fe-core/src/test/java/org/apache/doris/service/FrontendServiceImplTest.java index 2e5a4e0745631e..e145b0c688048b 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/service/FrontendServiceImplTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/service/FrontendServiceImplTest.java @@ -25,8 +25,10 @@ import org.apache.doris.catalog.OlapTable; import org.apache.doris.catalog.Partition; import org.apache.doris.common.Config; +import org.apache.doris.common.ConfigBase; import org.apache.doris.common.FeConstants; import org.apache.doris.qe.ConnectContext; +import org.apache.doris.qe.ShowResultSet; import org.apache.doris.tablefunction.BackendsTableValuedFunction; import org.apache.doris.thrift.TBackendsMetadataParams; import org.apache.doris.thrift.TCreatePartitionRequest; @@ -53,7 +55,6 @@ import org.junit.rules.ExpectedException; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.UUID; @@ -132,6 +133,51 @@ public void testCreatePartitionRange() throws Exception { Assert.assertNotNull(p20230807); } + @Test + public void testCreatePartitionRangeMedium() throws Exception { + ConfigBase.setMutableConfig("disable_storage_medium_check", "true"); + String createOlapTblStmt = new String("CREATE TABLE test.partition_range2(\n" + + " event_day DATETIME NOT NULL,\n" + + " site_id INT DEFAULT '10',\n" + + " city_code VARCHAR(100)\n" + + ")\n" + + "DUPLICATE KEY(event_day, site_id, city_code)\n" + + "AUTO PARTITION BY range (date_trunc( event_day,'day')) (\n" + + "\n" + + ")\n" + + "DISTRIBUTED BY HASH(event_day, site_id) BUCKETS 2\n" + + "PROPERTIES(\"storage_medium\" = \"ssd\",\"replication_num\" = \"1\");"); + + createTable(createOlapTblStmt); + Database db = Env.getCurrentInternalCatalog().getDbOrAnalysisException("test"); + OlapTable table = (OlapTable) db.getTableOrAnalysisException("partition_range2"); + + List> partitionValues = new ArrayList<>(); + List values = new ArrayList<>(); + + TNullableStringLiteral start = new TNullableStringLiteral(); + start.setValue("2023-08-07 00:00:00"); + values.add(start); + + partitionValues.add(values); + + FrontendServiceImpl impl = new FrontendServiceImpl(exeEnv); + TCreatePartitionRequest request = new TCreatePartitionRequest(); + request.setDbId(db.getId()); + request.setTableId(table.getId()); + request.setPartitionValues(partitionValues); + TCreatePartitionResult partition = impl.createPartition(request); + + Assert.assertEquals(partition.getStatus().getStatusCode(), TStatusCode.OK); + Partition p20230807 = table.getPartition("p20230807000000"); + Assert.assertNotNull(p20230807); + + ShowResultSet result = UtFrameUtils.showPartitionsByName(connectContext, "test.partition_range2"); + String showCreateTableResultSql = result.getResultRows().get(0).get(10); + System.out.println(showCreateTableResultSql); + Assert.assertEquals(showCreateTableResultSql, "SSD"); + } + @Test public void testCreatePartitionList() throws Exception { String createOlapTblStmt = new String("CREATE TABLE test.partition_list(\n" @@ -185,7 +231,8 @@ public void testGetDBNames() throws Exception { TGetDbsResult dbNames = impl.getDbNames(params); Assert.assertEquals(dbNames.getDbs().size(), 2); - Assert.assertEquals(dbNames.getDbs(), Arrays.asList("test", "test_")); + Assert.assertTrue(dbNames.getDbs().contains("test")); + Assert.assertTrue(dbNames.getDbs().contains("test_")); } @Test