Search in sources :

Example 26 with ArrayType

use of io.prestosql.spi.type.ArrayType in project hetu-core by openlookeng.

the class GreenPlumSqlClient method toPrestoType.

@Override
public Optional<ColumnMapping> toPrestoType(ConnectorSession session, Connection connection, JdbcTypeHandle typeHandle) {
    String jdbcTypeName = typeHandle.getJdbcTypeName().orElseThrow(() -> new PrestoException(JDBC_ERROR, "Type name is missing: " + typeHandle));
    switch(jdbcTypeName) {
        case "uuid":
            return Optional.of(uuidColumnMapping());
        case "jsonb":
        case "json":
            return Optional.of(jsonColumnMapping());
        case "timestamptz":
            // PostgreSQL's "timestamp with time zone" is reported as Types.TIMESTAMP rather than Types.TIMESTAMP_WITH_TIMEZONE
            return Optional.of(timestampWithTimeZoneColumnMapping());
        default:
            break;
    }
    if (typeHandle.getJdbcType() == Types.VARCHAR && !jdbcTypeName.equals("varchar")) {
        // This can be e.g. an ENUM
        return Optional.of(typedVarcharColumnMapping(jdbcTypeName));
    }
    if (typeHandle.getJdbcType() == Types.TIMESTAMP) {
        return Optional.of(timestampColumnMapping());
    }
    if (typeHandle.getJdbcType() == Types.ARRAY && supportArrays) {
        if (!typeHandle.getArrayDimensions().isPresent()) {
            return Optional.empty();
        }
        JdbcTypeHandle elementTypeHandle = getArrayElementTypeHandle(connection, typeHandle);
        String elementTypeName = typeHandle.getJdbcTypeName().orElseThrow(() -> new PrestoException(JDBC_ERROR, "Element type name is missing: " + elementTypeHandle));
        if (elementTypeHandle.getJdbcType() == Types.VARBINARY) {
            // https://github.com/pgjdbc/pgjdbc/pull/1184
            return Optional.empty();
        }
        return toPrestoType(session, connection, elementTypeHandle).map(elementMapping -> {
            ArrayType prestoArrayType = new ArrayType(elementMapping.getType());
            int arrayDimensions = typeHandle.getArrayDimensions().get();
            for (int i = 1; i < arrayDimensions; i++) {
                prestoArrayType = new ArrayType(prestoArrayType);
            }
            return arrayColumnMapping(session, prestoArrayType, elementTypeName);
        });
    }
    // in the scenario of push down, we will verify the type correctness in our query push down
    return super.toPrestoType(session, connection, typeHandle);
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) JdbcTypeHandle(io.prestosql.plugin.jdbc.JdbcTypeHandle) PrestoException(io.prestosql.spi.PrestoException)

Example 27 with ArrayType

use of io.prestosql.spi.type.ArrayType in project hetu-core by openlookeng.

the class GreenPlumSqlClient method toWriteMapping.

@Override
public WriteMapping toWriteMapping(ConnectorSession session, Type type) {
    if (VARBINARY.equals(type)) {
        return WriteMapping.sliceMapping("bytea", varbinaryWriteFunction());
    }
    if (TIMESTAMP.equals(type)) {
        return WriteMapping.longMapping("timestamp", timestampWriteFunction());
    }
    if (TIMESTAMP_WITH_TIME_ZONE.equals(type)) {
        return WriteMapping.longMapping("timestamp with time zone", timestampWithTimeZoneWriteFunction());
    }
    if (TinyintType.TINYINT.equals(type)) {
        return WriteMapping.longMapping("smallint", tinyintWriteFunction());
    }
    if (type.getTypeSignature().getBase().equals(StandardTypes.JSON)) {
        return WriteMapping.sliceMapping("jsonb", typedVarcharWriteFunction("json"));
    }
    if (type.getTypeSignature().getBase().equals(StandardTypes.UUID)) {
        return WriteMapping.sliceMapping("uuid", uuidWriteFunction());
    }
    if (type instanceof ArrayType && supportArrays) {
        Type elementType = ((ArrayType) type).getElementType();
        String elementDataType = toWriteMapping(session, elementType).getDataType();
        return WriteMapping.blockMapping(elementDataType + "[]", arrayWriteFunction(session, elementType, getArrayElementPgTypeName(session, this, elementType)));
    }
    return super.toWriteMapping(session, type);
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) TinyintType(io.prestosql.spi.type.TinyintType) VarcharType(io.prestosql.spi.type.VarcharType) Type(io.prestosql.spi.type.Type) ArrayType(io.prestosql.spi.type.ArrayType)

Example 28 with ArrayType

use of io.prestosql.spi.type.ArrayType in project hetu-core by openlookeng.

the class BlockAssertions method createArrayBigintBlock.

