use of io.trino.spi.type.CharType in project trino by trinodb.
the class RedshiftClient method legacyToWriteMapping.
private WriteMapping legacyToWriteMapping(Type type) {
// This method is copied from deprecated BaseJdbcClient.legacyToWriteMapping()
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("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 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 == VARBINARY) {
return WriteMapping.sliceMapping("varbinary", varbinaryWriteFunction());
}
if (type == DATE) {
return WriteMapping.longMapping("date", dateWriteFunctionUsingSqlDate());
}
throw new TrinoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
}
use of io.trino.spi.type.CharType 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 TrinoException(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();
}
use of io.trino.spi.type.CharType in project trino by trinodb.
the class HiveWriteUtils method getJavaObjectInspector.
public static ObjectInspector getJavaObjectInspector(Type type) {
if (type.equals(BOOLEAN)) {
return javaBooleanObjectInspector;
}
if (type.equals(BIGINT)) {
return javaLongObjectInspector;
}
if (type.equals(INTEGER)) {
return javaIntObjectInspector;
}
if (type.equals(SMALLINT)) {
return javaShortObjectInspector;
}
if (type.equals(TINYINT)) {
return javaByteObjectInspector;
}
if (type.equals(REAL)) {
return javaFloatObjectInspector;
}
if (type.equals(DOUBLE)) {
return javaDoubleObjectInspector;
}
if (type instanceof VarcharType) {
return writableStringObjectInspector;
}
if (type instanceof CharType) {
return writableHiveCharObjectInspector;
}
if (type.equals(VARBINARY)) {
return javaByteArrayObjectInspector;
}
if (type.equals(DATE)) {
return javaDateObjectInspector;
}
if (type instanceof TimestampType) {
return javaTimestampObjectInspector;
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
return getPrimitiveJavaObjectInspector(new DecimalTypeInfo(decimalType.getPrecision(), decimalType.getScale()));
}
if (isArrayType(type)) {
return ObjectInspectorFactory.getStandardListObjectInspector(getJavaObjectInspector(type.getTypeParameters().get(0)));
}
if (isMapType(type)) {
ObjectInspector keyObjectInspector = getJavaObjectInspector(type.getTypeParameters().get(0));
ObjectInspector valueObjectInspector = getJavaObjectInspector(type.getTypeParameters().get(1));
return ObjectInspectorFactory.getStandardMapObjectInspector(keyObjectInspector, valueObjectInspector);
}
if (isRowType(type)) {
return ObjectInspectorFactory.getStandardStructObjectInspector(type.getTypeSignature().getParameters().stream().map(parameter -> parameter.getNamedTypeSignature().getName().get()).collect(toImmutableList()), type.getTypeParameters().stream().map(HiveWriteUtils::getJavaObjectInspector).collect(toImmutableList()));
}
throw new IllegalArgumentException("unsupported type: " + type);
}
use of io.trino.spi.type.CharType in project trino by trinodb.
the class HiveWriteUtils method getRowColumnInspector.
public static ObjectInspector getRowColumnInspector(Type type) {
if (type.equals(BOOLEAN)) {
return writableBooleanObjectInspector;
}
if (type.equals(BIGINT)) {
return writableLongObjectInspector;
}
if (type.equals(INTEGER)) {
return writableIntObjectInspector;
}
if (type.equals(SMALLINT)) {
return writableShortObjectInspector;
}
if (type.equals(TINYINT)) {
return writableByteObjectInspector;
}
if (type.equals(REAL)) {
return writableFloatObjectInspector;
}
if (type.equals(DOUBLE)) {
return writableDoubleObjectInspector;
}
if (type instanceof VarcharType) {
VarcharType varcharType = (VarcharType) type;
if (varcharType.isUnbounded()) {
// Values for such columns must be stored as STRING in Hive
return writableStringObjectInspector;
}
if (varcharType.getBoundedLength() <= HiveVarchar.MAX_VARCHAR_LENGTH) {
// VARCHAR columns with the length less than or equal to 65535 are supported natively by Hive
return getPrimitiveWritableObjectInspector(getVarcharTypeInfo(varcharType.getBoundedLength()));
}
}
if (type instanceof CharType) {
CharType charType = (CharType) type;
int charLength = charType.getLength();
return getPrimitiveWritableObjectInspector(getCharTypeInfo(charLength));
}
if (type.equals(VARBINARY)) {
return writableBinaryObjectInspector;
}
if (type.equals(DATE)) {
return writableDateObjectInspector;
}
if (type instanceof TimestampType) {
return writableTimestampObjectInspector;
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
return getPrimitiveWritableObjectInspector(new DecimalTypeInfo(decimalType.getPrecision(), decimalType.getScale()));
}
if (isArrayType(type) || isMapType(type) || isRowType(type)) {
return getJavaObjectInspector(type);
}
throw new IllegalArgumentException("unsupported type: " + type);
}
use of io.trino.spi.type.CharType in project trino by trinodb.
the class HiveUtil method getPrefilledColumnValue.
public static NullableValue getPrefilledColumnValue(HiveColumnHandle columnHandle, HivePartitionKey partitionKey, Path path, OptionalInt bucketNumber, long fileSize, long fileModifiedTime, String partitionName) {
String columnValue;
if (partitionKey != null) {
columnValue = partitionKey.getValue();
} else if (isPathColumnHandle(columnHandle)) {
columnValue = path.toString();
} else if (isBucketColumnHandle(columnHandle)) {
columnValue = String.valueOf(bucketNumber.getAsInt());
} else if (isFileSizeColumnHandle(columnHandle)) {
columnValue = String.valueOf(fileSize);
} else if (isFileModifiedTimeColumnHandle(columnHandle)) {
columnValue = HIVE_TIMESTAMP_PARSER.print(fileModifiedTime);
} else if (isPartitionColumnHandle(columnHandle)) {
columnValue = partitionName;
} else {
throw new TrinoException(NOT_SUPPORTED, "unsupported hidden column: " + columnHandle);
}
byte[] bytes = columnValue.getBytes(UTF_8);
String name = columnHandle.getName();
Type type = columnHandle.getType();
if (isHiveNull(bytes)) {
return NullableValue.asNull(type);
} else if (type.equals(BOOLEAN)) {
return NullableValue.of(type, booleanPartitionKey(columnValue, name));
} else if (type.equals(BIGINT)) {
return NullableValue.of(type, bigintPartitionKey(columnValue, name));
} else if (type.equals(INTEGER)) {
return NullableValue.of(type, integerPartitionKey(columnValue, name));
} else if (type.equals(SMALLINT)) {
return NullableValue.of(type, smallintPartitionKey(columnValue, name));
} else if (type.equals(TINYINT)) {
return NullableValue.of(type, tinyintPartitionKey(columnValue, name));
} else if (type.equals(REAL)) {
return NullableValue.of(type, floatPartitionKey(columnValue, name));
} else if (type.equals(DOUBLE)) {
return NullableValue.of(type, doublePartitionKey(columnValue, name));
} else if (type instanceof VarcharType) {
return NullableValue.of(type, varcharPartitionKey(columnValue, name, type));
} else if (type instanceof CharType) {
return NullableValue.of(type, charPartitionKey(columnValue, name, type));
} else if (type.equals(DATE)) {
return NullableValue.of(type, datePartitionKey(columnValue, name));
} else if (type.equals(TIMESTAMP_MILLIS)) {
return NullableValue.of(type, timestampPartitionKey(columnValue, name));
} else if (type.equals(TIMESTAMP_TZ_MILLIS)) {
// used for $file_modified_time
return NullableValue.of(type, packDateTimeWithZone(floorDiv(timestampPartitionKey(columnValue, name), MICROSECONDS_PER_MILLISECOND), DateTimeZone.getDefault().getID()));
} else if (isShortDecimal(type)) {
return NullableValue.of(type, shortDecimalPartitionKey(columnValue, (DecimalType) type, name));
} else if (isLongDecimal(type)) {
return NullableValue.of(type, longDecimalPartitionKey(columnValue, (DecimalType) type, name));
} else if (type.equals(VarbinaryType.VARBINARY)) {
return NullableValue.of(type, utf8Slice(columnValue));
}
throw new TrinoException(NOT_SUPPORTED, format("Unsupported column type %s for prefilled column: %s", type.getDisplayName(), name));
}
Aggregations