use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class HiveCoercionPolicy method canCoerce.
@Override
public boolean canCoerce(HiveType fromHiveType, HiveType toHiveType) {
Type fromType = typeManager.getType(fromHiveType.getTypeSignature());
Type toType = typeManager.getType(toHiveType.getTypeSignature());
if (fromType instanceof VarcharType) {
return toHiveType.equals(HIVE_BYTE) || toHiveType.equals(HIVE_SHORT) || toHiveType.equals(HIVE_INT) || toHiveType.equals(HIVE_LONG);
}
if (toType instanceof VarcharType) {
return fromHiveType.equals(HIVE_BYTE) || fromHiveType.equals(HIVE_SHORT) || fromHiveType.equals(HIVE_INT) || fromHiveType.equals(HIVE_LONG);
}
if (fromHiveType.equals(HIVE_BYTE)) {
return toHiveType.equals(HIVE_SHORT) || toHiveType.equals(HIVE_INT) || toHiveType.equals(HIVE_LONG);
}
if (fromHiveType.equals(HIVE_SHORT)) {
return toHiveType.equals(HIVE_INT) || toHiveType.equals(HIVE_LONG);
}
if (fromHiveType.equals(HIVE_INT)) {
return toHiveType.equals(HIVE_LONG);
}
if (fromHiveType.equals(HIVE_FLOAT)) {
return toHiveType.equals(HIVE_DOUBLE);
}
return false;
}
use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class ColumnarBinaryHiveRecordCursor method getSlice.
@Override
public Slice getSlice(int fieldId) {
checkState(!closed, "Cursor is closed");
Type type = types[fieldId];
if (!isVarcharType(type) && !isCharType(type) && !type.equals(VARBINARY) && !isStructuralType(hiveTypes[fieldId]) && !isLongDecimal(type)) {
// we don't use Preconditions.checkArgument because it requires boxing fieldId, which affects inner loop performance
throw new IllegalArgumentException(format("Expected field to be VARCHAR, CHAR, VARBINARY or DECIMAL, actual %s (field %s)", type, fieldId));
}
if (!loaded[fieldId]) {
parseStringColumn(fieldId);
}
return slices[fieldId];
}
use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class ColumnarBinaryHiveRecordCursor method getObject.
@Override
public Object getObject(int fieldId) {
checkState(!closed, "Cursor is closed");
Type type = types[fieldId];
if (!isStructuralType(hiveTypes[fieldId])) {
// we don't use Preconditions.checkArgument because it requires boxing fieldId, which affects inner loop performance
throw new IllegalArgumentException(format("Expected field to be structural, actual %s (field %s)", type, fieldId));
}
if (!loaded[fieldId]) {
parseObjectColumn(fieldId);
}
return objects[fieldId];
}
use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class ExampleRecordCursor method checkFieldType.
private void checkFieldType(int field, Type expected) {
Type actual = getType(field);
checkArgument(actual.equals(expected), "Expected field %s to be type %s but is %s", field, expected, actual);
}
use of com.facebook.presto.spi.type.Type in project presto by prestodb.
the class ColumnarBinaryHiveRecordCursor method parseCharColumn.
private void parseCharColumn(int column, byte[] bytes, int start, int length) {
if (length == 0) {
nulls[column] = true;
} else {
nulls[column] = false;
Slice value = Slices.wrappedBuffer(Arrays.copyOfRange(bytes, start, start + length));
Type type = types[column];
slices[column] = trimSpacesAndTruncateToLength(value, type);
}
}
Aggregations