Search in sources :

Example 11 with JdbcTypeHandle

use of io.trino.plugin.jdbc.JdbcTypeHandle in project trino by trinodb.

the class OracleClient method toColumnMapping.

@Override
public Optional<ColumnMapping> toColumnMapping(ConnectorSession session, Connection connection, JdbcTypeHandle typeHandle) {
    String jdbcTypeName = typeHandle.getJdbcTypeName().orElseThrow(() -> new TrinoException(JDBC_ERROR, "Type name is missing: " + typeHandle));
    Optional<ColumnMapping> mappingToVarchar = getForcedMappingToVarchar(typeHandle);
    if (mappingToVarchar.isPresent()) {
        return mappingToVarchar;
    }
    if (jdbcTypeName.equalsIgnoreCase("date")) {
        return Optional.of(ColumnMapping.longMapping(TIMESTAMP_SECONDS, oracleTimestampReadFunction(), trinoTimestampToOracleDateWriteFunction(), FULL_PUSHDOWN));
    }
    switch(typeHandle.getJdbcType()) {
        case Types.SMALLINT:
            return Optional.of(ColumnMapping.longMapping(SMALLINT, ResultSet::getShort, smallintWriteFunction(), FULL_PUSHDOWN));
        case OracleTypes.BINARY_FLOAT:
            return Optional.of(ColumnMapping.longMapping(REAL, (resultSet, columnIndex) -> floatToRawIntBits(resultSet.getFloat(columnIndex)), oracleRealWriteFunction(), FULL_PUSHDOWN));
        case OracleTypes.BINARY_DOUBLE:
        case OracleTypes.FLOAT:
            return Optional.of(ColumnMapping.doubleMapping(DOUBLE, ResultSet::getDouble, oracleDoubleWriteFunction(), FULL_PUSHDOWN));
        case OracleTypes.NUMBER:
            int actualPrecision = typeHandle.getRequiredColumnSize();
            int decimalDigits = typeHandle.getRequiredDecimalDigits();
            // Map negative scale to decimal(p+s, 0).
            int precision = actualPrecision + max(-decimalDigits, 0);
            int scale = max(decimalDigits, 0);
            Optional<Integer> numberDefaultScale = getNumberDefaultScale(session);
            RoundingMode roundingMode = getNumberRoundingMode(session);
            if (precision < scale) {
                if (roundingMode == RoundingMode.UNNECESSARY) {
                    break;
                }
                scale = min(Decimals.MAX_PRECISION, scale);
                precision = scale;
            } else if (numberDefaultScale.isPresent() && precision == PRECISION_OF_UNSPECIFIED_NUMBER) {
                precision = Decimals.MAX_PRECISION;
                scale = numberDefaultScale.get();
            } else if (precision > Decimals.MAX_PRECISION || actualPrecision <= 0) {
                break;
            }
            DecimalType decimalType = createDecimalType(precision, scale);
            // JDBC driver can return BigDecimal with lower scale than column's scale when there are trailing zeroes
            if (decimalType.isShort()) {
                return Optional.of(ColumnMapping.longMapping(decimalType, shortDecimalReadFunction(decimalType, roundingMode), shortDecimalWriteFunction(decimalType), FULL_PUSHDOWN));
            }
            return Optional.of(ColumnMapping.objectMapping(decimalType, longDecimalReadFunction(decimalType, roundingMode), longDecimalWriteFunction(decimalType), FULL_PUSHDOWN));
        case OracleTypes.CHAR:
        case OracleTypes.NCHAR:
            CharType charType = createCharType(typeHandle.getRequiredColumnSize());
            return Optional.of(ColumnMapping.sliceMapping(charType, charReadFunction(charType), oracleCharWriteFunction(), FULL_PUSHDOWN));
        case OracleTypes.VARCHAR:
        case OracleTypes.NVARCHAR:
            return Optional.of(ColumnMapping.sliceMapping(createVarcharType(typeHandle.getRequiredColumnSize()), (varcharResultSet, varcharColumnIndex) -> utf8Slice(varcharResultSet.getString(varcharColumnIndex)), varcharWriteFunction(), FULL_PUSHDOWN));
        case OracleTypes.CLOB:
        case OracleTypes.NCLOB:
            return Optional.of(ColumnMapping.sliceMapping(createUnboundedVarcharType(), (resultSet, columnIndex) -> utf8Slice(resultSet.getString(columnIndex)), varcharWriteFunction(), DISABLE_PUSHDOWN));
        // Oracle's RAW(n)
        case OracleTypes.VARBINARY:
        case OracleTypes.BLOB:
            return Optional.of(ColumnMapping.sliceMapping(VARBINARY, (resultSet, columnIndex) -> wrappedBuffer(resultSet.getBytes(columnIndex)), varbinaryWriteFunction(), DISABLE_PUSHDOWN));
        case OracleTypes.TIMESTAMP:
            return Optional.of(ColumnMapping.longMapping(TIMESTAMP_MILLIS, oracleTimestampReadFunction(), trinoTimestampToOracleTimestampWriteFunction(), FULL_PUSHDOWN));
        case OracleTypes.TIMESTAMPTZ:
            return Optional.of(oracleTimestampWithTimeZoneColumnMapping());
    }
    if (getUnsupportedTypeHandling(session) == CONVERT_TO_VARCHAR) {
        return mapToUnboundedVarchar(typeHandle);
    }
    return Optional.empty();
}
Also used : ZonedDateTime(java.time.ZonedDateTime) StandardColumnMappings.bigintWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.bigintWriteFunction) NANOSECONDS_PER_MICROSECOND(io.trino.spi.type.Timestamps.NANOSECONDS_PER_MICROSECOND) CharType.createCharType(io.trino.spi.type.CharType.createCharType) SecureRandom(java.security.SecureRandom) Slices.wrappedBuffer(io.airlift.slice.Slices.wrappedBuffer) NOT_SUPPORTED(io.trino.spi.StandardErrorCode.NOT_SUPPORTED) ResultSet(java.sql.ResultSet) Map(java.util.Map) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) ZoneOffset(java.time.ZoneOffset) ENGLISH(java.util.Locale.ENGLISH) SMALLINT(io.trino.spi.type.SmallintType.SMALLINT) TypeHandlingJdbcSessionProperties.getUnsupportedTypeHandling(io.trino.plugin.jdbc.TypeHandlingJdbcSessionProperties.getUnsupportedTypeHandling) DateTimeEncoding.packDateTimeWithZone(io.trino.spi.type.DateTimeEncoding.packDateTimeWithZone) LongWriteFunction(io.trino.plugin.jdbc.LongWriteFunction) Set(java.util.Set) PreparedStatement(java.sql.PreparedStatement) SchemaTableName(io.trino.spi.connector.SchemaTableName) ZoneId(java.time.ZoneId) LongReadFunction(io.trino.plugin.jdbc.LongReadFunction) StandardColumnMappings.charReadFunction(io.trino.plugin.jdbc.StandardColumnMappings.charReadFunction) StandardColumnMappings.smallintWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.smallintWriteFunction) StandardColumnMappings.longDecimalWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.longDecimalWriteFunction) ConnectionFactory(io.trino.plugin.jdbc.ConnectionFactory) CONVERT_TO_VARCHAR(io.trino.plugin.jdbc.UnsupportedTypeHandling.CONVERT_TO_VARCHAR) DoubleWriteFunction(io.trino.plugin.jdbc.DoubleWriteFunction) DateTimeEncoding.unpackMillisUtc(io.trino.spi.type.DateTimeEncoding.unpackMillisUtc) JdbcTableHandle(io.trino.plugin.jdbc.JdbcTableHandle) DATE(io.trino.spi.type.DateType.DATE) REAL(io.trino.spi.type.RealType.REAL) JoinCondition(io.trino.spi.connector.JoinCondition) TIMESTAMP_MILLIS(io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS) LocalDateTime(java.time.LocalDateTime) BOOLEAN(io.trino.spi.type.BooleanType.BOOLEAN) Float.floatToRawIntBits(java.lang.Float.floatToRawIntBits) SQLException(java.sql.SQLException) TIMESTAMP_TZ_MILLIS(io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS) FULL_PUSHDOWN(io.trino.plugin.jdbc.PredicatePushdownController.FULL_PUSHDOWN) StandardColumnMappings.charWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.charWriteFunction) VARBINARY(io.trino.spi.type.VarbinaryType.VARBINARY) Math.floorDiv(java.lang.Math.floorDiv) TIMESTAMP_SECONDS(io.trino.spi.type.TimestampType.TIMESTAMP_SECONDS) DecimalType.createDecimalType(io.trino.spi.type.DecimalType.createDecimalType) QueryBuilder(io.trino.plugin.jdbc.QueryBuilder) ConnectorSession(io.trino.spi.connector.ConnectorSession) DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) IdentifierMapping(io.trino.plugin.jdbc.mapping.IdentifierMapping) CharType(io.trino.spi.type.CharType) TINYINT(io.trino.spi.type.TinyintType.TINYINT) StandardColumnMappings.shortDecimalWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.shortDecimalWriteFunction) StandardColumnMappings.varbinaryWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.varbinaryWriteFunction) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) WriteMapping(io.trino.plugin.jdbc.WriteMapping) JDBC_ERROR(io.trino.plugin.jdbc.JdbcErrorCode.JDBC_ERROR) BaseJdbcConfig(io.trino.plugin.jdbc.BaseJdbcConfig) Connection(java.sql.Connection) MICROSECONDS_PER_MILLISECOND(io.trino.spi.type.Timestamps.MICROSECONDS_PER_MILLISECOND) OracleSessionProperties.getNumberDefaultScale(io.trino.plugin.oracle.OracleSessionProperties.getNumberDefaultScale) Math.abs(java.lang.Math.abs) DateTimeEncoding.unpackZoneKey(io.trino.spi.type.DateTimeEncoding.unpackZoneKey) ColumnMapping(io.trino.plugin.jdbc.ColumnMapping) INTEGER(io.trino.spi.type.IntegerType.INTEGER) RoundingMode(java.math.RoundingMode) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) MICROSECONDS_PER_SECOND(io.trino.spi.type.Timestamps.MICROSECONDS_PER_SECOND) TrinoException(io.trino.spi.TrinoException) Math.min(java.lang.Math.min) Instant(java.time.Instant) String.format(java.lang.String.format) List(java.util.List) JdbcTypeHandle(io.trino.plugin.jdbc.JdbcTypeHandle) StandardColumnMappings.longDecimalReadFunction(io.trino.plugin.jdbc.StandardColumnMappings.longDecimalReadFunction) BIGINT(io.trino.spi.type.BigintType.BIGINT) Decimals(io.trino.spi.type.Decimals) Optional(java.util.Optional) Math.max(java.lang.Math.max) DecimalType(io.trino.spi.type.DecimalType) OracleTypes(oracle.jdbc.OracleTypes) MAX_RADIX(java.lang.Character.MAX_RADIX) Types(java.sql.Types) SliceWriteFunction(io.trino.plugin.jdbc.SliceWriteFunction) Math.floorMod(java.lang.Math.floorMod) StandardColumnMappings.varcharWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.varcharWriteFunction) StandardColumnMappings.tinyintWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.tinyintWriteFunction) Type(io.trino.spi.type.Type) OracleSessionProperties.getNumberRoundingMode(io.trino.plugin.oracle.OracleSessionProperties.getNumberRoundingMode) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) Float.intBitsToFloat(java.lang.Float.intBitsToFloat) Inject(javax.inject.Inject) VarcharType(io.trino.spi.type.VarcharType) OraclePreparedStatement(oracle.jdbc.OraclePreparedStatement) ImmutableList(com.google.common.collect.ImmutableList) Verify.verify(com.google.common.base.Verify.verify) Objects.requireNonNull(java.util.Objects.requireNonNull) DAYS(java.util.concurrent.TimeUnit.DAYS) BaseJdbcClient(io.trino.plugin.jdbc.BaseJdbcClient) Math.toIntExact(java.lang.Math.toIntExact) JdbcJoinCondition(io.trino.plugin.jdbc.JdbcJoinCondition) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) StandardColumnMappings.integerWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.integerWriteFunction) DISABLE_PUSHDOWN(io.trino.plugin.jdbc.PredicatePushdownController.DISABLE_PUSHDOWN) DateTimeFormatter(java.time.format.DateTimeFormatter) StandardColumnMappings.shortDecimalReadFunction(io.trino.plugin.jdbc.StandardColumnMappings.shortDecimalReadFunction) RoundingMode(java.math.RoundingMode) OracleSessionProperties.getNumberRoundingMode(io.trino.plugin.oracle.OracleSessionProperties.getNumberRoundingMode) TrinoException(io.trino.spi.TrinoException) DecimalType.createDecimalType(io.trino.spi.type.DecimalType.createDecimalType) DecimalType(io.trino.spi.type.DecimalType) CharType.createCharType(io.trino.spi.type.CharType.createCharType) CharType(io.trino.spi.type.CharType) ColumnMapping(io.trino.plugin.jdbc.ColumnMapping)

