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());
}
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());
}
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");
}
}
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());
}
Aggregations