Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug](auto-partition) fix auto partition could set storage_medium properties #45955

Merged
merged 7 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.base.Objects;
Expand Down Expand Up @@ -187,7 +189,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
Loading