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);
}
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);
}
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();
}
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();
}
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);
}
Aggregations