Java Code Examples for io.prestosql.spi.connector.RecordCursor#getObject()

The following examples show how to use io.prestosql.spi.connector.RecordCursor#getObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HiveCoercionRecordCursor.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void coerce(RecordCursor delegate, int field)
{
    if (delegate.isNull(field)) {
        setIsNull(true);
        return;
    }
    Block block = (Block) delegate.getObject(field);
    if (pageBuilder.isFull()) {
        pageBuilder.reset();
    }
    BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
    BlockBuilder listBuilder = blockBuilder.beginBlockEntry();
    for (int i = 0; i < block.getPositionCount(); i++) {
        if (elementCoercer == null) {
            toElementType.appendTo(block, i, listBuilder);
        }
        else {
            if (block.isNull(i)) {
                listBuilder.appendNull();
            }
            else {
                rewriteBlock(fromElementType, toElementType, block, i, listBuilder, elementCoercer, bridgingRecordCursor);
            }
        }
    }
    blockBuilder.closeEntry();
    pageBuilder.declarePosition();
    setObject(toType.getObject(blockBuilder, blockBuilder.getPositionCount() - 1));
}
 
Example 2
Source File: HiveCoercionRecordCursor.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void coerce(RecordCursor delegate, int field)
{
    if (delegate.isNull(field)) {
        setIsNull(true);
        return;
    }
    Block block = (Block) delegate.getObject(field);
    if (pageBuilder.isFull()) {
        pageBuilder.reset();
    }
    BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
    BlockBuilder mapBuilder = blockBuilder.beginBlockEntry();
    for (int i = 0; i < block.getPositionCount(); i++) {
        int k = i % 2;
        if (coercers[k] == null) {
            toKeyValueTypes.get(k).appendTo(block, i, mapBuilder);
        }
        else {
            if (block.isNull(i)) {
                mapBuilder.appendNull();
            }
            else {
                rewriteBlock(fromKeyValueTypes.get(k), toKeyValueTypes.get(k), block, i, mapBuilder, coercers[k], bridgingRecordCursor);
            }
        }
    }
    blockBuilder.closeEntry();
    pageBuilder.declarePosition();
    setObject(toType.getObject(blockBuilder, blockBuilder.getPositionCount() - 1));
}
 
Example 3
Source File: HiveCoercionRecordCursor.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void coerce(RecordCursor delegate, int field)
{
    if (delegate.isNull(field)) {
        setIsNull(true);
        return;
    }
    Block block = (Block) delegate.getObject(field);
    if (pageBuilder.isFull()) {
        pageBuilder.reset();
    }
    BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
    BlockBuilder rowBuilder = blockBuilder.beginBlockEntry();
    for (int i = 0; i < toFieldTypes.size(); i++) {
        if (i >= fromFieldTypes.size() || block.isNull(i)) {
            rowBuilder.appendNull();
        }
        else if (coercers[i] == null) {
            toFieldTypes.get(i).appendTo(block, i, rowBuilder);
        }
        else {
            rewriteBlock(fromFieldTypes.get(i), toFieldTypes.get(i), block, i, rowBuilder, coercers[i], bridgingRecordCursor);
        }
    }
    blockBuilder.closeEntry();
    pageBuilder.declarePosition();
    setObject(toType.getObject(blockBuilder, blockBuilder.getPositionCount() - 1));
}
 
Example 4
Source File: AbstractTestHiveFileFormats.java    From presto with Apache License 2.0 4 votes vote down vote up
public static Object getFieldFromCursor(RecordCursor cursor, Type type, int field)
{
    if (cursor.isNull(field)) {
        return null;
    }
    if (BOOLEAN.equals(type)) {
        return cursor.getBoolean(field);
    }
    if (TINYINT.equals(type)) {
        return cursor.getLong(field);
    }
    if (SMALLINT.equals(type)) {
        return cursor.getLong(field);
    }
    if (INTEGER.equals(type)) {
        return (int) cursor.getLong(field);
    }
    if (BIGINT.equals(type)) {
        return cursor.getLong(field);
    }
    if (REAL.equals(type)) {
        return intBitsToFloat((int) cursor.getLong(field));
    }
    if (DOUBLE.equals(type)) {
        return cursor.getDouble(field);
    }
    if (isVarcharType(type) || isCharType(type) || VARBINARY.equals(type)) {
        return cursor.getSlice(field);
    }
    if (DateType.DATE.equals(type)) {
        return cursor.getLong(field);
    }
    if (TimestampType.TIMESTAMP.equals(type)) {
        return cursor.getLong(field);
    }
    if (isStructuralType(type)) {
        return cursor.getObject(field);
    }
    if (type instanceof DecimalType) {
        DecimalType decimalType = (DecimalType) type;
        if (decimalType.isShort()) {
            return BigInteger.valueOf(cursor.getLong(field));
        }
        else {
            return Decimals.decodeUnscaledValue(cursor.getSlice(field));
        }
    }
    throw new RuntimeException("unknown type");
}