Search in sources :

Example 6 with VarbinaryType

use of io.trino.spi.type.VarbinaryType in project trino by trinodb.

the class PhoenixClient method toWriteMapping.

@Override
public WriteMapping toWriteMapping(ConnectorSession session, Type type) {
    if (type == BOOLEAN) {
        return WriteMapping.booleanMapping("boolean", booleanWriteFunction());
    }
    if (type == TINYINT) {
        return WriteMapping.longMapping("tinyint", tinyintWriteFunction());
    }
    if (type == SMALLINT) {
        return WriteMapping.longMapping("smallint", smallintWriteFunction());
    }
    if (type == INTEGER) {
        return WriteMapping.longMapping("integer", integerWriteFunction());
    }
    if (type == BIGINT) {
        return WriteMapping.longMapping("bigint", bigintWriteFunction());
    }
    if (type == REAL) {
        return WriteMapping.longMapping("float", realWriteFunction());
    }
    if (type == DOUBLE) {
        return WriteMapping.doubleMapping("double", doubleWriteFunction());
    }
    if (type instanceof DecimalType) {
        DecimalType decimalType = (DecimalType) type;
        String dataType = format("decimal(%s, %s)", decimalType.getPrecision(), decimalType.getScale());
        if (decimalType.isShort()) {
            return WriteMapping.longMapping(dataType, shortDecimalWriteFunction(decimalType));
        }
        return WriteMapping.objectMapping(dataType, longDecimalWriteFunction(decimalType));
    }
    if (type instanceof CharType) {
        return WriteMapping.sliceMapping("char(" + ((CharType) type).getLength() + ")", charWriteFunction());
    }
    if (type instanceof VarcharType) {
        VarcharType varcharType = (VarcharType) type;
        String dataType;
        if (varcharType.isUnbounded()) {
            dataType = "varchar";
        } else {
            dataType = "varchar(" + varcharType.getBoundedLength() + ")";
        }
        return WriteMapping.sliceMapping(dataType, varcharWriteFunction());
    }
    if (type instanceof VarbinaryType) {
        return WriteMapping.sliceMapping("varbinary", varbinaryWriteFunction());
    }
    if (type == DATE) {
        return WriteMapping.longMapping("date", dateWriteFunctionUsingString());
    }
    if (TIME.equals(type)) {
        return WriteMapping.longMapping("time", timeWriteFunctionUsingSqlTime());
    }
    // Phoenix doesn't support _WITH_TIME_ZONE
    if (TIME_WITH_TIME_ZONE.equals(type) || TIMESTAMP_TZ_MILLIS.equals(type)) {
        throw new TrinoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
    }
    if (type instanceof ArrayType) {
        Type elementType = ((ArrayType) type).getElementType();
        String elementDataType = toWriteMapping(session, elementType).getDataType().toUpperCase(ENGLISH);
        String elementWriteName = getArrayElementPhoenixTypeName(session, this, elementType);
        return WriteMapping.objectMapping(elementDataType + " ARRAY", arrayWriteFunction(session, elementType, elementWriteName));
    }
    throw new TrinoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
}
Also used : ArrayType(io.trino.spi.type.ArrayType) BloomType(org.apache.hadoop.hbase.regionserver.BloomType) JDBCType(java.sql.JDBCType) DecimalType.createDecimalType(io.trino.spi.type.DecimalType.createDecimalType) VarbinaryType(io.trino.spi.type.VarbinaryType) CharType(io.trino.spi.type.CharType) ArrayType(io.trino.spi.type.ArrayType) PDataType(org.apache.phoenix.schema.types.PDataType) DecimalType(io.trino.spi.type.DecimalType) Type(io.trino.spi.type.Type) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) VarcharType(io.trino.spi.type.VarcharType) VarbinaryType(io.trino.spi.type.VarbinaryType) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) VarcharType(io.trino.spi.type.VarcharType) DecimalType.createDecimalType(io.trino.spi.type.DecimalType.createDecimalType) DecimalType(io.trino.spi.type.DecimalType) TrinoException(io.trino.spi.TrinoException) CharType(io.trino.spi.type.CharType)

Example 7 with VarbinaryType

use of io.trino.spi.type.VarbinaryType in project trino by trinodb.

the class PhoenixClient method toWriteMapping.

