Java Code Examples for io.prestosql.spi.type.VarcharType#MAX_LENGTH

The following examples show how to use io.prestosql.spi.type.VarcharType#MAX_LENGTH . 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: DruidJdbcClient.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<ColumnMapping> toPrestoType(ConnectorSession session, Connection connection, JdbcTypeHandle typeHandle)
{
    switch (typeHandle.getJdbcType()) {
        case Types.VARCHAR:
            int columnSize = typeHandle.getColumnSize();
            if (columnSize > VarcharType.MAX_LENGTH || columnSize == -1) {
                return Optional.of(varcharColumnMapping(createUnboundedVarcharType()));
            }
            return Optional.of(varcharColumnMapping(createVarcharType(columnSize)));
    }
    return super.toPrestoType(session, connection, typeHandle);
}
 
Example 2
Source File: VarcharParametricType.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public Type createType(TypeManager typeManager, List<TypeParameter> parameters)
{
    if (parameters.isEmpty()) {
        return createUnboundedVarcharType();
    }
    if (parameters.size() != 1) {
        throw new IllegalArgumentException("Expected exactly one parameter for VARCHAR");
    }

    TypeParameter parameter = parameters.get(0);

    if (!parameter.isLongLiteral()) {
        throw new IllegalArgumentException("VARCHAR length must be a number");
    }

    long length = parameter.getLongLiteral();

    if (length == VarcharType.UNBOUNDED_LENGTH) {
        return VarcharType.createUnboundedVarcharType();
    }

    if (length < 0 || length > VarcharType.MAX_LENGTH) {
        throw new IllegalArgumentException("Invalid VARCHAR length " + length);
    }

    return VarcharType.createVarcharType((int) length);
}
 
Example 3
Source File: StandardColumnMappings.java    From presto with Apache License 2.0 4 votes vote down vote up
public static Optional<ColumnMapping> jdbcTypeToPrestoType(ConnectorSession session, JdbcTypeHandle type)
{
    int columnSize = type.getColumnSize();
    switch (type.getJdbcType()) {
        case Types.BIT:
        case Types.BOOLEAN:
            return Optional.of(booleanColumnMapping());

        case Types.TINYINT:
            return Optional.of(tinyintColumnMapping());

        case Types.SMALLINT:
            return Optional.of(smallintColumnMapping());

        case Types.INTEGER:
            return Optional.of(integerColumnMapping());

        case Types.BIGINT:
            return Optional.of(bigintColumnMapping());

        case Types.REAL:
            return Optional.of(realColumnMapping());

        case Types.FLOAT:
        case Types.DOUBLE:
            return Optional.of(doubleColumnMapping());

        case Types.NUMERIC:
        case Types.DECIMAL:
            int decimalDigits = type.getDecimalDigits();
            int precision = columnSize + max(-decimalDigits, 0); // Map decimal(p, -s) (negative scale) to decimal(p+s, 0).
            if (precision > Decimals.MAX_PRECISION) {
                return Optional.empty();
            }
            return Optional.of(decimalColumnMapping(createDecimalType(precision, max(decimalDigits, 0)), UNNECESSARY));

        case Types.CHAR:
        case Types.NCHAR:
            // TODO this is wrong, we're going to construct malformed Slice representation if source > charLength
            int charLength = min(columnSize, CharType.MAX_LENGTH);
            return Optional.of(charColumnMapping(createCharType(charLength)));

        case Types.VARCHAR:
        case Types.NVARCHAR:
        case Types.LONGVARCHAR:
        case Types.LONGNVARCHAR:
            if (columnSize > VarcharType.MAX_LENGTH) {
                return Optional.of(varcharColumnMapping(createUnboundedVarcharType()));
            }
            return Optional.of(varcharColumnMapping(createVarcharType(columnSize)));

        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            return Optional.of(varbinaryColumnMapping());

        case Types.DATE:
            return Optional.of(dateColumnMapping());

        case Types.TIME:
            // TODO default to `timeColumnMapping`
            return Optional.of(timeColumnMappingUsingSqlTime(session));

        case Types.TIMESTAMP:
            // TODO default to `timestampColumnMapping`
            return Optional.of(timestampColumnMappingUsingSqlTimestamp(session));
    }
    return Optional.empty();
}