Search in sources :

Example 21 with TiTableInfo

use of com.pingcap.tikv.meta.TiTableInfo in project tispark by pingcap.

the class TiKVScanAnalyzerTest method extractConditionsTest.

@Test
public void extractConditionsTest() {
    TiTableInfo table = createTable();
    TiIndexInfo index = table.getIndices().get(0);
    Expression eq1 = equal(ColumnRef.create("c1", table), Constant.create(0, IntegerType.INT));
    Expression eq2 = equal(ColumnRef.create("c2", table), Constant.create("test", StringType.VARCHAR));
    Expression le1 = lessEqual(ColumnRef.create("c3", table), Constant.create("fxxx", StringType.VARCHAR));
    // Last one should be pushed back
    Expression eq3 = equal(ColumnRef.create("c4", table), Constant.create("fxxx", StringType.VARCHAR));
    List<Expression> exprs = ImmutableList.of(eq1, eq2, le1, eq3);
    ScanSpec result = TiKVScanAnalyzer.extractConditions(exprs, table, index);
    assertEquals(1, result.getResidualPredicates().size());
    assertEquals(eq3, result.getResidualPredicates().toArray()[0]);
    assertEquals(2, result.getPointPredicates().size());
    assertEquals(eq1, result.getPointPredicates().get(0));
    assertEquals(eq2, result.getPointPredicates().get(1));
    assertTrue(result.getRangePredicate().isPresent());
    assertEquals(le1, result.getRangePredicate().get());
}
Also used : Expression(com.pingcap.tikv.expression.Expression) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) TiIndexInfo(com.pingcap.tikv.meta.TiIndexInfo) Test(org.junit.Test)

Example 22 with TiTableInfo

use of com.pingcap.tikv.meta.TiTableInfo in project tispark by pingcap.

the class TiKVScanAnalyzerTest method buildTableScanKeyRangeTest.

@Test
public void buildTableScanKeyRangeTest() {
    // This test also covers partitioned table. When it comes to partitioned table
    // we need to build key range from table ids(collect from partition definitions)
    TiTableInfo table = createTableWithIndex(6, 5);
    TiIndexInfo pkIndex = TiIndexInfo.generateFakePrimaryKeyIndex(table);
    Expression eq1 = lessThan(ColumnRef.create("c1", table), Constant.create(3, IntegerType.INT));
    List<Expression> exprs = ImmutableList.of(eq1);
    ScanSpec result = TiKVScanAnalyzer.extractConditions(exprs, table, pkIndex);
    List<IndexRange> irs = expressionToIndexRanges(result.getPointPredicates(), result.getRangePredicate(), table, pkIndex);
    TiKVScanAnalyzer scanAnalyzer = new TiKVScanAnalyzer();
    Map<Long, List<Coprocessor.KeyRange>> keyRanges = scanAnalyzer.buildTableScanKeyRange(table, irs, null);
    assertEquals(keyRanges.size(), 1);
    Coprocessor.KeyRange keyRange = keyRanges.get(table.getId()).get(0);
    assertEquals(ByteString.copyFrom(new byte[] { 116, -128, 0, 0, 0, 0, 0, 0, 6, 95, 114, 0, 0, 0, 0, 0, 0, 0, 0 }), keyRange.getStart());
    assertEquals(ByteString.copyFrom(new byte[] { 116, -128, 0, 0, 0, 0, 0, 0, 6, 95, 115, 0, 0, 0, 0, 0, 0, 0, 0 }), keyRange.getEnd());
}
Also used : Coprocessor(org.tikv.kvproto.Coprocessor) Expression(com.pingcap.tikv.expression.Expression) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) TiIndexInfo(com.pingcap.tikv.meta.TiIndexInfo) Test(org.junit.Test)

Example 23 with TiTableInfo

use of com.pingcap.tikv.meta.TiTableInfo in project tispark by pingcap.

the class DAGIteratorTest method staleEpochTest.