Example 12 with JdbcTypeHandle

use of io.trino.plugin.jdbc.JdbcTypeHandle in project trino by trinodb.

the class PhoenixClient method getArrayElementTypeHandle.

private JdbcTypeHandle getArrayElementTypeHandle(JdbcTypeHandle arrayTypeHandle) {
    String arrayTypeName = arrayTypeHandle.getJdbcTypeName().orElseThrow(() -> new TrinoException(PHOENIX_METADATA_ERROR, "Type name is missing for jdbc type: " + JDBCType.valueOf(arrayTypeHandle.getJdbcType())));
    checkArgument(arrayTypeName.endsWith(" ARRAY"), "array type must end with ' ARRAY'");
    arrayTypeName = arrayTypeName.substring(0, arrayTypeName.length() - " ARRAY".length());
    verify(arrayTypeHandle.getCaseSensitivity().isEmpty(), "Case sensitivity not supported");
    return new JdbcTypeHandle(PDataType.fromSqlTypeName(arrayTypeName).getSqlType(), Optional.of(arrayTypeName), arrayTypeHandle.getColumnSize(), arrayTypeHandle.getDecimalDigits(), arrayTypeHandle.getArrayDimensions(), Optional.empty());
}
Also used : JdbcTypeHandle(io.trino.plugin.jdbc.JdbcTypeHandle) TrinoException(io.trino.spi.TrinoException)