@Override
public WriteMapping toWriteMapping(ConnectorSession session, Type type) {
    if (type == BOOLEAN) {
        return WriteMapping.booleanMapping("boolean", booleanWriteFunction());
    }
    if (type == TINYINT) {
        return WriteMapping.longMapping("tinyint", tinyintWriteFunction());
    }
    if (type == SMALLINT) {
        return WriteMapping.longMapping("smallint", smallintWriteFunction());
    }
    if (type == INTEGER) {
        return WriteMapping.longMapping("integer", integerWriteFunction());
    }
    if (type == BIGINT) {
        return WriteMapping.longMapping("bigint", bigintWriteFunction());
    }
    if (type == REAL) {
        return WriteMapping.longMapping("float", realWriteFunction());
    }
    if (type == DOUBLE) {
        return WriteMapping.doubleMapping("double", doubleWriteFunction());
    }
    if (type instanceof DecimalType) {
        DecimalType decimalType = (DecimalType) type;
        String dataType = format("decimal(%s, %s)", decimalType.getPrecision(), decimalType.getScale());
        if (decimalType.isShort()) {
            return WriteMapping.longMapping(dataType, shortDecimalWriteFunction(decimalType));
        }
        return WriteMapping.objectMapping(dataType, longDecimalWriteFunction(decimalType));
    }
    if (type instanceof CharType) {
        return WriteMapping.sliceMapping("char(" + ((CharType) type).getLength() + ")", charWriteFunction());
    }
    if (type instanceof VarcharType) {
        VarcharType varcharType = (VarcharType) type;
        String dataType;
        if (varcharType.isUnbounded()) {
            dataType = "varchar";
        } else {
            dataType = "varchar(" + varcharType.getBoundedLength() + ")";
        }
        return WriteMapping.sliceMapping(dataType, varcharWriteFunction());
    }
    if (type instanceof VarbinaryType) {
        return WriteMapping.sliceMapping("varbinary", varbinaryWriteFunction());
    }
    if (type == DATE) {
        return WriteMapping.longMapping("date", dateWriteFunctionUsingString());
    }
    if (TIME.equals(type)) {
        return WriteMapping.longMapping("time", timeWriteFunctionUsingSqlTime());
    }
    // Phoenix doesn't support _WITH_TIME_ZONE
    if (TIME_WITH_TIME_ZONE.equals(type) || TIMESTAMP_TZ_MILLIS.equals(type)) {
        throw new TrinoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
    }
    if (type instanceof ArrayType) {
        Type elementType = ((ArrayType) type).getElementType();
        String elementDataType = toWriteMapping(session, elementType).getDataType().toUpperCase(ENGLISH);
        String elementWriteName = getArrayElementPhoenixTypeName(session, this, elementType);
        return WriteMapping.objectMapping(elementDataType + " ARRAY", arrayWriteFunction(session, elementType, elementWriteName));
    }
    throw new TrinoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
}
Also used : ArrayType(io.trino.spi.type.ArrayType) BloomType(org.apache.hadoop.hbase.regionserver.BloomType) JDBCType(java.sql.JDBCType) DecimalType.createDecimalType(io.trino.spi.type.DecimalType.createDecimalType) VarbinaryType(io.trino.spi.type.VarbinaryType) CharType(io.trino.spi.type.CharType) ArrayType(io.trino.spi.type.ArrayType) PDataType(org.apache.phoenix.schema.types.PDataType) DecimalType(io.trino.spi.type.DecimalType) Type(io.trino.spi.type.Type) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) VarcharType(io.trino.spi.type.VarcharType) VarbinaryType(io.trino.spi.type.VarbinaryType) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) VarcharType(io.trino.spi.type.VarcharType) DecimalType.createDecimalType(io.trino.spi.type.DecimalType.createDecimalType) DecimalType(io.trino.spi.type.DecimalType) TrinoException(io.trino.spi.TrinoException) CharType(io.trino.spi.type.CharType)

Example 8 with VarbinaryType

use of io.trino.spi.type.VarbinaryType in project trino by trinodb.

the class SqlServerClient method toWriteMapping.

