Java Code Examples for io.prestosql.spi.type.Type#getDisplayName()

The following examples show how to use io.prestosql.spi.type.Type#getDisplayName() . 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: PhoenixClient.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public WriteMapping toWriteMapping(ConnectorSession session, Type type)
{
    if (DOUBLE.equals(type)) {
        return WriteMapping.doubleMapping("double", doubleWriteFunction());
    }
    if (REAL.equals(type)) {
        return WriteMapping.longMapping("float", realWriteFunction());
    }
    if (TIME.equals(type)) {
        return WriteMapping.longMapping("time", timeWriteFunctionUsingSqlTime(session));
    }
    // Phoenix doesn't support _WITH_TIME_ZONE
    if (TIME_WITH_TIME_ZONE.equals(type) || TIMESTAMP_WITH_TIME_ZONE.equals(type)) {
        throw new PrestoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
    }
    if (type instanceof ArrayType) {
        Type elementType = ((ArrayType) type).getElementType();
        String elementDataType = toWriteMapping(session, elementType).getDataType().toUpperCase();
        String elementWriteName = getArrayElementPhoenixTypeName(session, this, elementType);
        return WriteMapping.objectMapping(elementDataType + " ARRAY", arrayWriteFunction(session, elementType, elementWriteName));
    }
    return super.toWriteMapping(session, type);
}
 
Example 2
Source File: ProcedureRegistry.java    From presto with Apache License 2.0 6 votes vote down vote up
private static Class<?> getObjectType(Type type)
{
    if (type.equals(BOOLEAN)) {
        return boolean.class;
    }
    if (type.equals(BIGINT)) {
        return long.class;
    }
    if (type.equals(DOUBLE)) {
        return double.class;
    }
    if (type.equals(VARCHAR)) {
        return String.class;
    }
    if (type instanceof ArrayType) {
        getObjectType(type.getTypeParameters().get(0));
        return List.class;
    }
    if (type instanceof MapType) {
        getObjectType(type.getTypeParameters().get(0));
        getObjectType(type.getTypeParameters().get(1));
        return Map.class;
    }
    throw new IllegalArgumentException("Unsupported argument type: " + type.getDisplayName());
}
 
Example 3
Source File: TypeConverter.java    From presto with Apache License 2.0 6 votes vote down vote up
public static org.apache.iceberg.types.Type toIcebergType(Type type)
{
    if (PRESTO_TO_ICEBERG.containsKey(type.getClass())) {
        return PRESTO_TO_ICEBERG.get(type.getClass());
    }
    if (type instanceof DecimalType) {
        return fromDecimal((DecimalType) type);
    }
    if (type instanceof RowType) {
        return fromRow((RowType) type);
    }
    if (type instanceof ArrayType) {
        return fromArray((ArrayType) type);
    }
    if (type instanceof MapType) {
        return fromMap((MapType) type);
    }
    if (type.equals(TIMESTAMP)) {
        return Types.TimestampType.withoutZone();
    }
    throw new PrestoException(NOT_SUPPORTED, "Type not supported for Iceberg: " + type.getDisplayName());
}
 
Example 4
Source File: PostgreSqlClient.java    From presto with Apache License 2.0 5 votes vote down vote up
private static SliceReadFunction arrayAsJsonReadFunction(ConnectorSession session, ColumnMapping baseElementMapping)
{
    return (resultSet, columnIndex) -> {
        // resolve array type
        Object jdbcArray = resultSet.getArray(columnIndex).getArray();
        int arrayDimensions = arrayDepth(jdbcArray);

        ReadFunction readFunction = baseElementMapping.getReadFunction();
        Type type = baseElementMapping.getType();
        for (int i = 0; i < arrayDimensions; i++) {
            readFunction = arrayReadFunction(type, readFunction);
            type = new ArrayType(type);
        }

        // read array into a block
        Block block = (Block) ((ObjectReadFunction) readFunction).readObject(resultSet, columnIndex);

        // convert block to JSON slice
        BlockBuilder builder = type.createBlockBuilder(null, 1);
        type.writeObject(builder, block);
        Object value = type.getObjectValue(session, builder.build(), 0);

        try {
            return Slices.wrappedBuffer(SORTED_MAPPER.writeValueAsBytes(value));
        }
        catch (JsonProcessingException e) {
            throw new PrestoException(JDBC_ERROR, "Conversion to JSON failed for  " + type.getDisplayName(), e);
        }
    };
}
 
