Skip to content

Commit

Permalink
branch-2.1: [Bug](auto-partition) fix auto partition could set storag…
Browse files Browse the repository at this point in the history
…e_medium properties #45955 (#46260)

Cherry-picked from #45955

Co-authored-by: zhangstar333 <[email protected]>
  • Loading branch information
github-actions[bot] and zhangstar333 authored Jan 2, 2025
1 parent df6935a commit f6d98a6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -186,7 +188,12 @@ public static Map<String, AddPartitionClause> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<List<TNullableStringLiteral>> partitionValues = new ArrayList<>();
List<TNullableStringLiteral> 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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f6d98a6

Please sign in to comment.