Search in sources :

Example 1 with IntegerType

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

the class TypedKey method next.

/**
 * Next TypedKey be truncated with prefixLength
 *
 * @return next TypedKey with same prefix length
 */
@Override
public TypedKey next() {
    DataType tp = getType();
    Object val = getValue();
    if (tp instanceof StringType) {
        return toTypedKey(prefixNext(((String) val).getBytes()), type, prefixLength);
    } else if (tp instanceof BytesType) {
        return toTypedKey(prefixNext(((byte[]) val)), type, prefixLength);
    } else if (DataType.isLengthUnSpecified(prefixLength)) {
        if (tp instanceof IntegerType) {
            return toTypedKey(((long) val) + 1, type);
        } else {
            // use byte array type when next key is hard to identify
            return toRawTypedKey(prefixNext(value), type);
        }
    } else {
        throw new TypeException("When prefix length is defined, type for TypedKey in next() function must be either String or Byte array. Actual: " + val.getClass().getName());
    }
}
Also used : IntegerType(com.pingcap.tikv.types.IntegerType) StringType(com.pingcap.tikv.types.StringType) DataType(com.pingcap.tikv.types.DataType) TypeException(com.pingcap.tikv.exception.TypeException) BytesType(com.pingcap.tikv.types.BytesType)

Aggregations

TypeException (com.pingcap.tikv.exception.TypeException)1 BytesType (com.pingcap.tikv.types.BytesType)1 DataType (com.pingcap.tikv.types.DataType)1 IntegerType (com.pingcap.tikv.types.IntegerType)1 StringType (com.pingcap.tikv.types.StringType)1