Search in sources :

Example 81 with Type

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;
}
Also used : Type(com.facebook.presto.spi.type.Type) VarcharType(com.facebook.presto.spi.type.VarcharType) VarcharType(com.facebook.presto.spi.type.VarcharType)

Example 82 with Type

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];
}
Also used : DecimalType(com.facebook.presto.spi.type.DecimalType) Varchars.isVarcharType(com.facebook.presto.spi.type.Varchars.isVarcharType) HiveUtil.isStructuralType(com.facebook.presto.hive.HiveUtil.isStructuralType) Type(com.facebook.presto.spi.type.Type) Chars.isCharType(com.facebook.presto.spi.type.Chars.isCharType)

Example 83 with Type

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];
}
Also used : DecimalType(com.facebook.presto.spi.type.DecimalType) Varchars.isVarcharType(com.facebook.presto.spi.type.Varchars.isVarcharType) HiveUtil.isStructuralType(com.facebook.presto.hive.HiveUtil.isStructuralType) Type(com.facebook.presto.spi.type.Type) Chars.isCharType(com.facebook.presto.spi.type.Chars.isCharType)

Example 84 with Type

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);
}
Also used : VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) Type(com.facebook.presto.spi.type.Type)

Example 85 with Type

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);
    }
}
Also used : DecimalType(com.facebook.presto.spi.type.DecimalType) Varchars.isVarcharType(com.facebook.presto.spi.type.Varchars.isVarcharType) HiveUtil.isStructuralType(com.facebook.presto.hive.HiveUtil.isStructuralType) Type(com.facebook.presto.spi.type.Type) Chars.isCharType(com.facebook.presto.spi.type.Chars.isCharType) Slice(io.airlift.slice.Slice)

Aggregations

Type (com.facebook.presto.spi.type.Type)392 Test (org.testng.annotations.Test)103 Block (com.facebook.presto.spi.block.Block)83 ImmutableList (com.google.common.collect.ImmutableList)79 ArrayType (com.facebook.presto.type.ArrayType)78 MapType (com.facebook.presto.type.MapType)72 Page (com.facebook.presto.spi.Page)68 PrestoException (com.facebook.presto.spi.PrestoException)51 List (java.util.List)50 VarcharType (com.facebook.presto.spi.type.VarcharType)48 DecimalType (com.facebook.presto.spi.type.DecimalType)44 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)40 MaterializedResult (com.facebook.presto.testing.MaterializedResult)40 ArrayList (java.util.ArrayList)40 MethodHandle (java.lang.invoke.MethodHandle)39 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)37 ImmutableMap (com.google.common.collect.ImmutableMap)36 Map (java.util.Map)36 Slice (io.airlift.slice.Slice)35 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)30