Skip to content

Commit

Permalink
[BugFix] [BackPort] Fix special partition error with NULL predicate (#…
Browse files Browse the repository at this point in the history
…34436) (#35425)

Signed-off-by: Seaven <[email protected]>
Co-authored-by: Seaven <[email protected]>
  • Loading branch information
LiShuMing and Seaven authored Nov 21, 2023
1 parent 940e9b8 commit 5d8438a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import com.starrocks.common.AnalysisException;
import com.starrocks.connector.PartitionUtil;
import com.starrocks.qe.ConnectContext;
import com.starrocks.server.GlobalStateMgr;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -123,17 +122,16 @@ private List<Long> prune(RangeMap<PartitionKey, Long> rangeMap,
&& lowerBound != null && upperBound != null
&& 0 == lowerBound.compareLiteral(upperBound)) {

LiteralExpr lowerBoundExpr = filter.getLowerBound(isConvertToDate);
LiteralExpr upperBoundExpr = filter.getUpperBound(isConvertToDate);

// eg: [10, 10], [null, null]
if (lowerBoundExpr instanceof NullLiteral && upperBoundExpr instanceof NullLiteral) {
if (lowerBound instanceof NullLiteral && upperBound instanceof NullLiteral) {
// replace Null with min value
LiteralExpr minKeyValue = LiteralExpr.createInfinity(
Type.fromPrimitiveType(keyColumn.getPrimitiveType()), false);
minKey.pushColumn(minKeyValue, keyColumn.getPrimitiveType());
maxKey.pushColumn(minKeyValue, keyColumn.getPrimitiveType());
} else {
LiteralExpr lowerBoundExpr = filter.getLowerBound(isConvertToDate);
LiteralExpr upperBoundExpr = filter.getUpperBound(isConvertToDate);
minKey.pushColumn(lowerBoundExpr, keyColumn.getPrimitiveType());
maxKey.pushColumn(upperBoundExpr, keyColumn.getPrimitiveType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ private static List<Long> listPartitionPrune(OlapTable olapTable, ListPartitionI
} catch (AnalysisException e) {
LOG.warn("PartitionPrune Failed. ", e);
}
return null;
return specifyPartitionIds;
}

private static List<Long> rangePartitionPrune(OlapTable olapTable, RangePartitionInfo partitionInfo,
Expand All @@ -343,7 +343,7 @@ private static List<Long> rangePartitionPrune(OlapTable olapTable, RangePartitio
} catch (Exception e) {
LOG.warn("PartitionPrune Failed. ", e);
}
return null;
return Lists.newArrayList(keyRangeById.keySet());
}

private static boolean isNeedFurtherPrune(List<Long> candidatePartitions, LogicalOlapScanOperator olapScanOperator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,11 @@ public void testCastStringWithWhitSpace() throws Exception {
plan = getFragmentPlan(sql);
assertContains(plan, "PREDICATES: 1: k1 = CAST(' -111 2 ' AS INT)");
}

@Test
public void testNullException() throws Exception {
String sql = "select * from ptest partition(p202007) where d2 is null";
String plan = getFragmentPlan(sql);
assertCContains(plan, "0:EMPTYSET");
}
}

0 comments on commit 5d8438a

Please sign in to comment.