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

The following examples show how to use io.prestosql.spi.connector.RecordCursor#getLong() . 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: PrestoThriftTypeUtils.java    From presto with Apache License 2.0 6 votes vote down vote up
public static PrestoThriftBlock fromLongBasedColumn(RecordSet recordSet, int columnIndex, int positions, BiFunction<boolean[], long[], PrestoThriftBlock> result)
{
    if (positions == 0) {
        return result.apply(null, null);
    }
    boolean[] nulls = null;
    long[] longs = null;
    RecordCursor cursor = recordSet.cursor();
    for (int position = 0; position < positions; position++) {
        checkState(cursor.advanceNextPosition(), "cursor has less values than expected");
        if (cursor.isNull(columnIndex)) {
            if (nulls == null) {
                nulls = new boolean[positions];
            }
            nulls[position] = true;
        }
        else {
            if (longs == null) {
                longs = new long[positions];
            }
            longs[position] = cursor.getLong(columnIndex);
        }
    }
    checkState(!cursor.advanceNextPosition(), "cursor has more values than expected");
    return result.apply(nulls, longs);
}
 
Example 2
Source File: PrestoThriftTypeUtils.java    From presto with Apache License 2.0 6 votes vote down vote up
public static PrestoThriftBlock fromIntBasedColumn(RecordSet recordSet, int columnIndex, int positions, BiFunction<boolean[], int[], PrestoThriftBlock> result)
{
    if (positions == 0) {
        return result.apply(null, null);
    }
    boolean[] nulls = null;
    int[] ints = null;
    RecordCursor cursor = recordSet.cursor();
    for (int position = 0; position < positions; position++) {
        checkState(cursor.advanceNextPosition(), "cursor has less values than expected");
        if (cursor.isNull(columnIndex)) {
            if (nulls == null) {
                nulls = new boolean[positions];
            }
            nulls[position] = true;
        }
        else {
            if (ints == null) {
                ints = new int[positions];
            }
            ints[position] = (int) cursor.getLong(columnIndex);
        }
    }
    checkState(!cursor.advanceNextPosition(), "cursor has more values than expected");
    return result.apply(nulls, ints);
}
 
Example 3
Source File: TableStatisticsRecorder.java    From presto with Apache License 2.0 6 votes vote down vote up
private Comparable<?> getPrestoValue(RecordCursor recordCursor, List<Column> columns, int columnId)
{
    if (recordCursor.isNull(columnId)) {
        return null;
    }

    Column column = columns.get(columnId);
    ColumnType.Base baseType = column.getType().getBase();
    switch (baseType) {
        case IDENTIFIER:
        case INTEGER:
        case DATE:
        case TIME:
        case DECIMAL:
            return recordCursor.getLong(columnId);
        case VARCHAR:
        case CHAR:
            return recordCursor.getSlice(columnId).toStringAscii();
    }
    throw new UnsupportedOperationException(format("Unsupported TPCDS base type [%s]", baseType));
}
 
Example 4
Source File: TpchIndexedData.java    From presto with Apache License 2.0 6 votes vote down vote up
private static Object extractObject(RecordCursor cursor, int field, Type type)
{
    if (cursor.isNull(field)) {
        return null;
    }

    Class<?> javaType = type.getJavaType();
    if (javaType == boolean.class) {
        return cursor.getBoolean(field);
    }
    if (javaType == long.class) {
        return cursor.getLong(field);
    }
    if (javaType == double.class) {
        return cursor.getDouble(field);
    }
    if (javaType == Slice.class) {
        return cursor.getSlice(field).toStringUtf8();
    }
    throw new AssertionError("Unsupported type: " + type);
}
 
Example 5
Source File: TestCassandraConnector.java    From presto with Apache License 2.0 5 votes vote down vote up
private static void assertReadFields(RecordCursor cursor, List<ColumnMetadata> schema)
{
    for (int columnIndex = 0; columnIndex < schema.size(); columnIndex++) {
        ColumnMetadata column = schema.get(columnIndex);
        if (!cursor.isNull(columnIndex)) {
            Type type = column.getType();
            if (BOOLEAN.equals(type)) {
                cursor.getBoolean(columnIndex);
            }
            else if (INTEGER.equals(type)) {
                cursor.getLong(columnIndex);
            }
            else if (BIGINT.equals(type)) {
                cursor.getLong(columnIndex);
            }
            else if (TIMESTAMP.equals(type)) {
                cursor.getLong(columnIndex);
            }
            else if (DOUBLE.equals(type)) {
                cursor.getDouble(columnIndex);
            }
            else if (REAL.equals(type)) {
                cursor.getLong(columnIndex);
            }
            else if (isVarcharType(type) || VARBINARY.equals(type)) {
                try {
                    cursor.getSlice(columnIndex);
                }
                catch (RuntimeException e) {
                    throw new RuntimeException("column " + column, e);
                }
            }
            else {
                fail("Unknown primitive type " + columnIndex);
            }
        }
    }
}
 
Example 6
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");
}