use of com.pingcap.tikv.expression.visitor.IndexMatcher in project tispark by pingcap.
the class IndexMatcherTest method matchOnlyEq.
@Test
public void matchOnlyEq() {
TiTableInfo table = createTable();
TiIndexInfo index = table.getIndices().get(0);
TiIndexColumn col = index.getIndexColumns().get(0);
IndexMatcher matcher = IndexMatcher.equalOnlyMatcher(col);
Constant c0 = Constant.create(0, IntegerType.INT);
Constant c1 = Constant.create(1, IntegerType.INT);
Constant c2 = Constant.create(2, IntegerType.INT);
ColumnRef col1 = ColumnRef.create("c1", table);
ColumnRef col2 = ColumnRef.create("c2", table);
// index col = c1, long
Expression cond = equal(col1, c1);
assertTrue(matcher.match(cond));
cond = equal(c1, col1);
assertTrue(matcher.match(cond));
cond = equal(col2, col1);
assertFalse(matcher.match(cond));
cond = equal(c1, c1);
assertFalse(matcher.match(cond));
cond = and(equal(c1, col1), equal(col1, c2));
assertFalse(matcher.match(cond));
cond = or(equal(c1, col1), equal(col1, c2));
assertTrue(matcher.match(cond));
cond = lessEqual(c0, col1);
assertFalse(matcher.match(cond));
}
use of com.pingcap.tikv.expression.visitor.IndexMatcher in project tispark by pingcap.
the class IndexMatcherTest method matchAll.
@Test
public void matchAll() {
TiTableInfo table = createTable();
TiIndexInfo index = table.getIndices().get(0);
TiIndexColumn col = index.getIndexColumns().get(0);
IndexMatcher matcher = IndexMatcher.matcher(col);
Constant c1 = Constant.create(1, IntegerType.INT);
Constant c2 = Constant.create(2, IntegerType.INT);
ColumnRef col1 = ColumnRef.create("c1", table);
// index col = c1, long
Expression cond = lessEqual(col1, c1);
assertTrue(matcher.match(cond));
cond = greaterEqual(c1, col1);
assertTrue(matcher.match(cond));
cond = lessThan(ColumnRef.create("c2", table), ColumnRef.create("c1", table));
assertFalse(matcher.match(cond));
cond = lessThan(c1, c1);
assertFalse(matcher.match(cond));
cond = and(lessThan(c1, col1), lessThan(col1, c2));
assertTrue(matcher.match(cond));
cond = or(lessThan(c1, col1), lessThan(col1, c2));
assertTrue(matcher.match(cond));
}
Aggregations