use of com.pingcap.tikv.key.IntHandle in project tispark by pingcap.
the class TableCodecV2Test method testHandle.
@Test
public void testHandle() {
TestCase testCase = TestCase.createNew(new int[] { 128, 0, 1, 0, 0, 0, 10, 1, 0, 1 }, MetaUtils.TableBuilder.newBuilder().name("t").addColumn("pk", IntegerType.BIGINT, true, -1).addColumn("c1", IntegerType.BIGINT, false, 10).setPkHandle(true).build(), new IntHandle(10000L), new Object[] { new IntHandle(10000L), 1L });
testCase.test();
}
use of com.pingcap.tikv.key.IntHandle in project tispark by pingcap.
the class RangeSplitterTest method groupByAndSortHandlesByRegionIdTest.
@Test
public void groupByAndSortHandlesByRegionIdTest() {
final long tableId = 1;
List<Handle> handles = new ArrayList<>();
handles.add(new IntHandle(1));
handles.add(new IntHandle(5));
handles.add(new IntHandle(4));
handles.add(new IntHandle(3));
handles.add(new IntHandle(10));
handles.add(new IntHandle(11));
handles.add(new IntHandle(12));
handles.add(new IntHandle(2));
handles.add(new IntHandle(100));
handles.add(new IntHandle(101));
handles.add(new IntHandle(99));
handles.add(new IntHandle(88));
handles.add(new IntHandle(-1));
handles.add(new IntHandle(-255));
handles.add(new IntHandle(-100));
handles.add(new IntHandle(-99));
handles.add(new IntHandle(-98));
handles.add(new IntHandle(Long.MIN_VALUE));
handles.add(new IntHandle(8960));
handles.add(new IntHandle(8959));
handles.add(new IntHandle(19999));
handles.add(new IntHandle(15001));
handles.add(new IntHandle(99999999999L));
handles.add(new IntHandle(Long.MAX_VALUE));
MockRegionManager mgr = new MockRegionManager(ImmutableList.of(keyRangeByHandle(tableId, null, Status.EQUAL, -100L, Status.EQUAL), keyRangeByHandle(tableId, -100L, Status.EQUAL, 10L, Status.GREATER), keyRangeByHandle(tableId, 10L, Status.GREATER, 50L, Status.EQUAL), keyRangeByHandle(tableId, 50L, Status.EQUAL, 100L, Status.GREATER), keyRangeByHandle(tableId, 100L, Status.GREATER, 9000L, Status.LESS), keyRangeByHandle(tableId, 0x2300L, /*8960*/
Status.LESS, 16000L, Status.EQUAL), keyRangeByHandle(tableId, 16000L, Status.EQUAL, null, Status.EQUAL)));
TLongObjectHashMap<List<Handle>> result = new TLongObjectHashMap<>();
RangeSplitter.newSplitter(mgr).groupByAndSortHandlesByRegionId(tableId, handles).forEach((k, v) -> result.put(k.first.getId(), v));
assertEquals(2, result.get(0).size());
assertEquals(10, result.get(1).size());
assertEquals(2, result.get(2).size());
assertEquals(3, result.get(3).size());
assertEquals(2, result.get(4).size());
assertEquals(2, result.get(5).size());
assertEquals(3, result.get(6).size());
}
use of com.pingcap.tikv.key.IntHandle in project tispark by pingcap.
the class RangeSplitterTest method splitAndSortHandlesByRegionTest.
@Test
public void splitAndSortHandlesByRegionTest() {
final long tableId = 1;
List<Handle> handles = new ArrayList<>();
handles.add(new IntHandle(1));
handles.add(new IntHandle(5));
handles.add(new IntHandle(4));
handles.add(new IntHandle(3));
handles.add(new IntHandle(10));
handles.add(new IntHandle(2));
handles.add(new IntHandle(100));
handles.add(new IntHandle(101));
handles.add(new IntHandle(99));
handles.add(new IntHandle(88));
handles.add(new IntHandle(-1));
handles.add(new IntHandle(-255));
handles.add(new IntHandle(-100));
handles.add(new IntHandle(-99));
handles.add(new IntHandle(-98));
handles.add(new IntHandle(Long.MIN_VALUE));
handles.add(new IntHandle(8960));
handles.add(new IntHandle(8959));
handles.add(new IntHandle(19999));
handles.add(new IntHandle(15001));
MockRegionManager mgr = new MockRegionManager(ImmutableList.of(keyRangeByHandle(tableId, null, Status.EQUAL, -100L, Status.EQUAL), keyRangeByHandle(tableId, -100L, Status.EQUAL, 10L, Status.GREATER), keyRangeByHandle(tableId, 10L, Status.GREATER, 50L, Status.EQUAL), keyRangeByHandle(tableId, 50L, Status.EQUAL, 100L, Status.GREATER), keyRangeByHandle(tableId, 100L, Status.GREATER, 9000L, Status.LESS), keyRangeByHandle(tableId, 0x2300L, /*8960*/
Status.LESS, 16000L, Status.EQUAL), keyRangeByHandle(tableId, 16000L, Status.EQUAL, null, Status.EQUAL)));
RangeSplitter s = RangeSplitter.newSplitter(mgr);
List<RangeSplitter.RegionTask> tasks = new ArrayList<>(s.splitAndSortHandlesByRegion(ImmutableList.of(tableId), handles));
tasks.sort((l, r) -> {
Long regionIdLeft = l.getRegion().getId();
Long regionIdRight = r.getRegion().getId();
return regionIdLeft.compareTo(regionIdRight);
});
// [-INF, -100): [Long.MIN_VALUE, Long.MIN_VALUE + 1), [-255, -254)
assertEquals(tasks.get(0).getRegion().getId(), 0);
assertEquals(tasks.get(0).getRanges().size(), 2);
assertEquals(tasks.get(0).getRanges().get(0), keyRangeByHandle(tableId, Long.MIN_VALUE, Long.MIN_VALUE + 1));
assertEquals(tasks.get(0).getRanges().get(1), keyRangeByHandle(tableId, -255L, -254L));
// [-100, 10.x): [-100, -97), [-1, 0), [1, 6), [10, 11)
assertEquals(tasks.get(1).getRegion().getId(), 1);
assertEquals(tasks.get(1).getRanges().size(), 4);
assertEquals(tasks.get(1).getRanges().get(0), keyRangeByHandle(tableId, -100L, -97L));
assertEquals(tasks.get(1).getRanges().get(1), keyRangeByHandle(tableId, -1L, 0L));
assertEquals(tasks.get(1).getRanges().get(2), keyRangeByHandle(tableId, 1L, 6L));
assertEquals(tasks.get(1).getRanges().get(3), keyRangeByHandle(tableId, 10L, 11L));
// [10.x, 50): empty
// [50, 100.x): [88, 89) [99, 101)
assertEquals(tasks.get(2).getRegion().getId(), 3);
assertEquals(tasks.get(2).getRanges().size(), 2);
assertEquals(tasks.get(2).getRanges().get(0), keyRangeByHandle(tableId, 88L, 89L));
assertEquals(tasks.get(2).getRanges().get(1), keyRangeByHandle(tableId, 99L, 101L));
// [100.x, less than 8960): [101, 102) [8959, 8960)
assertEquals(tasks.get(3).getRegion().getId(), 4);
assertEquals(tasks.get(3).getRanges().size(), 2);
assertEquals(tasks.get(3).getRanges().get(0), keyRangeByHandle(tableId, 101L, 102L));
assertEquals(tasks.get(3).getRanges().get(1), keyRangeByHandle(tableId, 8959L, 8960L));
// [less than 8960, 16000): [9000, 9001), [15001, 15002)
assertEquals(tasks.get(4).getRegion().getId(), 5);
assertEquals(tasks.get(4).getRanges().size(), 2);
assertEquals(tasks.get(4).getRanges().get(0), keyRangeByHandle(tableId, 8960L, 8961L));
assertEquals(tasks.get(4).getRanges().get(1), keyRangeByHandle(tableId, 15001L, 15002L));
// [16000, INF): [19999, 20000)
assertEquals(tasks.get(5).getRegion().getId(), 6);
assertEquals(tasks.get(5).getRanges().size(), 1);
assertEquals(tasks.get(5).getRanges().get(0), keyRangeByHandle(tableId, 19999L, 20000L));
}
use of com.pingcap.tikv.key.IntHandle in project tispark by pingcap.
the class CoprocessorIterator method getHandleIterator.
/**
* Build a DAGIterator from TiDAGRequest and region tasks to get handles
*
* <p>When we use getHandleIterator, we must be preforming a IndexScan.
*
* @param req TiDAGRequest built
* @param regionTasks a list or RegionTask each contains a task on a single region
* @param session TiSession
* @return a DAGIterator to be processed
*/
public static CoprocessorIterator<Handle> getHandleIterator(TiDAGRequest req, List<RegionTask> regionTasks, TiSession session) {
TiDAGRequest dagRequest = req.copy();
// set encode type to TypeDefault because currently, only
// CoprocessorIterator<TiChunk> support TypeChunk and TypeCHBlock encode type
dagRequest.setEncodeType(EncodeType.TypeDefault);
return new DAGIterator<Handle>(dagRequest.buildIndexScan(), regionTasks, session, SchemaInfer.create(dagRequest, true), dagRequest.getPushDownType(), dagRequest.getStoreType(), dagRequest.getStartTs().getVersion()) {
@Override
public Handle next() {
Row row = rowReader.readRow(handleTypes);
Object[] data = new Object[handleTypes.length];
for (int i = 0; i < handleTypes.length; i++) {
data[i] = row.get(i, handleTypes[i]);
}
if (handleTypes.length == 1 && handleTypes[0] == IntegerType.BIGINT) {
return new IntHandle((long) data[0]);
} else {
return CommonHandle.newCommonHandle(handleTypes, data);
}
}
};
}
use of com.pingcap.tikv.key.IntHandle in project tispark by pingcap.
the class TiKVScanAnalyzerTest method testKeyRangeGenWithNoFilterTest.
@Test
public void testKeyRangeGenWithNoFilterTest() {
TiTableInfo table = createTableWithPrefix();
TiIndexInfo index = TiIndexInfo.generateFakePrimaryKeyIndex(table);
TiKVScanAnalyzer scanBuilder = new TiKVScanAnalyzer();
TiKVScanAnalyzer.TiKVScanPlan scanPlan = scanBuilder.buildIndexScan(ImmutableList.of(), ImmutableList.of(), index, table, null, false);
ByteString startKey = RowKey.toRowKey(table.getId(), new IntHandle(Long.MIN_VALUE)).toByteString();
ByteString endKey = RowKey.createBeyondMax(table.getId()).toByteString();
assertEquals(1, scanPlan.getKeyRanges().size());
assertEquals(startKey, scanPlan.getKeyRanges().get(table.getId()).get(0).getStart());
assertEquals(endKey, scanPlan.getKeyRanges().get(table.getId()).get(0).getEnd());
}
Aggregations