Skip to content

Commit

Permalink
update fe test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangstar333 committed Oct 7, 2023
1 parent 1badd2f commit dd11569
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 66 deletions.
4 changes: 2 additions & 2 deletions be/src/vec/sink/writer/vtablet_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1683,10 +1683,10 @@ Status VTabletWriter::append_block(doris::vectorized::Block& input_block) {
} else {
// if there's projection of partition calc, we need to calc it first.
auto [part_ctx, part_func] = _get_partition_function();
int result_idx;
int result_idx = -1;
if (_vpartition->is_projection_partition()) {
// calc the start value of missing partition ranges.
static_cast<void>(part_func->execute(part_ctx.get(), block.get(), &result_idx));
RETURN_IF_ERROR(part_func->execute(part_ctx.get(), block.get(), &result_idx));
VLOG_DEBUG << "Partition-calculated block:" << block->dump_data();
// change the column to compare to transformed.
_vpartition->set_transformed_slots({(uint16_t)result_idx});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,11 @@

package org.apache.doris.analysis;

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;
import org.junit.jupiter.api.Test;

public class RangePartitionPruneTest extends PartitionPruneTestBase {
@Mocked
ExecuteEnv exeEnv;

@Override
protected void runBeforeAll() throws Exception {
Expand Down Expand Up @@ -121,17 +104,16 @@ 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\");");
String autoCreatePartitionTable = new String("CREATE TABLE test.test_to_date_trunc(\n"
+ " event_day DATETIME\n"
+ ")\n"
+ "DUPLICATE KEY(event_day)\n"
+ "AUTO PARTITION BY range date_trunc(event_day, \"day\") (\n"
+ "\tPARTITION `p20230807` values [(20230807 ), (20230808 )),\n"
+ "\tPARTITION `p20020106` values [(20020106 ), (20020107 ))\n"
+ ")\n"
+ "DISTRIBUTED BY HASH(event_day) BUCKETS 4\n"
+ "PROPERTIES(\"replication_num\" = \"1\");");
createTables(singleColumnPartitionTable,
notNullSingleColumnPartitionTable,
multipleColumnsPartitionTable,
Expand Down Expand Up @@ -222,44 +204,13 @@ private void initTestCases() {
"partitions=5/8");
addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t1 where (dt between 20211121 and 20211122) or dt is null or (dt between 20211123 and 20211125)",
"partitions=6/8");
addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test_to_date_trunc where event_day= \"2023-08-07 11:00:00\" ",
"partitions=1/2");
addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test_to_date_trunc where date_trunc(event_day, \"day\")= \"2023-08-07 11:00:00\" ",
"partitions=1/2");

}

@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 {
Expand Down

0 comments on commit dd11569

Please sign in to comment.