Search in sources :

Example 1 with ArrayMapping

use of io.trino.plugin.postgresql.PostgreSqlConfig.ArrayMapping in project trino by trinodb.

the class PostgreSqlClient method arrayToTrinoType.

private Optional<ColumnMapping> arrayToTrinoType(ConnectorSession session, Connection connection, JdbcTypeHandle typeHandle) {
    checkArgument(typeHandle.getJdbcType() == Types.ARRAY, "Not array type");
    ArrayMapping arrayMapping = getArrayMapping(session);
    if (arrayMapping == DISABLED) {
        return Optional.empty();
    }
    // resolve and map base array element type
    JdbcTypeHandle baseElementTypeHandle = getArrayElementTypeHandle(connection, typeHandle);
    String baseElementTypeName = baseElementTypeHandle.getJdbcTypeName().orElseThrow(() -> new TrinoException(JDBC_ERROR, "Element type name is missing: " + baseElementTypeHandle));
    if (baseElementTypeHandle.getJdbcType() == Types.BINARY) {
        // https://github.com/pgjdbc/pgjdbc/pull/1184
        return Optional.empty();
    }
    Optional<ColumnMapping> baseElementMapping = toColumnMapping(session, connection, baseElementTypeHandle);
    if (arrayMapping == AS_ARRAY) {
        if (typeHandle.getArrayDimensions().isEmpty()) {
            return Optional.empty();
        }
        return baseElementMapping.map(elementMapping -> {
            ArrayType prestoArrayType = new ArrayType(elementMapping.getType());
            ColumnMapping arrayColumnMapping = arrayColumnMapping(session, prestoArrayType, elementMapping, baseElementTypeName);
            int arrayDimensions = typeHandle.getArrayDimensions().get();
            for (int i = 1; i < arrayDimensions; i++) {
                prestoArrayType = new ArrayType(prestoArrayType);
                arrayColumnMapping = arrayColumnMapping(session, prestoArrayType, arrayColumnMapping, baseElementTypeName);
            }
            return arrayColumnMapping;
        });
    }
    if (arrayMapping == AS_JSON) {
        return baseElementMapping.map(elementMapping -> arrayAsJsonColumnMapping(session, elementMapping));
    }
    throw new IllegalStateException("Unsupported array mapping type: " + arrayMapping);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) ArrayMapping(io.trino.plugin.postgresql.PostgreSqlConfig.ArrayMapping) PostgreSqlSessionProperties.getArrayMapping(io.trino.plugin.postgresql.PostgreSqlSessionProperties.getArrayMapping) JdbcTypeHandle(io.trino.plugin.jdbc.JdbcTypeHandle) TrinoException(io.trino.spi.TrinoException) StandardColumnMappings.bigintColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.bigintColumnMapping) StandardColumnMappings.decimalColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.decimalColumnMapping) ColumnMapping(io.trino.plugin.jdbc.ColumnMapping) StandardColumnMappings.realColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.realColumnMapping) StandardColumnMappings.varbinaryColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.varbinaryColumnMapping) StandardColumnMappings.booleanColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.booleanColumnMapping) StandardColumnMappings.doubleColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.doubleColumnMapping) StandardColumnMappings.smallintColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.smallintColumnMapping) StandardColumnMappings.integerColumnMapping(io.trino.plugin.jdbc.StandardColumnMappings.integerColumnMapping) ImplementAvgFloatingPoint(io.trino.plugin.jdbc.aggregation.ImplementAvgFloatingPoint)

Aggregations

ColumnMapping (io.trino.plugin.jdbc.ColumnMapping)1 JdbcTypeHandle (io.trino.plugin.jdbc.JdbcTypeHandle)1 StandardColumnMappings.bigintColumnMapping (io.trino.plugin.jdbc.StandardColumnMappings.bigintColumnMapping)1 StandardColumnMappings.booleanColumnMapping (io.trino.plugin.jdbc.StandardColumnMappings.booleanColumnMapping)1 StandardColumnMappings.decimalColumnMapping (io.trino.plugin.jdbc.StandardColumnMappings.decimalColumnMapping)1 StandardColumnMappings.doubleColumnMapping (io.trino.plugin.jdbc.StandardColumnMappings.doubleColumnMapping)1 StandardColumnMappings.integerColumnMapping (io.trino.plugin.jdbc.StandardColumnMappings.integerColumnMapping)1 StandardColumnMappings.realColumnMapping (io.trino.plugin.jdbc.StandardColumnMappings.realColumnMapping)1 StandardColumnMappings.smallintColumnMapping (io.trino.plugin.jdbc.StandardColumnMappings.smallintColumnMapping)1 StandardColumnMappings.varbinaryColumnMapping (io.trino.plugin.jdbc.StandardColumnMappings.varbinaryColumnMapping)1 ImplementAvgFloatingPoint (io.trino.plugin.jdbc.aggregation.ImplementAvgFloatingPoint)1 ArrayMapping (io.trino.plugin.postgresql.PostgreSqlConfig.ArrayMapping)1 PostgreSqlSessionProperties.getArrayMapping (io.trino.plugin.postgresql.PostgreSqlSessionProperties.getArrayMapping)1 TrinoException (io.trino.spi.TrinoException)1 ArrayType (io.trino.spi.type.ArrayType)1