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();
}
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;
}
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();
}
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());
}
}
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);
}
Aggregations