Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangstar333 committed Sep 21, 2023
1 parent ecdd70d commit 3a75372
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public String debugString() {
MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(this);
helper.add("slotDesc", desc != null ? desc.debugString() : "null");
helper.add("col", col);
helper.add("type1", type.toSql());
helper.add("type", type.toSql());
helper.add("label", label);
helper.add("tblName", tblName != null ? tblName.toSql() : "null");
return helper.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ public void write(DataOutput out) throws IOException {
out.writeInt(size);
for (int i = 0; i < size; ++i) {
Expr e = this.partitionExprs.get(i);
LOG.info("this.partitionExprs.get(i): " + e.debugString());
Expr.writeTo(e, out);
}
out.writeBoolean(isAutoCreatePartitions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,28 @@

package org.apache.doris.analysis;

import org.apache.doris.common.FeConstants;
import java.util.ArrayList;
import java.util.List;

import org.apache.doris.catalog.Database;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.Partition;
import org.apache.doris.common.FeConstants;
import org.apache.doris.service.ExecuteEnv;
import org.apache.doris.service.FrontendServiceImpl;
import org.apache.doris.thrift.TCreatePartitionRequest;
import org.apache.doris.thrift.TCreatePartitionResult;
import org.apache.doris.thrift.TStatusCode;
import org.apache.doris.thrift.TStringLiteral;
import org.junit.Assert;
import org.junit.jupiter.api.Test;

import mockit.Mocked;

public class RangePartitionPruneTest extends PartitionPruneTestBase {
@Mocked
ExecuteEnv exeEnv;

@Override
protected void runBeforeAll() throws Exception {
Expand Down Expand Up @@ -104,10 +121,22 @@ protected void runBeforeAll() throws Exception {
+ "DISTRIBUTED BY HASH(`k1`) BUCKETS 10\n"
+ "PROPERTIES ('replication_num' = '1');";

String autoCreatePartitionTable = new String("CREATE TABLE test.partition_range(\n"
+ " event_day DATETIME,\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(\"replication_num\" = \"1\");");
createTables(singleColumnPartitionTable,
notNullSingleColumnPartitionTable,
multipleColumnsPartitionTable,
notNullMultipleColumnsPartitionTable);
notNullMultipleColumnsPartitionTable,
autoCreatePartitionTable);
}

private void initTestCases() {
Expand Down Expand Up @@ -196,6 +225,42 @@ private void initTestCases() {

}

@Test
public void createPartition() throws Exception {
Database db = Env.getCurrentInternalCatalog().getDbOrAnalysisException("default_cluster:test");
OlapTable table = (OlapTable) db.getTableOrAnalysisException("partition_range");

List<List<TStringLiteral>> partitionValues = new ArrayList<>();

List<TStringLiteral> first = new ArrayList<>();
TStringLiteral firstLiteral = new TStringLiteral();
firstLiteral.setValue("2023-08-07 11:00:00");
first.add(firstLiteral);
partitionValues.add(first);

List<TStringLiteral> second = new ArrayList<>();
TStringLiteral secondLiteral = new TStringLiteral();
secondLiteral.setValue("2002-01-06 12:00:00");
second.add(secondLiteral);

partitionValues.add(second);

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);
ArrayList<Partition> partitions = (ArrayList<Partition>) table.getAllPartitions();
Assert.assertEquals(partitions.size(), 2);

addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.partition_range where event_day= \"2023-08-07 11:00:00\" ", "partitions=1/2");
addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.partition_range where date_trunc(event_day, \"day\")= \"2023-08-07 11:00:00\" ", "partitions=1/2");
doTest();
}

@Test
public void testPartitionPrune() throws Exception {
initTestCases();
Expand Down

0 comments on commit 3a75372

Please sign in to comment.