public static Block createArrayBigintBlock(Iterable<? extends Iterable<Long>> values) {
    ArrayType arrayType = new ArrayType(BIGINT);
    BlockBuilder builder = arrayType.createBlockBuilder(null, 100);
    for (Iterable<Long> value : values) {
        if (value == null) {
            builder.appendNull();
        } else {
            arrayType.writeObject(builder, createLongsBlock(value));
        }
    }
    return builder.build();
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) BlockBuilder(io.prestosql.spi.block.BlockBuilder) RowBlockBuilder(io.prestosql.spi.block.RowBlockBuilder)

Example 29 with ArrayType

use of io.prestosql.spi.type.ArrayType in project hetu-core by openlookeng.

the class BlockAssertions method createStringArraysBlock.

public static Block createStringArraysBlock(Iterable<? extends Iterable<String>> values) {
    ArrayType arrayType = new ArrayType(VARCHAR);
    BlockBuilder builder = arrayType.createBlockBuilder(null, 100);
    for (Iterable<String> value : values) {
        if (value == null) {
            builder.appendNull();
        } else {
            arrayType.writeObject(builder, createStringsBlock(value));
        }
    }
    return builder.build();
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) BlockBuilder(io.prestosql.spi.block.BlockBuilder) RowBlockBuilder(io.prestosql.spi.block.RowBlockBuilder)

Example 30 with ArrayType

use of io.prestosql.spi.type.ArrayType in project hetu-core by openlookeng.

the class TestTypeUtil method testParametricType.

@Test
public void testParametricType() {
    Type type = parseType(typeManager, "decimal(10,2)");
    assertTrue(type instanceof DecimalType);
    type = parseType(typeManager, "char(100)");
    assertTrue(type instanceof CharType);
    type = parseType(typeManager, "varchar(100)");
    assertTrue(type instanceof VarcharType);
    type = parseType(typeManager, "array(varchar(10))");
    assertTrue(type instanceof ArrayType);
    type = parseType(typeManager, "row(street varchar(10))");
    assertTrue(type instanceof RowType);
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) BigintType(io.prestosql.spi.type.BigintType) UnknownType(io.prestosql.spi.type.UnknownType) CharType(io.prestosql.spi.type.CharType) DecimalType(io.prestosql.spi.type.DecimalType) HyperLogLogType(io.prestosql.spi.type.HyperLogLogType) DoubleType(io.prestosql.spi.type.DoubleType) P4HyperLogLogType(io.prestosql.spi.type.P4HyperLogLogType) RowType(io.prestosql.spi.type.RowType) TimestampWithTimeZoneType(io.prestosql.spi.type.TimestampWithTimeZoneType) Type(io.prestosql.spi.type.Type) SmallintType(io.prestosql.spi.type.SmallintType) TimeWithTimeZoneType(io.prestosql.spi.type.TimeWithTimeZoneType) IntegerType(io.prestosql.spi.type.IntegerType) TimeType(io.prestosql.spi.type.TimeType) RealType(io.prestosql.spi.type.RealType) ArrayType(io.prestosql.spi.type.ArrayType) VarbinaryType(io.prestosql.spi.type.VarbinaryType) TimestampType(io.prestosql.spi.type.TimestampType) DateType(io.prestosql.spi.type.DateType) BooleanType(io.prestosql.spi.type.BooleanType) TypeUtil.parseType(io.prestosql.client.util.TypeUtil.parseType) VarcharType(io.prestosql.spi.type.VarcharType) VarcharType(io.prestosql.spi.type.VarcharType) DecimalType(io.prestosql.spi.type.DecimalType) RowType(io.prestosql.spi.type.RowType) CharType(io.prestosql.spi.type.CharType) Test(org.testng.annotations.Test)

Aggregations

ArrayType (io.prestosql.spi.type.ArrayType)250 Test (org.testng.annotations.Test)182 RowType (io.prestosql.spi.type.RowType)100 Type (io.prestosql.spi.type.Type)99 List (java.util.List)86 ImmutableList (com.google.common.collect.ImmutableList)84 ArrayList (java.util.ArrayList)73 Arrays.asList (java.util.Arrays.asList)64 Collections.singletonList (java.util.Collections.singletonList)64 MessageType (org.apache.parquet.schema.MessageType)58 MessageTypeParser.parseMessageType (org.apache.parquet.schema.MessageTypeParser.parseMessageType)54 VarcharType.createUnboundedVarcharType (io.prestosql.spi.type.VarcharType.createUnboundedVarcharType)53 DecimalType.createDecimalType (io.prestosql.spi.type.DecimalType.createDecimalType)49 StructuralTestUtil.mapType (io.prestosql.tests.StructuralTestUtil.mapType)48 MapType (io.prestosql.spi.type.MapType)31 BigInteger (java.math.BigInteger)24 Map (java.util.Map)23 HashMap (java.util.HashMap)21 Block (io.prestosql.spi.block.Block)20 VarcharType (io.prestosql.spi.type.VarcharType)20