Example 13 with JdbcTypeHandle

use of io.trino.plugin.jdbc.JdbcTypeHandle in project trino by trinodb.

the class SingleStoreClient method toColumnMapping.

@Override
public Optional<ColumnMapping> toColumnMapping(ConnectorSession session, Connection connection, JdbcTypeHandle typeHandle) {
    String jdbcTypeName = typeHandle.getJdbcTypeName().orElseThrow(() -> new TrinoException(JDBC_ERROR, "Type name is missing: " + typeHandle));
    Optional<ColumnMapping> mapping = getForcedMappingToVarchar(typeHandle);
    if (mapping.isPresent()) {
        return mapping;
    }
    Optional<ColumnMapping> unsignedMapping = getUnsignedMapping(typeHandle);
    if (unsignedMapping.isPresent()) {
        return unsignedMapping;
    }
    if (jdbcTypeName.equalsIgnoreCase("json")) {
        return Optional.of(jsonColumnMapping());
    }
    switch(typeHandle.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:
            // attempts to treat them as exact in comparisons may lead to problems
            return Optional.of(ColumnMapping.longMapping(REAL, (resultSet, columnIndex) -> floatToRawIntBits(resultSet.getFloat(columnIndex)), realWriteFunction(), DISABLE_PUSHDOWN));
        case Types.DOUBLE:
            return Optional.of(doubleColumnMapping());
        case Types.CHAR:
        case // TODO it it is dummy copied from StandardColumnMappings, verify if it is proper mapping
        Types.NCHAR:
            return Optional.of(defaultCharColumnMapping(typeHandle.getRequiredColumnSize(), false));
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            return Optional.of(defaultVarcharColumnMapping(typeHandle.getRequiredColumnSize(), false));
        case Types.DECIMAL:
            int precision = typeHandle.getRequiredColumnSize();
            int decimalDigits = typeHandle.getRequiredDecimalDigits();
            if (getDecimalRounding(session) == ALLOW_OVERFLOW && precision > Decimals.MAX_PRECISION) {
                int scale = min(decimalDigits, getDecimalDefaultScale(session));
                return Optional.of(decimalColumnMapping(createDecimalType(Decimals.MAX_PRECISION, scale), getDecimalRoundingMode(session)));
            }
            if (precision > Decimals.MAX_PRECISION) {
                break;
            }
            return Optional.of(decimalColumnMapping(createDecimalType(precision, max(decimalDigits, 0))));
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            return Optional.of(varbinaryColumnMapping());
        case Types.DATE:
            return Optional.of(ColumnMapping.longMapping(DATE, dateReadFunctionUsingLocalDate(), dateWriteFunction()));
        case Types.TIME:
            TimeType timeType = createTimeType(getTimePrecision(typeHandle.getRequiredColumnSize()));
            return Optional.of(ColumnMapping.longMapping(timeType, singleStoreTimeReadFunction(timeType), timeWriteFunction(timeType.getPrecision())));
        case Types.TIMESTAMP:
            // TODO (https://github.com/trinodb/trino/issues/5450) Fix DST handling
            TimestampType timestampType = createTimestampType(getTimestampPrecision(typeHandle.getRequiredColumnSize()));
            return Optional.of(timestampColumnMapping(timestampType));
    }
    if (getUnsupportedTypeHandling(session) == CONVERT_TO_VARCHAR) {
        return mapToUnboundedVarchar(typeHandle);
    }
    return Optional.empty();
}
Also used : AggregateFunction(io.trino.spi.connector.AggregateFunction) StandardColumnMappings.bigintWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.bigintWriteFunction) NOT_SUPPORTED(io.trino.spi.StandardErrorCode.NOT_SUPPORTED) StandardColumnMappings.booleanColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.booleanColumnMapping) StandardColumnMappings.defaultVarcharColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.defaultVarcharColumnMapping) ResultSet(java.sql.ResultSet) Map(java.util.Map) StandardColumnMappings.doubleWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.doubleWriteFunction) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) DecimalSessionSessionProperties.getDecimalDefaultScale(io.trino.plugin.jdbc.DecimalSessionSessionProperties.getDecimalDefaultScale) SMALLINT(io.trino.spi.type.SmallintType.SMALLINT) TypeHandlingJdbcSessionProperties.getUnsupportedTypeHandling(io.trino.plugin.jdbc.TypeHandlingJdbcSessionProperties.getUnsupportedTypeHandling) LongWriteFunction(io.trino.plugin.jdbc.LongWriteFunction) SchemaTableName(io.trino.spi.connector.SchemaTableName) Collectors.joining(java.util.stream.Collectors.joining) LongReadFunction(io.trino.plugin.jdbc.LongReadFunction) DateTimeParseException(java.time.format.DateTimeParseException) Stream(java.util.stream.Stream) StandardColumnMappings.smallintWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.smallintWriteFunction) StandardColumnMappings.longDecimalWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.longDecimalWriteFunction) ConnectionFactory(io.trino.plugin.jdbc.ConnectionFactory) CONVERT_TO_VARCHAR(io.trino.plugin.jdbc.UnsupportedTypeHandling.CONVERT_TO_VARCHAR) JdbcTableHandle(io.trino.plugin.jdbc.JdbcTableHandle) DATE(io.trino.spi.type.DateType.DATE) REAL(io.trino.spi.type.RealType.REAL) JoinCondition(io.trino.spi.connector.JoinCondition) StandardColumnMappings.doubleColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.doubleColumnMapping) StandardColumnMappings.booleanWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.booleanWriteFunction) ALLOW_OVERFLOW(io.trino.plugin.jdbc.DecimalConfig.DecimalMapping.ALLOW_OVERFLOW) BOOLEAN(io.trino.spi.type.BooleanType.BOOLEAN) DatabaseMetaData(java.sql.DatabaseMetaData) StandardColumnMappings.bigintColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.bigintColumnMapping) StandardColumnMappings.timeWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.timeWriteFunction) TimestampType(io.trino.spi.type.TimestampType) StandardColumnMappings.defaultCharColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.defaultCharColumnMapping) Float.floatToRawIntBits(java.lang.Float.floatToRawIntBits) SQLException(java.sql.SQLException) StandardColumnMappings.charWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.charWriteFunction) PreparedQuery(io.trino.plugin.jdbc.PreparedQuery) StandardColumnMappings.decimalColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.decimalColumnMapping) Timestamps.round(io.trino.spi.type.Timestamps.round) ColumnHandle(io.trino.spi.connector.ColumnHandle) VARBINARY(io.trino.spi.type.VarbinaryType.VARBINARY) StandardColumnMappings.realWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.realWriteFunction) DecimalType.createDecimalType(io.trino.spi.type.DecimalType.createDecimalType) QueryBuilder(io.trino.plugin.jdbc.QueryBuilder) StandardColumnMappings.smallintColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.smallintColumnMapping) StandardTypes(io.trino.spi.type.StandardTypes) ConnectorSession(io.trino.spi.connector.ConnectorSession) DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) IdentifierMapping(io.trino.plugin.jdbc.mapping.IdentifierMapping) TIMESTAMP_MICROS(io.trino.spi.type.TimestampType.TIMESTAMP_MICROS) CharType(io.trino.spi.type.CharType) DecimalSessionSessionProperties.getDecimalRoundingMode(io.trino.plugin.jdbc.DecimalSessionSessionProperties.getDecimalRoundingMode) StandardColumnMappings.timestampColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.timestampColumnMapping) TINYINT(io.trino.spi.type.TinyintType.TINYINT) StandardColumnMappings.shortDecimalWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.shortDecimalWriteFunction) StandardColumnMappings.varbinaryWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.varbinaryWriteFunction) WriteMapping(io.trino.plugin.jdbc.WriteMapping) JDBC_ERROR(io.trino.plugin.jdbc.JdbcErrorCode.JDBC_ERROR) BaseJdbcConfig(io.trino.plugin.jdbc.BaseJdbcConfig) Connection(java.sql.Connection) BiFunction(java.util.function.BiFunction) StandardColumnMappings.dateReadFunctionUsingLocalDate(io.trino.plugin.jdbc.StandardColumnMappings.dateReadFunctionUsingLocalDate) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) TimestampType.createTimestampType(io.trino.spi.type.TimestampType.createTimestampType) ColumnMapping(io.trino.plugin.jdbc.ColumnMapping) LocalTime(java.time.LocalTime) INTEGER(io.trino.spi.type.IntegerType.INTEGER) TypeSignature(io.trino.spi.type.TypeSignature) ImmutableSet(com.google.common.collect.ImmutableSet) DecimalSessionSessionProperties.getDecimalRounding(io.trino.plugin.jdbc.DecimalSessionSessionProperties.getDecimalRounding) Collection(java.util.Collection) TrinoException(io.trino.spi.TrinoException) Math.min(java.lang.Math.min) String.format(java.lang.String.format) JdbcSortItem(io.trino.plugin.jdbc.JdbcSortItem) List(java.util.List) JdbcTypeHandle(io.trino.plugin.jdbc.JdbcTypeHandle) BIGINT(io.trino.spi.type.BigintType.BIGINT) LocalDate(java.time.LocalDate) Decimals(io.trino.spi.type.Decimals) Optional(java.util.Optional) Math.max(java.lang.Math.max) Pattern(java.util.regex.Pattern) ISO_LOCAL_TIME(java.time.format.DateTimeFormatter.ISO_LOCAL_TIME) StandardColumnMappings.tinyintColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.tinyintColumnMapping) DecimalType(io.trino.spi.type.DecimalType) StandardColumnMappings.integerColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.integerColumnMapping) Types(java.sql.Types) StandardColumnMappings.timestampWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.timestampWriteFunction) StandardColumnMappings.varbinaryColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.varbinaryColumnMapping) TimeType(io.trino.spi.type.TimeType) StandardColumnMappings.varcharWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.varcharWriteFunction) StandardColumnMappings.tinyintWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.tinyintWriteFunction) PICOSECONDS_PER_NANOSECOND(io.trino.spi.type.Timestamps.PICOSECONDS_PER_NANOSECOND) Type(io.trino.spi.type.Type) TimeType.createTimeType(io.trino.spi.type.TimeType.createTimeType) NANOSECONDS_PER_DAY(io.trino.spi.type.Timestamps.NANOSECONDS_PER_DAY) Inject(javax.inject.Inject) VarcharType(io.trino.spi.type.VarcharType) JoinStatistics(io.trino.spi.connector.JoinStatistics) JoinType(io.trino.spi.connector.JoinType) Verify.verify(com.google.common.base.Verify.verify) Objects.requireNonNull(java.util.Objects.requireNonNull) JsonTypeUtil.jsonParse(io.trino.plugin.base.util.JsonTypeUtil.jsonParse) BaseJdbcClient(io.trino.plugin.jdbc.BaseJdbcClient) JdbcJoinCondition(io.trino.plugin.jdbc.JdbcJoinCondition) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) PICOSECONDS_PER_DAY(io.trino.spi.type.Timestamps.PICOSECONDS_PER_DAY) StandardColumnMappings.integerWriteFunction(io.trino.plugin.jdbc.StandardColumnMappings.integerWriteFunction) DISABLE_PUSHDOWN(io.trino.plugin.jdbc.PredicatePushdownController.DISABLE_PUSHDOWN) DateTimeFormatter(java.time.format.DateTimeFormatter) TypeManager(io.trino.spi.type.TypeManager) TrinoException(io.trino.spi.TrinoException) TimestampType(io.trino.spi.type.TimestampType) TimestampType.createTimestampType(io.trino.spi.type.TimestampType.createTimestampType) StandardColumnMappings.booleanColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.booleanColumnMapping) StandardColumnMappings.defaultVarcharColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.defaultVarcharColumnMapping) StandardColumnMappings.doubleColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.doubleColumnMapping) StandardColumnMappings.bigintColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.bigintColumnMapping) StandardColumnMappings.defaultCharColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.defaultCharColumnMapping) StandardColumnMappings.decimalColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.decimalColumnMapping) StandardColumnMappings.smallintColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.smallintColumnMapping) StandardColumnMappings.timestampColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.timestampColumnMapping) ColumnMapping(io.trino.plugin.jdbc.ColumnMapping) StandardColumnMappings.tinyintColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.tinyintColumnMapping) StandardColumnMappings.integerColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.integerColumnMapping) StandardColumnMappings.varbinaryColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.varbinaryColumnMapping) TimeType(io.trino.spi.type.TimeType) TimeType.createTimeType(io.trino.spi.type.TimeType.createTimeType)