@Override
public WriteMapping toWriteMapping(ConnectorSession session, Type type) {
    if (type == BOOLEAN) {
        return WriteMapping.booleanMapping("bit", booleanWriteFunction());
    }
    if (type == TINYINT) {
        return WriteMapping.longMapping("tinyint", tinyintWriteFunction());
    }
    if (type == SMALLINT) {
        return WriteMapping.longMapping("smallint", smallintWriteFunction());
    }
    if (type == INTEGER) {
        return WriteMapping.longMapping("integer", integerWriteFunction());
    }
    if (type == BIGINT) {
        return WriteMapping.longMapping("bigint", bigintWriteFunction());
    }
    if (type == REAL) {
        return WriteMapping.longMapping("real", realWriteFunction());
    }
    if (type == DOUBLE) {
        return WriteMapping.doubleMapping("double precision", doubleWriteFunction());
    }
    if (type instanceof DecimalType) {
        DecimalType decimalType = (DecimalType) type;
        String dataType = format("decimal(%s, %s)", decimalType.getPrecision(), decimalType.getScale());
        if (decimalType.isShort()) {
            return WriteMapping.longMapping(dataType, shortDecimalWriteFunction(decimalType));
        }
        return WriteMapping.objectMapping(dataType, longDecimalWriteFunction(decimalType));
    }
    if (type instanceof VarcharType) {
        VarcharType varcharType = (VarcharType) type;
        String dataType;
        if (varcharType.isUnbounded() || varcharType.getBoundedLength() > 4000) {
            dataType = "nvarchar(max)";
        } else {
            dataType = "nvarchar(" + varcharType.getBoundedLength() + ")";
        }
        return WriteMapping.sliceMapping(dataType, varcharWriteFunction());
    }
    if (type instanceof CharType) {
        CharType charType = (CharType) type;
        String dataType;
        if (charType.getLength() > 4000) {
            dataType = "nvarchar(max)";
        } else {
            dataType = "nchar(" + charType.getLength() + ")";
        }
        return WriteMapping.sliceMapping(dataType, charWriteFunction());
    }
    if (type instanceof VarbinaryType) {
        return WriteMapping.sliceMapping("varbinary(max)", varbinaryWriteFunction());
    }
    if (type == DATE) {
        return WriteMapping.longMapping("date", sqlServerDateWriteFunction());
    }
    if (type instanceof TimeType) {
        TimeType timeType = (TimeType) type;
        int precision = min(timeType.getPrecision(), MAX_SUPPORTED_TEMPORAL_PRECISION);
        String dataType = format("time(%d)", precision);
        return WriteMapping.longMapping(dataType, sqlServerTimeWriteFunction(precision));
    }
    if (type instanceof TimestampType) {
        TimestampType timestampType = (TimestampType) type;
        int precision = min(timestampType.getPrecision(), MAX_SUPPORTED_TEMPORAL_PRECISION);
        String dataType = format("datetime2(%d)", precision);
        if (timestampType.getPrecision() <= MAX_SHORT_PRECISION) {
            return WriteMapping.longMapping(dataType, timestampWriteFunction(timestampType));
        }
        return WriteMapping.objectMapping(dataType, longTimestampWriteFunction(timestampType, precision));
    }
    throw new TrinoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
}
Also used : VarbinaryType(io.trino.spi.type.VarbinaryType) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) VarcharType(io.trino.spi.type.VarcharType) DecimalType.createDecimalType(io.trino.spi.type.DecimalType.createDecimalType) DecimalType(io.trino.spi.type.DecimalType) TimestampType(io.trino.spi.type.TimestampType) TimestampType.createTimestampType(io.trino.spi.type.TimestampType.createTimestampType) TrinoException(io.trino.spi.TrinoException) CharType(io.trino.spi.type.CharType) ImplementAvgFloatingPoint(io.trino.plugin.jdbc.aggregation.ImplementAvgFloatingPoint) TimeType(io.trino.spi.type.TimeType) TimeType.createTimeType(io.trino.spi.type.TimeType.createTimeType)

Aggregations

VarbinaryType (io.trino.spi.type.VarbinaryType)8 VarcharType (io.trino.spi.type.VarcharType)8 CharType (io.trino.spi.type.CharType)7 DecimalType (io.trino.spi.type.DecimalType)7 TrinoException (io.trino.spi.TrinoException)5 DecimalType.createDecimalType (io.trino.spi.type.DecimalType.createDecimalType)5 ArrayType (io.trino.spi.type.ArrayType)4 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)4 TimestampType (io.trino.spi.type.TimestampType)3 Type (io.trino.spi.type.Type)3 MapType (io.trino.spi.type.MapType)2 RowType (io.trino.spi.type.RowType)2 TimeType (io.trino.spi.type.TimeType)2 JDBCType (java.sql.JDBCType)2 BloomType (org.apache.hadoop.hbase.regionserver.BloomType)2 PDataType (org.apache.phoenix.schema.types.PDataType)2 VerifyException (com.google.common.base.VerifyException)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImplementAvgFloatingPoint (io.trino.plugin.jdbc.aggregation.ImplementAvgFloatingPoint)1 SqlTime (io.trino.spi.type.SqlTime)1