use of com.pingcap.tikv.meta.TiDAGRequest 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.meta.TiDAGRequest in project tispark by pingcap.
the class CoprocessorIterator method getRowIterator.
/**
* Build a DAGIterator from TiDAGRequest and region tasks to get rows
*
* <p>When we are preforming a scan request using coveringIndex, {@link
* com.pingcap.tidb.tipb.IndexScan} should be used to read index rows. In other circumstances,
* {@link com.pingcap.tidb.tipb.TableScan} is used to scan table rows.
*
* @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<Row> getRowIterator(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<Row>(dagRequest.buildTableScan(), regionTasks, session, SchemaInfer.create(dagRequest), dagRequest.getPushDownType(), dagRequest.getStoreType(), dagRequest.getStartTs().getVersion()) {
@Override
public Row next() {
return rowReader.readRow(schemaInfer.getTypes().toArray(new DataType[0]));
}
};
}
use of com.pingcap.tikv.meta.TiDAGRequest in project tispark by pingcap.
the class RegionUtils method getRegionTasks.
private static List<RegionTask> getRegionTasks(TiSession session, String databaseName, String tableName) {
requireNonNull(session, "session is null");
requireNonNull(databaseName, "databaseName is null");
requireNonNull(tableName, "tableName is null");
TiTableInfo table = session.getCatalog().getTable(databaseName, tableName);
requireNonNull(table, String.format("Table not found %s.%s", databaseName, tableName));
TiKVScanAnalyzer builder = new TiKVScanAnalyzer();
TiDAGRequest dagRequest = builder.buildTiDAGReq(ImmutableList.of(), ImmutableList.of(), table, session.getTimestamp(), new TiDAGRequest(PushDownType.NORMAL));
List<KeyRange> ranges = new ArrayList<>();
dagRequest.getRangesMaps().forEach((k, v) -> ranges.addAll(v));
return RangeSplitter.newSplitter(session.getRegionManager()).splitRangeByRegion(ranges);
}
use of com.pingcap.tikv.meta.TiDAGRequest in project tispark by pingcap.
the class SchemaInferTest method selectAggWithGroupBySchemaInferTest.
@Test
public void selectAggWithGroupBySchemaInferTest() {
// select sum(number) from t1 group by name;
List<TiDAGRequest> dagRequests = makeSelectDAGReq(simpleGroupBy, complexGroupBy);
for (TiDAGRequest req : dagRequests) {
List<DataType> dataTypes = SchemaInfer.create(req).getTypes();
assertEquals(2, dataTypes.size());
assertEquals(IntegerType.BIGINT.getClass(), dataTypes.get(0).getClass());
assertEquals(IntegerType.BIGINT.getClass(), dataTypes.get(1).getClass());
}
}
use of com.pingcap.tikv.meta.TiDAGRequest in project tispark by pingcap.
the class SchemaInferTest method selectAggSchemaInferTest.
@Test
public void selectAggSchemaInferTest() {
// select sum(number) from t1;
TiDAGRequest tiDAGRequest = new TiDAGRequest(TiDAGRequest.PushDownType.NORMAL);
tiDAGRequest.addRequiredColumn(number);
tiDAGRequest.addAggregate(sum);
tiDAGRequest.setTableInfo(table);
tiDAGRequest.setStartTs(ts);
List<DataType> dataTypes = SchemaInfer.create(tiDAGRequest).getTypes();
assertEquals(1, dataTypes.size());
assertEquals(IntegerType.INT.getClass(), dataTypes.get(0).getClass());
}
Aggregations