Search in sources :

Example 11 with DataType

use of com.pingcap.tikv.types.DataType in project tispark by pingcap.

the class Codec method decodeOne.

public static Object decodeOne(byte[] colData) {
    if (colData.length <= 1) {
        throw new CodecException("invalid encoded column data, length <=1");
    }
    int flag = colData[0];
    DataType tp;
    switch(flag) {
        case INT_FLAG:
        case UINT_FLAG:
        case VARINT_FLAG:
        case UVARINT_FLAG:
            tp = IntegerType.BIGINT;
            break;
        case FLOATING_FLAG:
            tp = RealType.DOUBLE;
            break;
        case BYTES_FLAG:
        case COMPACT_BYTES_FLAG:
            tp = BytesType.TEXT;
            break;
        case DECIMAL_FLAG:
            tp = DecimalType.DECIMAL;
            break;
        case DURATION_FLAG:
            tp = TimeType.TIME;
            break;
        case JSON_FLAG:
            tp = JsonType.JSON;
            break;
        default:
            throw new CodecException("Unknown type");
    }
    return tp.decode(new CodecDataInput(colData));
}
Also used : DataType(com.pingcap.tikv.types.DataType) CodecException(com.pingcap.tikv.exception.CodecException)

Example 12 with DataType

use of com.pingcap.tikv.types.DataType in project tispark by pingcap.

the class TiColumnInfo method copyWithoutPrimaryKey.

TiColumnInfo copyWithoutPrimaryKey() {
    InternalTypeHolder typeHolder = type.toTypeHolder();
    typeHolder.setFlag(type.getFlag() & (~TiColumnInfo.PK_MASK));
    DataType newType = DataTypeFactory.of(typeHolder);
    return new TiColumnInfo(this.id, this.name, this.offset, newType, this.schemaState, this.originDefaultValue, this.defaultValue, this.defaultValueBit, this.comment, this.version, this.generatedExprString, this.hidden);
}
Also used : DataType(com.pingcap.tikv.types.DataType)

Example 13 with DataType

use of com.pingcap.tikv.types.DataType 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 14 with DataType

use of com.pingcap.tikv.types.DataType in project tispark by pingcap.

the class DefaultRowReader method readRow.

public Row readRow(DataType[] dataTypes) {
    int length = dataTypes.length;
    Row row = ObjectRowImpl.create(length);
    for (int i = 0; i < length; i++) {
        DataType type = dataTypes[i];
        if (type.isNextNull(cdi)) {
            cdi.readUnsignedByte();
            row.setNull(i);
        } else {
            row.set(i, type, type.decode(cdi));
        }
    }
    return row;
}
Also used : DataType(com.pingcap.tikv.types.DataType)

Example 15 with DataType

use of com.pingcap.tikv.types.DataType in project tispark by pingcap.

the class TiKVScanAnalyzerTest method TestCoveringIndex.

