Search in sources :

Example 1 with IndexMatcher

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));
}
Also used : TiIndexColumn(com.pingcap.tikv.meta.TiIndexColumn) IndexMatcher(com.pingcap.tikv.expression.visitor.IndexMatcher) Expression(com.pingcap.tikv.expression.Expression) Constant(com.pingcap.tikv.expression.Constant) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) ColumnRef(com.pingcap.tikv.expression.ColumnRef) TiIndexInfo(com.pingcap.tikv.meta.TiIndexInfo) Test(org.junit.Test)

Example 2 with IndexMatcher

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));
}
Also used : TiIndexColumn(com.pingcap.tikv.meta.TiIndexColumn) IndexMatcher(com.pingcap.tikv.expression.visitor.IndexMatcher) Expression(com.pingcap.tikv.expression.Expression) Constant(com.pingcap.tikv.expression.Constant) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) ColumnRef(com.pingcap.tikv.expression.ColumnRef) TiIndexInfo(com.pingcap.tikv.meta.TiIndexInfo) Test(org.junit.Test)

Aggregations

ColumnRef (com.pingcap.tikv.expression.ColumnRef)2 Constant (com.pingcap.tikv.expression.Constant)2 Expression (com.pingcap.tikv.expression.Expression)2 IndexMatcher (com.pingcap.tikv.expression.visitor.IndexMatcher)2 TiIndexColumn (com.pingcap.tikv.meta.TiIndexColumn)2 TiIndexInfo (com.pingcap.tikv.meta.TiIndexInfo)2 TiTableInfo (com.pingcap.tikv.meta.TiTableInfo)2 Test (org.junit.Test)2