Skip to content

Commit

Permalink
refactor to set
Browse files Browse the repository at this point in the history
Signed-off-by: Murphy <[email protected]>
  • Loading branch information
murphyatwork committed Dec 3, 2024
1 parent 76a8399 commit d9982da
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -616,24 +616,22 @@ public List<Long> getSortedPartitions(boolean asc) {

/**
* ListPartition would put the NULL value into a real NULL partition, whose partition value is NullLiteral
*
* @return
*/
@Override
public List<Long> getNullValuePartitions() {
public Set<Long> getNullValuePartitions() {
if (MapUtils.isNotEmpty(idToLiteralExprValues)) {
return idToLiteralExprValues.entrySet().stream()
.filter(x -> x.getValue().stream().anyMatch(LiteralExpr::isConstantNull))
.map(Map.Entry::getKey)
.collect(Collectors.toList());
.collect(Collectors.toSet());
} else if (MapUtils.isNotEmpty(idToMultiLiteralExprValues)) {
// only if all partition columns are NULL
return idToMultiLiteralExprValues.entrySet().stream()
.filter(x -> x.getValue().stream().anyMatch(y -> y.stream().allMatch(LiteralExpr::isConstantNull)))
.map(Map.Entry::getKey)
.collect(Collectors.toList());
.collect(Collectors.toSet());
} else {
return Lists.newArrayList();
return Sets.newHashSet();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.validation.constraints.NotNull;

/*
Expand Down Expand Up @@ -258,7 +259,7 @@ public List<Long> getSortedPartitions(boolean asc) {
* Return the partitions that contains NULL partition values
* e.g. PARTITION p_null VALUES IN (NULL)
*/
public List<Long> getNullValuePartitions() {
public Set<Long> getNullValuePartitions() {
throw new NotImplementedException("not reachable");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,11 @@ public List<Long> getSortedPartitions(boolean asc) {
* It's a little bit tricky, as that partition might contain NULL, or might not.
*/
@Override
public List<Long> getNullValuePartitions() {
public Set<Long> getNullValuePartitions() {
return idToRange.entrySet().stream()
.filter(x -> x.getValue().lowerEndpoint().isMinValue())
.map(Map.Entry::getKey)
.collect(Collectors.toList());
.collect(Collectors.toSet());
}

// get a sorted range list, exclude partitions which ids are in 'excludePartitionIds'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private OptExpression optimizeWithPartitionPrune(OptExpression optExpression,
List<Partition> nonEmpty = table.getNonEmptyPartitions();
Set<Long> nonEmptyPartitionIds = nonEmpty.stream().map(Partition::getId).collect(Collectors.toSet());
PartitionInfo partitionInfo = table.getPartitionInfo();
List<Long> nullPartitions = partitionInfo.getNullValuePartitions();
Set<Long> nullPartitions = partitionInfo.getNullValuePartitions();

List<Long> pruned = Lists.newArrayList();
if (hasMinMax.first) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.List;
import java.util.Set;

import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -366,7 +366,7 @@ public void testMinMaxPrune_NullValuePartition() throws Exception {
{
OlapTable t1 = (OlapTable) starRocksAssert.getTable("test", "t1_list");
PartitionInfo partitionInfo = t1.getPartitionInfo();
List<Long> nullValuePartitions = partitionInfo.getNullValuePartitions();
Set<Long> nullValuePartitions = partitionInfo.getNullValuePartitions();
Assert.assertEquals(1, nullValuePartitions.size());
}

Expand All @@ -383,7 +383,7 @@ public void testMinMaxPrune_NullValuePartition() throws Exception {
OlapTable t3 = (OlapTable) starRocksAssert.getTable("test", "t3_composite");
PartitionInfo partitionInfo = t3.getPartitionInfo();

List<Long> nullValuePartitions = partitionInfo.getNullValuePartitions();
Set<Long> nullValuePartitions = partitionInfo.getNullValuePartitions();
Assert.assertEquals(0, nullValuePartitions.size());

starRocksAssert.ddl("alter table t3_composite add partition pnull values in ((NULL, NULL))");
Expand All @@ -402,7 +402,7 @@ public void testMinMaxPrune_NullValuePartition() throws Exception {
{
OlapTable t2 = (OlapTable) starRocksAssert.getTable("test", "t2_range");
PartitionInfo partitionInfo = t2.getPartitionInfo();
List<Long> nullValuePartitions = partitionInfo.getNullValuePartitions();
Set<Long> nullValuePartitions = partitionInfo.getNullValuePartitions();
Assert.assertEquals(1, nullValuePartitions.size());
}

Expand Down

0 comments on commit d9982da

Please sign in to comment.