use of com.pingcap.tikv.expression.visitor.PrunedPartitionBuilder in project tispark by pingcap.
the class RangeColumnPartitionPruner method visit.
@Override
protected Set<Integer> visit(ComparisonBinaryExpression node, LogicalBinaryExpression parent) {
NormalizedPredicate predicate = node.normalize();
if (predicate == null) {
throw new UnsupportedOperationException(String.format("ComparisonBinaryExpression %s cannot be normalized", node.toString()));
}
String colRefName = predicate.getColumnRef().getName();
List<Expression> partExprs = partExprsPerColumnRef.get(colRefName);
Set<Integer> partDefs = new HashSet<>();
if (partExprs == null) {
switch(parent.getCompType()) {
case OR:
return partDefs;
case AND:
for (int i = 0; i < partsSize; i++) {
partDefs.add(i);
}
return partDefs;
}
}
Objects.requireNonNull(partExprs, "partition expression cannot be null");
for (int i = 0; i < partsSize; i++) {
PrunedPartitionBuilder rangeBuilder = new PrunedPartitionBuilder(ImmutableSet.of(predicate.getColumnRef()));
RangeSet<TypedKey> partExprRange = rangeBuilder.buildRange(partExprs.get(i));
RangeSet<TypedKey> filterRange = rangeBuilder.buildRange(node);
RangeSet<TypedKey> copy = TreeRangeSet.create(partExprRange);
copy.removeAll(filterRange.complement());
// part expr and filter is connected
if (!copy.isEmpty()) {
partDefs.add(i);
}
}
return partDefs;
}
Aggregations