@Test
public void TestCoveringIndex() {
    InternalTypeHolder holder = new InternalTypeHolder(MySQLType.TypeVarchar.getTypeCode(), 0, // indicating a prefix type
    3, 0, "", "", ImmutableList.of());
    Map<String, DataType> dataTypeMap = new HashMap<>();
    dataTypeMap.put("id", IntegerType.INT);
    dataTypeMap.put("a", IntegerType.INT);
    dataTypeMap.put("b", IntegerType.INT);
    dataTypeMap.put("c", IntegerType.INT);
    dataTypeMap.put("holder", DataTypeFactory.of(holder));
    Map<String, Integer> offsetMap = new HashMap<>();
    offsetMap.put("id", 0);
    offsetMap.put("a", 1);
    offsetMap.put("b", 2);
    offsetMap.put("c", 3);
    offsetMap.put("holder", 4);
    class test {

        private final String[] columnNames;

        private final String[] indexNames;

        private final int[] indexLens;

        private final boolean isCovering;

        private test(String[] col, String[] idx, int[] idxLen, boolean result) {
            columnNames = col;
            indexNames = idx;
            indexLens = idxLen;
            isCovering = result;
        }

        private String[] getColumnNames() {
            return columnNames;
        }

        private String[] getIndexNames() {
            return indexNames;
        }

        private int[] getIndexLens() {
            return indexLens;
        }
    }
    final test[] tests = { new test(new String[] { "a" }, new String[] { "a" }, new int[] { -1 }, true), new test(new String[] { "a" }, new String[] { "a", "b" }, new int[] { -1, -1 }, true), new test(new String[] { "a", "b" }, new String[] { "b", "a" }, new int[] { -1, -1 }, true), new test(new String[] { "a", "b" }, new String[] { "b", "c" }, new int[] { -1, -1 }, false), new test(new String[] { "holder", "b" }, new String[] { "holder", "b" }, new int[] { 50, -1 }, false), new test(new String[] { "a", "b" }, new String[] { "a", "c" }, new int[] { -1, -1 }, false), new test(new String[] { "id", "a" }, new String[] { "a", "b" }, new int[] { -1, -1 }, true) };
    TiKVScanAnalyzer scanBuilder = new TiKVScanAnalyzer();
    for (test t : tests) {
        List<TiColumnInfo> columns = new ArrayList<>();
        List<TiIndexColumn> indexCols = new ArrayList<>();
        boolean pkIsHandle = false;
        for (int i = 0; i < t.getColumnNames().length; i++) {
            String colName = t.getColumnNames()[i];
            if (colName.equals("id")) {
                pkIsHandle = true;
            }
            columns.add(new TiColumnInfo(offsetMap.get(colName), colName, i, dataTypeMap.get(colName), colName.equals("id")));
        }
        for (int i = 0; i < t.getIndexNames().length; i++) {
            String idxName = t.getIndexNames()[i];
            int idxLen = t.getIndexLens()[i];
            indexCols.add(new TiIndexColumn(CIStr.newCIStr(idxName), offsetMap.get(idxName), idxLen));
        }
        TiIndexInfo indexInfo = new TiIndexInfo(1, CIStr.newCIStr("test_idx"), CIStr.newCIStr("testTable"), ImmutableList.copyOf(indexCols), false, false, SchemaState.StatePublic.getStateCode(), "Test Index", IndexType.IndexTypeBtree.getTypeCode(), false, false);
        boolean isCovering = scanBuilder.isCoveringIndex(columns, indexInfo, pkIsHandle);
        assertEquals(t.isCovering, isCovering);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) InternalTypeHolder(com.pingcap.tikv.meta.TiColumnInfo.InternalTypeHolder) TiIndexColumn(com.pingcap.tikv.meta.TiIndexColumn) DataType(com.pingcap.tikv.types.DataType) TiColumnInfo(com.pingcap.tikv.meta.TiColumnInfo) TiIndexInfo(com.pingcap.tikv.meta.TiIndexInfo) Test(org.junit.Test)

Aggregations

DataType (com.pingcap.tikv.types.DataType)17 TiDAGRequest (com.pingcap.tikv.meta.TiDAGRequest)5 Test (org.junit.Test)5 InternalTypeHolder (com.pingcap.tikv.meta.TiColumnInfo.InternalTypeHolder)3 ByteString (com.google.protobuf.ByteString)2 Expr (com.pingcap.tidb.tipb.Expr)2 CodecDataInput (com.pingcap.tikv.codec.CodecDataInput)2 FuncCallExpr (com.pingcap.tikv.expression.FuncCallExpr)2 TiIndexColumn (com.pingcap.tikv.meta.TiIndexColumn)2 Row (com.pingcap.tikv.row.Row)2 ArrayList (java.util.ArrayList)2 ScalarFuncSig (com.pingcap.tidb.tipb.ScalarFuncSig)1 CodecDataOutput (com.pingcap.tikv.codec.CodecDataOutput)1 BatchedTiChunkColumnVector (com.pingcap.tikv.columnar.BatchedTiChunkColumnVector)1 TiChunk (com.pingcap.tikv.columnar.TiChunk)1 TiChunkColumnVector (com.pingcap.tikv.columnar.TiChunkColumnVector)1 TiRowColumnVector (com.pingcap.tikv.columnar.TiRowColumnVector)1 CHType (com.pingcap.tikv.columnar.datatypes.CHType)1 CodecException (com.pingcap.tikv.exception.CodecException)1 TiExpressionException (com.pingcap.tikv.exception.TiExpressionException)1