Example 14 with JdbcTypeHandle

use of io.trino.plugin.jdbc.JdbcTypeHandle in project trino by trinodb.

the class PostgreSqlClient method getArrayElementTypeHandle.

private static JdbcTypeHandle getArrayElementTypeHandle(Connection connection, JdbcTypeHandle arrayTypeHandle) {
    String jdbcTypeName = arrayTypeHandle.getJdbcTypeName().orElseThrow(() -> new TrinoException(JDBC_ERROR, "Type name is missing: " + arrayTypeHandle));
    try {
        TypeInfo typeInfo = connection.unwrap(PgConnection.class).getTypeInfo();
        int pgElementOid = typeInfo.getPGArrayElement(typeInfo.getPGType(jdbcTypeName));
        verify(arrayTypeHandle.getCaseSensitivity().isEmpty(), "Case sensitivity not supported");
        return new JdbcTypeHandle(typeInfo.getSQLType(pgElementOid), Optional.of(typeInfo.getPGType(pgElementOid)), arrayTypeHandle.getColumnSize(), arrayTypeHandle.getDecimalDigits(), arrayTypeHandle.getArrayDimensions(), Optional.empty());
    } catch (SQLException e) {
        throw new TrinoException(JDBC_ERROR, e);
    }
}
Also used : JdbcTypeHandle(io.trino.plugin.jdbc.JdbcTypeHandle) SQLException(java.sql.SQLException) PgConnection(org.postgresql.jdbc.PgConnection) TrinoException(io.trino.spi.TrinoException) TypeInfo(org.postgresql.core.TypeInfo) ImplementAvgFloatingPoint(io.trino.plugin.jdbc.aggregation.ImplementAvgFloatingPoint)

