Search in sources :

Example 1 with TimeWithTimeZoneType

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

the class TestTypeUtil method testParseType.

@Test
public void testParseType() {
    Type type = parseType(typeManager, "bigint");
    assertTrue(type instanceof BigintType);
    type = parseType(typeManager, "integer");
    assertTrue(type instanceof IntegerType);
    type = parseType(typeManager, "smallint");
    assertTrue(type instanceof SmallintType);
    type = parseType(typeManager, "boolean");
    assertTrue(type instanceof BooleanType);
    type = parseType(typeManager, "date");
    assertTrue(type instanceof DateType);
    type = parseType(typeManager, "real");
    assertTrue(type instanceof RealType);
    type = parseType(typeManager, "double");
    assertTrue(type instanceof DoubleType);
    type = parseType(typeManager, "HyperLogLog");
    assertTrue(type instanceof HyperLogLogType);
    type = parseType(typeManager, "P4HyperLogLog");
    assertTrue(type instanceof P4HyperLogLogType);
    type = parseType(typeManager, "timestamp");
    assertTrue(type instanceof TimestampType);
    type = parseType(typeManager, "timestamp with time zone");
    assertTrue(type instanceof TimestampWithTimeZoneType);
    type = parseType(typeManager, "time");
    assertTrue(type instanceof TimeType);
    type = parseType(typeManager, "time with time zone");
    assertTrue(type instanceof TimeWithTimeZoneType);
    type = parseType(typeManager, "varbinary");
    assertTrue(type instanceof VarbinaryType);
    type = parseType(typeManager, "unknown");
    assertTrue(type instanceof UnknownType);
}
Also used : BooleanType(io.prestosql.spi.type.BooleanType) P4HyperLogLogType(io.prestosql.spi.type.P4HyperLogLogType) TimeWithTimeZoneType(io.prestosql.spi.type.TimeWithTimeZoneType) RealType(io.prestosql.spi.type.RealType) BigintType(io.prestosql.spi.type.BigintType) TimeType(io.prestosql.spi.type.TimeType) IntegerType(io.prestosql.spi.type.IntegerType) UnknownType(io.prestosql.spi.type.UnknownType) 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) HyperLogLogType(io.prestosql.spi.type.HyperLogLogType) P4HyperLogLogType(io.prestosql.spi.type.P4HyperLogLogType) VarbinaryType(io.prestosql.spi.type.VarbinaryType) DoubleType(io.prestosql.spi.type.DoubleType) TimestampWithTimeZoneType(io.prestosql.spi.type.TimestampWithTimeZoneType) TimestampType(io.prestosql.spi.type.TimestampType) SmallintType(io.prestosql.spi.type.SmallintType) DateType(io.prestosql.spi.type.DateType) Test(org.testng.annotations.Test)

Example 2 with TimeWithTimeZoneType

use of io.prestosql.spi.type.TimeWithTimeZoneType in project TiBigData by tidb-incubator.

the class TypeHelpers method toSqlString.

public static String toSqlString(Type type) {
    if (type instanceof TimeWithTimeZoneType || type instanceof TimestampWithTimeZoneType) {
        throw new PrestoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
    }
    if (type instanceof TimestampType) {
        return format("timestamp(%s)", ((TimestampType) type).getPrecision());
    }
    if (type instanceof VarcharType) {
        VarcharType varcharType = (VarcharType) type;
        if (varcharType.isUnbounded()) {
            return "longtext";
        }
        Integer length = varcharType.getLength().orElseThrow(IllegalStateException::new);
        if (length <= 255) {
            return "tinytext";
        }
        if (length <= 65535) {
            return "text";
        }
        if (length <= 16777215) {
            return "mediumtext";
        }
        return "longtext";
    }
    if (type instanceof CharType) {
        int length = ((CharType) type).getLength();
        if (length <= 255) {
            return "char(" + length + ")";
        }
        return "text";
    }
    if (type instanceof DecimalType) {
        return format("decimal(%s, %s)", ((DecimalType) type).getPrecision(), ((DecimalType) type).getScale());
    }
    if (type instanceof TimeType) {
        return format("time(%s)", ((TimeType) type).getPrecision());
    }
    String sqlType = SQL_TYPES.get(type);
    if (sqlType != null) {
        return sqlType;
    }
    return type.getDisplayName();
}
Also used : VarcharType(io.prestosql.spi.type.VarcharType) TimestampWithTimeZoneType(io.prestosql.spi.type.TimestampWithTimeZoneType) TimeWithTimeZoneType(io.prestosql.spi.type.TimeWithTimeZoneType) TimestampType(io.prestosql.spi.type.TimestampType) DecimalType(io.prestosql.spi.type.DecimalType) DecimalType.createDecimalType(io.prestosql.spi.type.DecimalType.createDecimalType) PrestoException(io.prestosql.spi.PrestoException) CharType(io.prestosql.spi.type.CharType) TimeType(io.prestosql.spi.type.TimeType)

Aggregations

CharType (io.prestosql.spi.type.CharType)2 DecimalType (io.prestosql.spi.type.DecimalType)2 TimeType (io.prestosql.spi.type.TimeType)2 TimeWithTimeZoneType (io.prestosql.spi.type.TimeWithTimeZoneType)2 TimestampType (io.prestosql.spi.type.TimestampType)2 TimestampWithTimeZoneType (io.prestosql.spi.type.TimestampWithTimeZoneType)2 VarcharType (io.prestosql.spi.type.VarcharType)2 TypeUtil.parseType (io.prestosql.client.util.TypeUtil.parseType)1 PrestoException (io.prestosql.spi.PrestoException)1 ArrayType (io.prestosql.spi.type.ArrayType)1 BigintType (io.prestosql.spi.type.BigintType)1 BooleanType (io.prestosql.spi.type.BooleanType)1 DateType (io.prestosql.spi.type.DateType)1 DecimalType.createDecimalType (io.prestosql.spi.type.DecimalType.createDecimalType)1 DoubleType (io.prestosql.spi.type.DoubleType)1 HyperLogLogType (io.prestosql.spi.type.HyperLogLogType)1 IntegerType (io.prestosql.spi.type.IntegerType)1 P4HyperLogLogType (io.prestosql.spi.type.P4HyperLogLogType)1 RealType (io.prestosql.spi.type.RealType)1 RowType (io.prestosql.spi.type.RowType)1