use of com.pingcap.tikv.expression.visitor.IndexRangeSetBuilder in project tispark by pingcap.
the class PredicateUtils method expressionToPoints.
/**
* Turn access conditions into list of points Each condition is bound to single key We pick up
* single condition for each index key and disregard if multiple EQ conditions in DNF
*
* @param pointPredicates expressions that convertible to access points
* @return access points for each index
*/
private static List<Key> expressionToPoints(List<Expression> pointPredicates, TiTableInfo table, TiIndexInfo index) {
requireNonNull(pointPredicates, "pointPredicates cannot be null");
List<Key> resultKeys = new ArrayList<>();
IndexRangeSetBuilder indexRangeBuilder = new IndexRangeSetBuilder(table, index);
for (int i = 0; i < pointPredicates.size(); i++) {
Expression predicate = pointPredicates.get(i);
try {
// each expr will be expand to one or more points
Set<Range<TypedKey>> ranges = indexRangeBuilder.buildRange(predicate).asRanges();
List<Key> points = rangesToPoint(ranges);
resultKeys = joinKeys(resultKeys, points);
} catch (Exception e) {
throw new TiExpressionException(String.format("Error converting access points %s", predicate), e);
}
}
return resultKeys;
}
use of com.pingcap.tikv.expression.visitor.IndexRangeSetBuilder in project tispark by pingcap.
the class PredicateUtils method expressionToIndexRanges.
/**
* Build index ranges from access points and access conditions
*
* @param pointPredicates conditions converting to a single point access
* @param rangePredicate conditions converting to a range
* @return Index Range for scan
*/
public static List<IndexRange> expressionToIndexRanges(List<Expression> pointPredicates, Optional<Expression> rangePredicate, TiTableInfo table, TiIndexInfo index) {
requireNonNull(pointPredicates, "pointPredicates is null");
requireNonNull(rangePredicate, "rangePredicate is null");
ImmutableList.Builder<IndexRange> builder = ImmutableList.builder();
IndexRangeSetBuilder indexRangeBuilder = new IndexRangeSetBuilder(table, index);
if (pointPredicates.size() != 0) {
List<Key> pointKeys = expressionToPoints(pointPredicates, table, index);
for (Key key : pointKeys) {
if (rangePredicate.isPresent()) {
Set<Range<TypedKey>> ranges = indexRangeBuilder.buildRange(rangePredicate.get()).asRanges();
for (Range<TypedKey> range : ranges) {
builder.add(new IndexRange(key, range));
}
} else {
// no predicates with point keys leads to empty range encoding
builder.add(new IndexRange(key, null));
}
}
} else {
if (rangePredicate.isPresent()) {
Set<Range<TypedKey>> ranges = indexRangeBuilder.buildRange(rangePredicate.get()).asRanges();
for (Range<TypedKey> range : ranges) {
builder.add(new IndexRange(null, range));
}
} else {
// no filter at all means full range
builder.add(new IndexRange(null, Range.all()));
}
}
return builder.build();
}
Aggregations