Example 5
Source File: SliceColumnReader.java    From presto with Apache License 2.0 5 votes vote down vote up
private static int getMaxCodePointCount(Type type)
{
    if (isVarcharType(type)) {
        VarcharType varcharType = (VarcharType) type;
        return varcharType.isUnbounded() ? -1 : varcharType.getBoundedLength();
    }
    if (isCharType(type)) {
        return ((CharType) type).getLength();
    }
    if (isVarbinaryType(type)) {
        return -1;
    }
    throw new IllegalArgumentException("Unsupported encoding " + type.getDisplayName());
}
 
Example 6
Source File: QuantileDigestAggregationFunction.java    From presto with Apache License 2.0 5 votes vote down vote up
private static MethodHandle getMethodHandle(Type valueType, int arity)
{
    final MethodHandle inputFunction;
    switch (valueType.getDisplayName()) {
        case StandardTypes.DOUBLE:
            inputFunction = INPUT_DOUBLE;
            break;
        case StandardTypes.REAL:
            inputFunction = INPUT_REAL;
            break;
        case StandardTypes.BIGINT:
            inputFunction = INPUT_BIGINT;
            break;
        default:
            throw new IllegalArgumentException(format("Unsupported type %s supplied", valueType.getDisplayName()));
    }

    switch (arity) {
        case 1:
            // weight and accuracy unspecified
            return insertArguments(inputFunction, 2, DEFAULT_WEIGHT, DEFAULT_ACCURACY);
        case 2:
            // weight specified, accuracy unspecified
            return insertArguments(inputFunction, 3, DEFAULT_ACCURACY);
        case 3:
            // weight and accuracy specified
            return inputFunction;
        default:
            throw new IllegalArgumentException(format("Unsupported number of arguments: %s", arity));
    }
}
 
Example 7
Source File: RaptorBucketFunction.java    From presto with Apache License 2.0 5 votes vote down vote up
private static HashFunction getHashFunction(Type type)
{
    if (type.equals(BIGINT)) {
        return bigintHashFunction();
    }
    if (type.equals(INTEGER)) {
        return intHashFunction();
    }
    if (isVarcharType(type)) {
        return varcharHashFunction();
    }
    throw new PrestoException(NOT_SUPPORTED, "Bucketing is supported for bigint, integer and varchar, not " + type.getDisplayName());
}
 
Example 8
Source File: IcebergPageSink.java    From presto with Apache License 2.0 5 votes vote down vote up
public static Object getIcebergValue(Block block, int position, Type type)
{
    if (block.isNull(position)) {
        return null;
    }
    if (type instanceof BigintType) {
        return type.getLong(block, position);
    }
    if (type instanceof IntegerType || type instanceof SmallintType || type instanceof TinyintType || type instanceof DateType) {
        return toIntExact(type.getLong(block, position));
    }
    if (type instanceof BooleanType) {
        return type.getBoolean(block, position);
    }
    if (type instanceof DecimalType) {
        return readBigDecimal((DecimalType) type, block, position);
    }
    if (type instanceof RealType) {
        return intBitsToFloat(toIntExact(type.getLong(block, position)));
    }
    if (type instanceof DoubleType) {
        return type.getDouble(block, position);
    }
    if (type instanceof TimestampType) {
        return MILLISECONDS.toMicros(type.getLong(block, position));
    }
    if (type instanceof TimestampWithTimeZoneType) {
        return MILLISECONDS.toMicros(unpackMillisUtc(type.getLong(block, position)));
    }
    if (type instanceof VarbinaryType) {
        return type.getSlice(block, position).getBytes();
    }
    if (type instanceof VarcharType) {
        return type.getSlice(block, position).toStringUtf8();
    }
    throw new UnsupportedOperationException("Type not supported as partition column: " + type.getDisplayName());
}
 
Example 9
Source File: TestPrestoDatabaseMetaData.java    From presto with Apache License 2.0 5 votes vote down vote up
private static void assertColumnSpec(ResultSet rs, int jdbcType, Long columnSize, Long numPrecRadix, Long decimalDigits, Long charOctetLength, Type type)
        throws SQLException
{
    String message = " of " + type.getDisplayName() + ": ";
    assertTrue(rs.next());
    assertEquals(rs.getObject("DATA_TYPE"), (long) jdbcType, "DATA_TYPE" + message);
    assertEquals(rs.getObject("COLUMN_SIZE"), columnSize, "COLUMN_SIZE" + message);
    assertEquals(rs.getObject("NUM_PREC_RADIX"), numPrecRadix, "NUM_PREC_RADIX" + message);
    assertEquals(rs.getObject("DECIMAL_DIGITS"), decimalDigits, "DECIMAL_DIGITS" + message);
    assertEquals(rs.getObject("CHAR_OCTET_LENGTH"), charOctetLength, "CHAR_OCTET_LENGTH" + message);
}
 
