Search in sources :

Example 1 with PrunedPartitionBuilder

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;
}
Also used : TypedKey(com.pingcap.tikv.key.TypedKey) NormalizedPredicate(com.pingcap.tikv.expression.ComparisonBinaryExpression.NormalizedPredicate) PrunedPartitionBuilder(com.pingcap.tikv.expression.visitor.PrunedPartitionBuilder) HashSet(java.util.HashSet)

Aggregations

NormalizedPredicate (com.pingcap.tikv.expression.ComparisonBinaryExpression.NormalizedPredicate)1 PrunedPartitionBuilder (com.pingcap.tikv.expression.visitor.PrunedPartitionBuilder)1 TypedKey (com.pingcap.tikv.key.TypedKey)1 HashSet (java.util.HashSet)1