use of com.facebook.presto.common.type.VarcharType in project presto by prestodb.
the class TransactionsSystemTable method createStringsBlock.
private static Block createStringsBlock(List<ConnectorId> values) {
VarcharType varchar = createUnboundedVarcharType();
BlockBuilder builder = varchar.createBlockBuilder(null, values.size());
for (ConnectorId value : values) {
if (value == null) {
builder.appendNull();
} else {
varchar.writeString(builder, value.getCatalogName());
}
}
return builder.build();
}
use of com.facebook.presto.common.type.VarcharType in project presto by prestodb.
the class TypeCoercer method compatibility.
private TypeCompatibility compatibility(Type fromType, Type toType) {
Type standardFromType = toStandardType(fromType);
Type standardToType = toStandardType(toType);
if (standardFromType.equals(standardToType)) {
return TypeCompatibility.compatible(toSemanticType(toType, standardToType), true);
}
if (standardFromType.equals(UnknownType.UNKNOWN)) {
return TypeCompatibility.compatible(toSemanticType(toType, standardToType), true);
}
if (standardToType.equals(UnknownType.UNKNOWN)) {
return TypeCompatibility.compatible(toSemanticType(fromType, standardFromType), false);
}
String fromTypeBaseName = standardFromType.getTypeSignature().getBase();
String toTypeBaseName = standardToType.getTypeSignature().getBase();
if (featuresConfig.isLegacyDateTimestampToVarcharCoercion()) {
if ((fromTypeBaseName.equals(StandardTypes.DATE) || fromTypeBaseName.equals(StandardTypes.TIMESTAMP)) && toTypeBaseName.equals(StandardTypes.VARCHAR)) {
return TypeCompatibility.compatible(toSemanticType(toType, standardToType), true);
}
if (fromTypeBaseName.equals(StandardTypes.VARCHAR) && (toTypeBaseName.equals(StandardTypes.DATE) || toTypeBaseName.equals(StandardTypes.TIMESTAMP))) {
return TypeCompatibility.compatible(toSemanticType(fromType, standardFromType), true);
}
}
if (fromTypeBaseName.equals(toTypeBaseName)) {
if (fromTypeBaseName.equals(StandardTypes.DECIMAL)) {
Type commonSuperType = getCommonSuperTypeForDecimal((DecimalType) standardFromType, (DecimalType) standardToType);
return TypeCompatibility.compatible(toSemanticType(toType, commonSuperType), commonSuperType.equals(standardToType));
}
if (fromTypeBaseName.equals(StandardTypes.VARCHAR)) {
Type commonSuperType = getCommonSuperTypeForVarchar((VarcharType) standardFromType, (VarcharType) standardToType);
return TypeCompatibility.compatible(toSemanticType(toType, commonSuperType), commonSuperType.equals(standardToType));
}
if (fromTypeBaseName.equals(StandardTypes.CHAR) && !featuresConfig.isLegacyCharToVarcharCoercion()) {
Type commonSuperType = getCommonSuperTypeForChar((CharType) standardFromType, (CharType) standardToType);
return TypeCompatibility.compatible(toSemanticType(toType, commonSuperType), commonSuperType.equals(standardToType));
}
if (fromTypeBaseName.equals(StandardTypes.ROW)) {
return typeCompatibilityForRow((RowType) standardFromType, (RowType) standardToType).toSemanticTypeCompatibility(toType);
}
if (isCovariantParametrizedType(standardFromType)) {
return typeCompatibilityForCovariantParametrizedType(standardFromType, standardToType).toSemanticTypeCompatibility(toType);
}
return TypeCompatibility.incompatible();
}
Optional<Type> coercedType = coerceTypeBase(standardFromType, standardToType.getTypeSignature().getBase());
if (coercedType.isPresent()) {
return compatibility(toSemanticType(toType, coercedType.get()), standardToType);
}
coercedType = coerceTypeBase(standardToType, standardFromType.getTypeSignature().getBase());
if (coercedType.isPresent()) {
TypeCompatibility typeCompatibility = compatibility(standardFromType, coercedType.get());
if (!typeCompatibility.isCompatible()) {
return TypeCompatibility.incompatible();
}
return TypeCompatibility.compatible(toSemanticType(toType, typeCompatibility.getCommonSuperType()), false);
}
return TypeCompatibility.incompatible();
}
use of com.facebook.presto.common.type.VarcharType in project presto by prestodb.
the class OrcType method toOrcType.
private static List<OrcType> toOrcType(int nextFieldTypeIndex, Type type) {
if (BOOLEAN.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.BOOLEAN));
}
if (TINYINT.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.BYTE));
}
if (SMALLINT.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.SHORT));
}
if (INTEGER.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.INT));
}
if (BIGINT.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.LONG));
}
if (DOUBLE.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.DOUBLE));
}
if (REAL.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.FLOAT));
}
if (type instanceof VarcharType) {
VarcharType varcharType = (VarcharType) type;
if (varcharType.isUnbounded()) {
return ImmutableList.of(new OrcType(OrcTypeKind.STRING));
}
return ImmutableList.of(new OrcType(OrcTypeKind.VARCHAR, varcharType.getLengthSafe()));
}
if (type instanceof CharType) {
return ImmutableList.of(new OrcType(OrcTypeKind.CHAR, ((CharType) type).getLength()));
}
if (VARBINARY.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.BINARY));
}
if (DATE.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.DATE));
}
if (TIMESTAMP.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.TIMESTAMP));
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
return ImmutableList.of(new OrcType(OrcTypeKind.DECIMAL, decimalType.getPrecision(), decimalType.getScale()));
}
if (type.getTypeSignature().getBase().equals(ARRAY)) {
return createOrcArrayType(nextFieldTypeIndex, type.getTypeParameters().get(0));
}
if (type.getTypeSignature().getBase().equals(MAP)) {
return createOrcMapType(nextFieldTypeIndex, type.getTypeParameters().get(0), type.getTypeParameters().get(1));
}
if (type.getTypeSignature().getBase().equals(ROW)) {
List<String> fieldNames = new ArrayList<>();
for (int i = 0; i < type.getTypeSignature().getParameters().size(); i++) {
TypeSignatureParameter parameter = type.getTypeSignature().getParameters().get(i);
fieldNames.add(parameter.getNamedTypeSignature().getName().orElse("field" + i));
}
List<Type> fieldTypes = type.getTypeParameters();
return createOrcRowType(nextFieldTypeIndex, fieldNames, fieldTypes);
}
throw new NotSupportedException(format("Unsupported Hive type: %s", type));
}
use of com.facebook.presto.common.type.VarcharType in project presto by prestodb.
the class SequencePageBuilder method createSequencePage.
public static Page createSequencePage(List<? extends Type> types, int length, int... initialValues) {
Block[] blocks = new Block[initialValues.length];
for (int i = 0; i < blocks.length; i++) {
Type type = types.get(i);
int initialValue = initialValues[i];
if (type.equals(BIGINT)) {
blocks[i] = BlockAssertions.createLongSequenceBlock(initialValue, initialValue + length);
} else if (type.equals(REAL)) {
blocks[i] = BlockAssertions.createSequenceBlockOfReal(initialValue, initialValue + length);
} else if (type.equals(DOUBLE)) {
blocks[i] = BlockAssertions.createDoubleSequenceBlock(initialValue, initialValue + length);
} else if (type instanceof VarcharType) {
blocks[i] = BlockAssertions.createStringSequenceBlock(initialValue, initialValue + length);
} else if (type.equals(BOOLEAN)) {
blocks[i] = BlockAssertions.createBooleanSequenceBlock(initialValue, initialValue + length);
} else if (type.equals(DATE)) {
blocks[i] = BlockAssertions.createDateSequenceBlock(initialValue, initialValue + length);
} else if (type.equals(TIMESTAMP)) {
blocks[i] = BlockAssertions.createTimestampSequenceBlock(initialValue, initialValue + length);
} else if (isShortDecimal(type)) {
blocks[i] = BlockAssertions.createShortDecimalSequenceBlock(initialValue, initialValue + length, (DecimalType) type);
} else if (isLongDecimal(type)) {
blocks[i] = BlockAssertions.createLongDecimalSequenceBlock(initialValue, initialValue + length, (DecimalType) type);
} else {
throw new IllegalStateException("Unsupported type " + type);
}
}
return new Page(blocks);
}
use of com.facebook.presto.common.type.VarcharType in project presto by prestodb.
the class SelectiveStreamReaders method createStreamReader.
public static SelectiveStreamReader createStreamReader(StreamDescriptor streamDescriptor, Map<Subfield, TupleDomainFilter> filters, Optional<Type> outputType, List<Subfield> requiredSubfields, DateTimeZone hiveStorageTimeZone, OrcRecordReaderOptions options, boolean legacyMapSubscript, OrcAggregatedMemoryContext systemMemoryContext) {
OrcTypeKind type = streamDescriptor.getOrcTypeKind();
switch(type) {
case BOOLEAN:
{
checkArgument(requiredSubfields.isEmpty(), "Boolean stream reader doesn't support subfields");
verifyStreamType(streamDescriptor, outputType, BooleanType.class::isInstance);
return new BooleanSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType.isPresent(), systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()));
}
case BYTE:
{
checkArgument(requiredSubfields.isEmpty(), "Byte stream reader doesn't support subfields");
verifyStreamType(streamDescriptor, outputType, TinyintType.class::isInstance);
return new ByteSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType.isPresent(), systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()));
}
case SHORT:
case INT:
case LONG:
case DATE:
{
checkArgument(requiredSubfields.isEmpty(), "Primitive type stream reader doesn't support subfields");
verifyStreamType(streamDescriptor, outputType, t -> t instanceof BigintType || t instanceof IntegerType || t instanceof SmallintType || t instanceof DateType);
return new LongSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType, systemMemoryContext);
}
case FLOAT:
{
checkArgument(requiredSubfields.isEmpty(), "Float type stream reader doesn't support subfields");
verifyStreamType(streamDescriptor, outputType, RealType.class::isInstance);
return new FloatSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType.isPresent(), systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()));
}
case DOUBLE:
checkArgument(requiredSubfields.isEmpty(), "Double stream reader doesn't support subfields");
verifyStreamType(streamDescriptor, outputType, DoubleType.class::isInstance);
return new DoubleSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType.isPresent(), systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()));
case BINARY:
case STRING:
case VARCHAR:
case CHAR:
checkArgument(requiredSubfields.isEmpty(), "Primitive stream reader doesn't support subfields");
verifyStreamType(streamDescriptor, outputType, t -> t instanceof VarcharType || t instanceof CharType || t instanceof VarbinaryType);
return new SliceSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType, systemMemoryContext);
case TIMESTAMP:
{
checkArgument(requiredSubfields.isEmpty(), "Timestamp stream reader doesn't support subfields");
verifyStreamType(streamDescriptor, outputType, TimestampType.class::isInstance);
return new TimestampSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), hiveStorageTimeZone, outputType.isPresent(), systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()), options);
}
case LIST:
verifyStreamType(streamDescriptor, outputType, ArrayType.class::isInstance);
return new ListSelectiveStreamReader(streamDescriptor, filters, requiredSubfields, null, 0, outputType, hiveStorageTimeZone, options, legacyMapSubscript, systemMemoryContext);
case STRUCT:
verifyStreamType(streamDescriptor, outputType, RowType.class::isInstance);
return new StructSelectiveStreamReader(streamDescriptor, filters, requiredSubfields, outputType, hiveStorageTimeZone, options, legacyMapSubscript, systemMemoryContext);
case MAP:
verifyStreamType(streamDescriptor, outputType, MapType.class::isInstance);
return new MapSelectiveStreamReader(streamDescriptor, filters, requiredSubfields, outputType, hiveStorageTimeZone, options, legacyMapSubscript, systemMemoryContext);
case DECIMAL:
{
verifyStreamType(streamDescriptor, outputType, DecimalType.class::isInstance);
if (streamDescriptor.getOrcType().getPrecision().get() <= MAX_SHORT_PRECISION) {
return new ShortDecimalSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType, systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()));
} else {
return new LongDecimalSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType, systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()));
}
}
case UNION:
default:
throw new IllegalArgumentException("Unsupported type: " + type);
}
}
Aggregations