Example 10
Source File: ShardMetadataRecordCursor.java    From presto with Apache License 2.0 4 votes vote down vote up
private ResultSet getNextResultSet()
{
    closeCurrentResultSet();

    if (!tableIds.hasNext()) {
        return null;
    }

    Long tableId = tableIds.next();
    Long columnId = metadataDao.getTemporalColumnId(tableId);
    List<String> columnNames;

    if (columnId == null) {
        columnNames = getMappedColumnNames("null", "null", "null", "null");
    }
    else {
        Type temporalType = metadataDao.getTableColumn(tableId, columnId).getDataType();
        if (temporalType.equals(DATE)) {
            columnNames = getMappedColumnNames("null", "null", minColumn(columnId), maxColumn(columnId));
        }
        else if (temporalType.equals(TIMESTAMP)) {
            columnNames = getMappedColumnNames(minColumn(columnId), maxColumn(columnId), "null", "null");
        }
        else {
            throw new PrestoException(RAPTOR_CORRUPT_METADATA, "Temporal column should be of type date or timestamp, not " + temporalType.getDisplayName());
        }
    }

    try {
        connection = dbi.open().getConnection();
        statement = PreparedStatementBuilder.create(
                connection,
                constructSqlTemplate(columnNames, tableId),
                columnNames,
                TYPES,
                ImmutableSet.of(getColumnIndex(SHARD_METADATA, SHARD_UUID)),
                tupleDomain);
        return statement.executeQuery();
    }
    catch (SQLException | DBIException e) {
        close();
        throw metadataError(e);
    }
}
 
Example 11
Source File: MySqlClient.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public WriteMapping toWriteMapping(ConnectorSession session, Type type)
{
    if (REAL.equals(type)) {
        return WriteMapping.longMapping("float", realWriteFunction());
    }
    if (TIME_WITH_TIME_ZONE.equals(type) || TIMESTAMP_WITH_TIME_ZONE.equals(type)) {
        throw new PrestoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
    }
    if (TIMESTAMP.equals(type)) {
        // TODO use `timestampWriteFunction`
        return WriteMapping.longMapping("datetime", timestampWriteFunctionUsingSqlTimestamp(session));
    }
    if (VARBINARY.equals(type)) {
        return WriteMapping.sliceMapping("mediumblob", varbinaryWriteFunction());
    }
    if (isVarcharType(type)) {
        VarcharType varcharType = (VarcharType) type;
        String dataType;
        if (varcharType.isUnbounded()) {
            dataType = "longtext";
        }
        else if (varcharType.getBoundedLength() <= 255) {
            dataType = "tinytext";
        }
        else if (varcharType.getBoundedLength() <= 65535) {
            dataType = "text";
        }
        else if (varcharType.getBoundedLength() <= 16777215) {
            dataType = "mediumtext";
        }
        else {
            dataType = "longtext";
        }
        return WriteMapping.sliceMapping(dataType, varcharWriteFunction());
    }
    if (type.equals(jsonType)) {
        return WriteMapping.sliceMapping("json", varcharWriteFunction());
    }

    return super.toWriteMapping(session, type);
}
 
Example 12
Source File: CassandraPageSink.java    From presto with Apache License 2.0 4 votes vote down vote up
private void appendColumn(List<Object> values, Page page, int position, int channel)
{
    Block block = page.getBlock(channel);
    Type type = columnTypes.get(channel);
    if (block.isNull(position)) {
        values.add(null);
    }
    else if (BOOLEAN.equals(type)) {
        values.add(type.getBoolean(block, position));
    }
    else if (BIGINT.equals(type)) {
        values.add(type.getLong(block, position));
    }
    else if (INTEGER.equals(type)) {
        values.add(toIntExact(type.getLong(block, position)));
    }
    else if (SMALLINT.equals(type)) {
        values.add(Shorts.checkedCast(type.getLong(block, position)));
    }
    else if (TINYINT.equals(type)) {
        values.add(SignedBytes.checkedCast(type.getLong(block, position)));
    }
    else if (DOUBLE.equals(type)) {
        values.add(type.getDouble(block, position));
    }
    else if (REAL.equals(type)) {
        values.add(intBitsToFloat(toIntExact(type.getLong(block, position))));
    }
    else if (DATE.equals(type)) {
        values.add(toCassandraDate.apply(type.getLong(block, position)));
    }
    else if (TIMESTAMP.equals(type)) {
        values.add(new Timestamp(type.getLong(block, position)));
    }
    else if (isVarcharType(type)) {
        values.add(type.getSlice(block, position).toStringUtf8());
    }
    else if (VARBINARY.equals(type)) {
        values.add(type.getSlice(block, position).toByteBuffer());
    }
    else {
        throw new PrestoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
    }
}