@Test
public void staleEpochTest() {
    Metapb.Store store = Metapb.Store.newBuilder().setAddress(LOCAL_ADDR + ":" + port).setId(1).setState(Metapb.StoreState.Up).setVersion(Version.RESOLVE_LOCK_V4).build();
    TiTableInfo table = createTable();
    TiDAGRequest req = new TiDAGRequest(PushDownType.NORMAL);
    req.setTableInfo(table);
    req.addRequiredColumn(ColumnRef.create("c1", IntegerType.INT));
    req.addRequiredColumn(ColumnRef.create("c2", StringType.VARCHAR));
    req.setStartTs(new TiTimestamp(0, 1));
    List<KeyRange> keyRanges = ImmutableList.of(createByteStringRange(ByteString.copyFromUtf8("key1"), ByteString.copyFromUtf8("key4")));
    pdServer.addGetRegionResp(GrpcUtils.makeGetRegionResponse(pdServer.getClusterId(), region.getMeta()));
    pdServer.addGetStoreResp(GrpcUtils.makeGetStoreResponse(pdServer.getClusterId(), store));
    server.putError("key1", KVMockServer.STALE_EPOCH);
    CodecDataOutput cdo = new CodecDataOutput();
    IntegerCodec.writeLongFully(cdo, 666, false);
    BytesCodec.writeBytesFully(cdo, "value1".getBytes());
    server.put("key1", cdo.toByteString());
    List<RegionTask> tasks = ImmutableList.of(RegionTask.newInstance(region, store, keyRanges));
    CoprocessorIterator<Row> iter = CoprocessorIterator.getRowIterator(req, tasks, session);
    if (!iter.hasNext()) {
        assertEquals("iterator has next should be true", true, false);
    } else {
        Row r = iter.next();
        SchemaInfer infer = SchemaInfer.create(req);
        assertEquals(r.get(0, infer.getType(0)), 666L);
        assertEquals(r.get(1, infer.getType(1)), "value1");
    }
}
Also used : TiTimestamp(com.pingcap.tikv.meta.TiTimestamp) KeyRange(org.tikv.kvproto.Coprocessor.KeyRange) TiDAGRequest(com.pingcap.tikv.meta.TiDAGRequest) RegionTask(com.pingcap.tikv.util.RangeSplitter.RegionTask) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) CodecDataOutput(com.pingcap.tikv.codec.CodecDataOutput) Row(com.pingcap.tikv.row.Row) SchemaInfer(com.pingcap.tikv.operation.SchemaInfer) Metapb(org.tikv.kvproto.Metapb) MockServerTest(com.pingcap.tikv.MockServerTest) Test(org.junit.Test)

Example 24 with TiTableInfo

use of com.pingcap.tikv.meta.TiTableInfo in project tispark by pingcap.

the class ComparisonBinaryExpressionTest method normalizeTest.

@Test
public void normalizeTest() {
    TiTableInfo table = createTable();
    ColumnRef col1 = ColumnRef.create("c1", table);
    Constant c1 = Constant.create(1, IntegerType.INT);
    // index col = c1, long
    ComparisonBinaryExpression cond = equal(col1, c1);
    verifyNormalize(cond, "c1", 1, IntegerType.INT, Operator.EQUAL);
    cond = lessEqual(c1, col1);
    verifyNormalize(cond, "c1", 1, IntegerType.INT, Operator.GREATER_EQUAL);
    cond = lessThan(c1, col1);
    verifyNormalize(cond, "c1", 1, IntegerType.INT, Operator.GREATER_THAN);
    cond = greaterEqual(c1, col1);
    verifyNormalize(cond, "c1", 1, IntegerType.INT, Operator.LESS_EQUAL);
    cond = greaterThan(c1, col1);
    verifyNormalize(cond, "c1", 1, IntegerType.INT, Operator.LESS_THAN);
    cond = equal(c1, col1);
    verifyNormalize(cond, "c1", 1, IntegerType.INT, Operator.EQUAL);
    cond = notEqual(c1, col1);
    verifyNormalize(cond, "c1", 1, IntegerType.INT, Operator.NOT_EQUAL);
    cond = lessEqual(col1, c1);
    verifyNormalize(cond, "c1", 1, IntegerType.INT, Operator.LESS_EQUAL);
    cond = equal(divide(col1, c1), c1);
    assertNull(cond.normalize());
}
Also used : TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) Test(org.junit.Test)

Aggregations

TiTableInfo (com.pingcap.tikv.meta.TiTableInfo)24 Test (org.junit.Test)17 Expression (com.pingcap.tikv.expression.Expression)11 TiIndexInfo (com.pingcap.tikv.meta.TiIndexInfo)9 ColumnRef (com.pingcap.tikv.expression.ColumnRef)5 ImmutableList (com.google.common.collect.ImmutableList)4 Constant (com.pingcap.tikv.expression.Constant)4 TiDAGRequest (com.pingcap.tikv.meta.TiDAGRequest)4 ArrayList (java.util.ArrayList)4 TiDBInfo (com.pingcap.tikv.meta.TiDBInfo)3 List (java.util.List)3 Context (com.alibaba.citrus.turbine.Context)2 Range (com.google.common.collect.Range)2 ByteString (com.google.protobuf.ByteString)2 Lists (com.pingcap.com.google.common.collect.Lists)2 Maps (com.pingcap.com.google.common.collect.Maps)2 TiConfiguration (com.pingcap.tikv.TiConfiguration)2 TiSession (com.pingcap.tikv.TiSession)2 Catalog (com.pingcap.tikv.catalog.Catalog)2 IndexMatcher (com.pingcap.tikv.expression.visitor.IndexMatcher)2