Search in sources :

Example 16 with CodecDataOutput

use of com.pingcap.tikv.codec.CodecDataOutput in project tispark by pingcap.

the class IntHandle method encodedAsKey.

@Override
public byte[] encodedAsKey() {
    CodecDataOutput cdo = new CodecDataOutput();
    IntegerType.BIGINT.encode(cdo, DataType.EncodeType.KEY, handle);
    byte[] encoded = cdo.toBytes();
    if (infFlag == 1) {
        return Arrays.copyOf(encoded, encoded.length + 1);
    }
    return encoded;
}
Also used : CodecDataOutput(com.pingcap.tikv.codec.CodecDataOutput)

Example 17 with CodecDataOutput

use of com.pingcap.tikv.codec.CodecDataOutput in project tispark by pingcap.

the class Key method createTypelessMin.

private static Key createTypelessMin() {
    CodecDataOutput cdo = new CodecDataOutput();
    DataType.encodeIndex(cdo);
    return new Key(cdo.toBytes()) {

        @Override
        public String toString() {
            return "MIN";
        }
    };
}
Also used : CodecDataOutput(com.pingcap.tikv.codec.CodecDataOutput)

Example 18 with CodecDataOutput

use of com.pingcap.tikv.codec.CodecDataOutput in project tispark by pingcap.

the class GrpcUtils method encodeKey.

public static ByteString encodeKey(byte[] key) {
    CodecDataOutput cdo = new CodecDataOutput();
    BytesCodec.writeBytes(cdo, key);
    return cdo.toByteString();
}
Also used : CodecDataOutput(com.pingcap.tikv.codec.CodecDataOutput)

Example 19 with CodecDataOutput

use of com.pingcap.tikv.codec.CodecDataOutput 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");
    }
}
Also used : TiTimestamp(com.pingcap.tikv.meta.TiTimestamp) KeyRange(org.tikv.kvproto.Coprocessor.KeyRange) TiDAGRequest(com.pingcap.tikv.meta.TiDAGRequest) RegionTask(com.pingcap.tikv.util.RangeSplitter.RegionTask) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) CodecDataOutput(com.pingcap.tikv.codec.CodecDataOutput) Row(com.pingcap.tikv.row.Row) SchemaInfer(com.pingcap.tikv.operation.SchemaInfer) Metapb(org.tikv.kvproto.Metapb) MockServerTest(com.pingcap.tikv.MockServerTest) Test(org.junit.Test)

Example 20 with CodecDataOutput

use of com.pingcap.tikv.codec.CodecDataOutput in project tispark by pingcap.

the class DecimalTypeTest method encode.

private static byte[] encode(Object val, EncodeType encodeType, DataType type) {
    CodecDataOutput cdo = new CodecDataOutput();
    type.encode(cdo, encodeType, val);
    return cdo.toBytes();
}
Also used : CodecDataOutput(com.pingcap.tikv.codec.CodecDataOutput)

Aggregations

CodecDataOutput (com.pingcap.tikv.codec.CodecDataOutput)20 ByteString (com.google.protobuf.ByteString)4 Expr (com.pingcap.tidb.tipb.Expr)2 BytePairWrapper (com.pingcap.tikv.BytePairWrapper)2 FuncCallExpr (com.pingcap.tikv.expression.FuncCallExpr)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 MockServerTest (com.pingcap.tikv.MockServerTest)1 CodecDataInput (com.pingcap.tikv.codec.CodecDataInput)1 AllocateRowIDOverflowException (com.pingcap.tikv.exception.AllocateRowIDOverflowException)1 TiBatchWriteException (com.pingcap.tikv.exception.TiBatchWriteException)1 TypeException (com.pingcap.tikv.exception.TypeException)1 TiDAGRequest (com.pingcap.tikv.meta.TiDAGRequest)1 TiTableInfo (com.pingcap.tikv.meta.TiTableInfo)1 TiTimestamp (com.pingcap.tikv.meta.TiTimestamp)1 PDErrorHandler (com.pingcap.tikv.operation.PDErrorHandler)1 SchemaInfer (com.pingcap.tikv.operation.SchemaInfer)1 TiRegion (com.pingcap.tikv.region.TiRegion)1 Row (com.pingcap.tikv.row.Row)1 DataType (com.pingcap.tikv.types.DataType)1 RegionTask (com.pingcap.tikv.util.RangeSplitter.RegionTask)1