diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java index ef46f1f70dd1eca..72f07067f9893f3 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java @@ -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(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/PartitionInfo.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/PartitionInfo.java index 24db05fc0eaa9a9..b7ca3c622cc7b04 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/PartitionInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/PartitionInfo.java @@ -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); diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/RangePartitionPruneTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/RangePartitionPruneTest.java index df0c10afd087de6..af45087078feb9c 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/RangePartitionPruneTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/RangePartitionPruneTest.java @@ -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 { @@ -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() { @@ -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> partitionValues = new ArrayList<>(); + + List first = new ArrayList<>(); + TStringLiteral firstLiteral = new TStringLiteral(); + firstLiteral.setValue("2023-08-07 11:00:00"); + first.add(firstLiteral); + partitionValues.add(first); + + List 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 partitions = (ArrayList) 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();