Aggregations

JdbcTypeHandle (io.trino.plugin.jdbc.JdbcTypeHandle)14 TrinoException (io.trino.spi.TrinoException)12 ColumnMapping (io.trino.plugin.jdbc.ColumnMapping)9 JdbcColumnHandle (io.trino.plugin.jdbc.JdbcColumnHandle)7 SQLException (java.sql.SQLException)7 StandardColumnMappings.bigintColumnMapping (io.trino.plugin.jdbc.StandardColumnMappings.bigintColumnMapping)6 StandardColumnMappings.decimalColumnMapping (io.trino.plugin.jdbc.StandardColumnMappings.decimalColumnMapping)6 StandardColumnMappings.doubleColumnMapping (io.trino.plugin.jdbc.StandardColumnMappings.doubleColumnMapping)6 StandardColumnMappings.integerColumnMapping (io.trino.plugin.jdbc.StandardColumnMappings.integerColumnMapping)6 StandardColumnMappings.smallintColumnMapping (io.trino.plugin.jdbc.StandardColumnMappings.smallintColumnMapping)6 StandardColumnMappings.varbinaryColumnMapping (io.trino.plugin.jdbc.StandardColumnMappings.varbinaryColumnMapping)6 SchemaTableName (io.trino.spi.connector.SchemaTableName)6 Verify.verify (com.google.common.base.Verify.verify)5 ImmutableSet (com.google.common.collect.ImmutableSet)5 BaseJdbcClient (io.trino.plugin.jdbc.BaseJdbcClient)5 BaseJdbcConfig (io.trino.plugin.jdbc.BaseJdbcConfig)5 ConnectionFactory (io.trino.plugin.jdbc.ConnectionFactory)5 JDBC_ERROR (io.trino.plugin.jdbc.JdbcErrorCode.JDBC_ERROR)5 JdbcTableHandle (io.trino.plugin.jdbc.JdbcTableHandle)5 StandardColumnMappings.booleanColumnMapping (io.trino.plugin.jdbc.StandardColumnMappings.booleanColumnMapping)5