Search in sources :

Example 1 with DataType

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

the class ProtoConverter method visit.

@Override
protected Expr visit(Not node, Object context) {
    ScalarFuncSig protoSig = null;
    DataType dataType = getType(node);
    switch(dataType.getType()) {
        case TypeDecimal:
            protoSig = ScalarFuncSig.UnaryNotDecimal;
            break;
        case TypeDouble:
        case TypeFloat:
            protoSig = ScalarFuncSig.UnaryNotReal;
            break;
        case TypeInt24:
        case TypeLong:
        case TypeShort:
        case TypeLonglong:
        case TypeTiny:
            protoSig = ScalarFuncSig.UnaryNotInt;
            break;
        default:
    }
    Objects.requireNonNull(protoSig, "unary not can not find proper proto signature.");
    Expr.Builder builder = scalarToPartialProto(node, context);
    builder.setSig(protoSig);
    builder.setFieldType(toPBFieldType(getType(node)));
    return builder.build();
}
Also used : Expr(com.pingcap.tidb.tipb.Expr) FuncCallExpr(com.pingcap.tikv.expression.FuncCallExpr) DataType(com.pingcap.tikv.types.DataType) ScalarFuncSig(com.pingcap.tidb.tipb.ScalarFuncSig)

Example 2 with DataType

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

the class ProtoConverter method getTypeSignature.

private String getTypeSignature(Expression expression) {
    DataType type = getType(expression);
    String typeSignature = SCALAR_SIG_MAP.get(type.getClass());
    if (typeSignature == null) {
        throw new TiExpressionException(String.format("Type %s signature unknown", type));
    }
    return typeSignature;
}
Also used : DataType(com.pingcap.tikv.types.DataType) TiExpressionException(com.pingcap.tikv.exception.TiExpressionException)

Example 3 with DataType

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

the class TiTableInfo method copyColumn.

private TiColumnInfo copyColumn(TiColumnInfo col) {
    DataType type = col.getType();
    InternalTypeHolder typeHolder = type.toTypeHolder();
    typeHolder.setFlag(type.getFlag() & (~DataType.PriKeyFlag));
    DataType newType = DataTypeFactory.of(typeHolder);
    return new TiColumnInfo(col.getId(), col.getName(), col.getOffset(), newType, col.getSchemaState(), col.getOriginDefaultValue(), col.getDefaultValue(), col.getDefaultValueBit(), col.getComment(), col.getVersion(), col.getGeneratedExprString(), col.isHidden()).copyWithoutPrimaryKey();
}
Also used : InternalTypeHolder(com.pingcap.tikv.meta.TiColumnInfo.InternalTypeHolder) DataType(com.pingcap.tikv.types.DataType)

Example 4 with DataType

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

Example 5 with DataType

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

the class IndexKey method encodeIndexDataValues.

public static EncodeIndexDataResult encodeIndexDataValues(Row row, List<TiIndexColumn> indexColumns, Handle handle, boolean appendHandleIfContainsNull, TiTableInfo tableInfo) {
    // when appendHandleIfContainsNull is true, append handle column if any of the index column is
    // NULL
    boolean appendHandle = false;
    if (handle.isInt()) {
        if (appendHandleIfContainsNull) {
            for (TiIndexColumn col : indexColumns) {
                DataType colTp = tableInfo.getColumn(col.getOffset()).getType();
                if (row.get(col.getOffset(), colTp) == null) {
                    appendHandle = true;
                    break;
                }
            }
        }
    }
    Key[] keys = new Key[indexColumns.size() + (appendHandle ? 1 : 0)];
    for (int i = 0; i < indexColumns.size(); i++) {
        TiIndexColumn col = indexColumns.get(i);
        DataType colTp = tableInfo.getColumn(col.getOffset()).getType();
        // truncate index's if necessary
        Key key = TypedKey.toTypedKey(row.get(col.getOffset(), colTp), colTp, (int) col.getLength());
        keys[i] = key;
    }
    if (appendHandle) {
        Key key = TypedKey.toTypedKey(handle, IntegerType.BIGINT);
        keys[keys.length - 1] = key;
    }
    return new EncodeIndexDataResult(keys, appendHandle);
}
Also used : TiIndexColumn(com.pingcap.tikv.meta.TiIndexColumn) DataType(com.pingcap.tikv.types.DataType)

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