Search in sources :

Example 6 with TiDAGRequest

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);
            }
        }
    };
}
Also used : IntHandle(com.pingcap.tikv.key.IntHandle) Row(com.pingcap.tikv.row.Row) TiDAGRequest(com.pingcap.tikv.meta.TiDAGRequest)

Example 7 with TiDAGRequest

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]));
        }
    };
}
Also used : DataType(com.pingcap.tikv.types.DataType) TiDAGRequest(com.pingcap.tikv.meta.TiDAGRequest)

Example 8 with TiDAGRequest

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);
}
Also used : TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) KeyRange(org.tikv.kvproto.Coprocessor.KeyRange) ArrayList(java.util.ArrayList) TiKVScanAnalyzer(com.pingcap.tikv.predicates.TiKVScanAnalyzer) TiDAGRequest(com.pingcap.tikv.meta.TiDAGRequest)

Example 9 with TiDAGRequest

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());
    }
}
Also used : DataType(com.pingcap.tikv.types.DataType) TiDAGRequest(com.pingcap.tikv.meta.TiDAGRequest) Test(org.junit.Test)

Example 10 with TiDAGRequest

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());
}
Also used : DataType(com.pingcap.tikv.types.DataType) TiDAGRequest(com.pingcap.tikv.meta.TiDAGRequest) Test(org.junit.Test)

Aggregations

TiDAGRequest (com.pingcap.tikv.meta.TiDAGRequest)11 DataType (com.pingcap.tikv.types.DataType)5 Test (org.junit.Test)4 TiTableInfo (com.pingcap.tikv.meta.TiTableInfo)3 Row (com.pingcap.tikv.row.Row)3 ArrayList (java.util.ArrayList)3 TiChunk (com.pingcap.tikv.columnar.TiChunk)2 KeyRange (org.tikv.kvproto.Coprocessor.KeyRange)2 Context (com.alibaba.citrus.turbine.Context)1 Lists (com.pingcap.com.google.common.collect.Lists)1 Maps (com.pingcap.com.google.common.collect.Maps)1 MockServerTest (com.pingcap.tikv.MockServerTest)1 Snapshot (com.pingcap.tikv.Snapshot)1 TiConfiguration (com.pingcap.tikv.TiConfiguration)1 TiSession (com.pingcap.tikv.TiSession)1 Catalog (com.pingcap.tikv.catalog.Catalog)1 CodecDataInput (com.pingcap.tikv.codec.CodecDataInput)1 CodecDataOutput (com.pingcap.tikv.codec.CodecDataOutput)1 BatchedTiChunkColumnVector (com.pingcap.tikv.columnar.BatchedTiChunkColumnVector)1 TiChunkColumnVector (com.pingcap.tikv.columnar.TiChunkColumnVector)1