Search in sources :

Example 6 with BigintType

use of com.facebook.presto.common.type.BigintType in project presto by prestodb.

the class DruidPushdownUtils method getLiteralAsString.

// Copied from com.facebook.presto.sql.planner.LiteralInterpreter.evaluate
public static String getLiteralAsString(ConnectorSession session, ConstantExpression node) {
    Type type = node.getType();
    if (node.getValue() == null) {
        throw new PrestoException(DRUID_PUSHDOWN_UNSUPPORTED_EXPRESSION, "Null constant expression: " + node + " with value of type: " + type);
    }
    if (type instanceof BooleanType) {
        return String.valueOf(((Boolean) node.getValue()).booleanValue());
    }
    if (type instanceof BigintType || type instanceof TinyintType || type instanceof SmallintType || type instanceof IntegerType) {
        Number number = (Number) node.getValue();
        return format("%d", number.longValue());
    }
    if (type instanceof DoubleType) {
        return node.getValue().toString();
    }
    if (type instanceof RealType) {
        Long number = (Long) node.getValue();
        return format("%f", intBitsToFloat(number.intValue()));
    }
    if (type instanceof DecimalType) {
        DecimalType decimalType = (DecimalType) type;
        if (decimalType.isShort()) {
            checkState(node.getValue() instanceof Long);
            return decodeDecimal(BigInteger.valueOf((long) node.getValue()), decimalType).toString();
        }
        checkState(node.getValue() instanceof Slice);
        Slice value = (Slice) node.getValue();
        return decodeDecimal(decodeUnscaledValue(value), decimalType).toString();
    }
    if (type instanceof VarcharType || type instanceof CharType) {
        return "'" + ((Slice) node.getValue()).toStringUtf8() + "'";
    }
    if (type instanceof TimestampType) {
        return getTimestampLiteralAsString(session, (long) node.getValue());
    }
    if (type instanceof TimestampWithTimeZoneType) {
        return getTimestampLiteralAsString(session, new SqlTimestampWithTimeZone((long) node.getValue()).getMillisUtc());
    }
    throw new PrestoException(DRUID_PUSHDOWN_UNSUPPORTED_EXPRESSION, "Cannot handle the constant expression: " + node + " with value of type: " + type);
}
Also used : VarcharType(com.facebook.presto.common.type.VarcharType) TinyintType(com.facebook.presto.common.type.TinyintType) BooleanType(com.facebook.presto.common.type.BooleanType) PrestoException(com.facebook.presto.spi.PrestoException) RealType(com.facebook.presto.common.type.RealType) BigintType(com.facebook.presto.common.type.BigintType) IntegerType(com.facebook.presto.common.type.IntegerType) DecimalType(com.facebook.presto.common.type.DecimalType) BooleanType(com.facebook.presto.common.type.BooleanType) IntegerType(com.facebook.presto.common.type.IntegerType) CharType(com.facebook.presto.common.type.CharType) Type(com.facebook.presto.common.type.Type) TinyintType(com.facebook.presto.common.type.TinyintType) BigintType(com.facebook.presto.common.type.BigintType) VarcharType(com.facebook.presto.common.type.VarcharType) RealType(com.facebook.presto.common.type.RealType) TimestampWithTimeZoneType(com.facebook.presto.common.type.TimestampWithTimeZoneType) SmallintType(com.facebook.presto.common.type.SmallintType) DoubleType(com.facebook.presto.common.type.DoubleType) TimestampType(com.facebook.presto.common.type.TimestampType) SqlTimestampWithTimeZone(com.facebook.presto.common.type.SqlTimestampWithTimeZone) DoubleType(com.facebook.presto.common.type.DoubleType) Slice(io.airlift.slice.Slice) TimestampWithTimeZoneType(com.facebook.presto.common.type.TimestampWithTimeZoneType) DecimalType(com.facebook.presto.common.type.DecimalType) TimestampType(com.facebook.presto.common.type.TimestampType) SmallintType(com.facebook.presto.common.type.SmallintType) CharType(com.facebook.presto.common.type.CharType)

Example 7 with BigintType

use of com.facebook.presto.common.type.BigintType 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);
    }
}
Also used : StreamDescriptor(com.facebook.presto.orc.StreamDescriptor) Iterables(com.google.common.collect.Iterables) DateTimeZone(org.joda.time.DateTimeZone) MapType(com.facebook.presto.common.type.MapType) DecimalType(com.facebook.presto.common.type.DecimalType) BooleanType(com.facebook.presto.common.type.BooleanType) OrcTypeKind(com.facebook.presto.orc.metadata.OrcType.OrcTypeKind) MAX_SHORT_PRECISION(com.facebook.presto.common.type.Decimals.MAX_SHORT_PRECISION) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) IntegerType(com.facebook.presto.common.type.IntegerType) Subfield(com.facebook.presto.common.Subfield) Map(java.util.Map) ArrayType(com.facebook.presto.common.type.ArrayType) CharType(com.facebook.presto.common.type.CharType) Type(com.facebook.presto.common.type.Type) TinyintType(com.facebook.presto.common.type.TinyintType) OrcAggregatedMemoryContext(com.facebook.presto.orc.OrcAggregatedMemoryContext) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) BigintType(com.facebook.presto.common.type.BigintType) OrcRecordReaderOptions(com.facebook.presto.orc.OrcRecordReaderOptions) VarcharType(com.facebook.presto.common.type.VarcharType) RealType(com.facebook.presto.common.type.RealType) String.format(java.lang.String.format) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) SmallintType(com.facebook.presto.common.type.SmallintType) List(java.util.List) VarbinaryType(com.facebook.presto.common.type.VarbinaryType) Optional(java.util.Optional) Arrays.ensureCapacity(com.facebook.presto.common.array.Arrays.ensureCapacity) DateType(com.facebook.presto.common.type.DateType) DoubleType(com.facebook.presto.common.type.DoubleType) RowType(com.facebook.presto.common.type.RowType) TimestampType(com.facebook.presto.common.type.TimestampType) VarcharType(com.facebook.presto.common.type.VarcharType) RowType(com.facebook.presto.common.type.RowType) OrcTypeKind(com.facebook.presto.orc.metadata.OrcType.OrcTypeKind) MapType(com.facebook.presto.common.type.MapType) ArrayType(com.facebook.presto.common.type.ArrayType) VarbinaryType(com.facebook.presto.common.type.VarbinaryType) SmallintType(com.facebook.presto.common.type.SmallintType) DateType(com.facebook.presto.common.type.DateType) BigintType(com.facebook.presto.common.type.BigintType) IntegerType(com.facebook.presto.common.type.IntegerType) DoubleType(com.facebook.presto.common.type.DoubleType) CharType(com.facebook.presto.common.type.CharType)

Example 8 with BigintType

use of com.facebook.presto.common.type.BigintType in project presto by prestodb.

the class PinotPushdownUtils method getLiteralAsString.

// Copied from com.facebook.presto.sql.planner.LiteralInterpreter.evaluate
public static String getLiteralAsString(ConstantExpression node) {
    Type type = node.getType();
    if (node.getValue() == null) {
        throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), String.format("Null constant expression %s with value of type %s", node, type));
    }
    if (type instanceof BooleanType) {
        return String.valueOf(((Boolean) node.getValue()).booleanValue());
    }
    if (type instanceof BigintType || type instanceof TinyintType || type instanceof SmallintType || type instanceof IntegerType) {
        Number number = (Number) node.getValue();
        return format("%d", number.longValue());
    }
    if (type instanceof DoubleType) {
        return node.getValue().toString();
    }
    if (type instanceof RealType) {
        Long number = (Long) node.getValue();
        return format("%f", intBitsToFloat(number.intValue()));
    }
    if (type instanceof DecimalType) {
        DecimalType decimalType = (DecimalType) type;
        if (decimalType.isShort()) {
            checkState(node.getValue() instanceof Long);
            return decodeDecimal(BigInteger.valueOf((long) node.getValue()), decimalType).toString();
        }
        checkState(node.getValue() instanceof Slice);
        Slice value = (Slice) node.getValue();
        return decodeDecimal(decodeUnscaledValue(value), decimalType).toString();
    }
    if (type instanceof VarcharType || type instanceof CharType) {
        return "'" + ((Slice) node.getValue()).toStringUtf8() + "'";
    }
    if (type instanceof TimestampType || type instanceof DateType) {
        return node.getValue().toString();
    }
    if (type instanceof TimestampWithTimeZoneType) {
        Long millisUtc = DateTimeEncoding.unpackMillisUtc((Long) node.getValue());
        return millisUtc.toString();
    }
    throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), String.format("Cannot handle the constant expression %s with value of type %s", node, type));
}
Also used : VarcharType(com.facebook.presto.common.type.VarcharType) TinyintType(com.facebook.presto.common.type.TinyintType) BooleanType(com.facebook.presto.common.type.BooleanType) RealType(com.facebook.presto.common.type.RealType) BigintType(com.facebook.presto.common.type.BigintType) IntegerType(com.facebook.presto.common.type.IntegerType) DecimalType(com.facebook.presto.common.type.DecimalType) BooleanType(com.facebook.presto.common.type.BooleanType) IntegerType(com.facebook.presto.common.type.IntegerType) CharType(com.facebook.presto.common.type.CharType) Type(com.facebook.presto.common.type.Type) TinyintType(com.facebook.presto.common.type.TinyintType) BigintType(com.facebook.presto.common.type.BigintType) VarcharType(com.facebook.presto.common.type.VarcharType) RealType(com.facebook.presto.common.type.RealType) TimestampWithTimeZoneType(com.facebook.presto.common.type.TimestampWithTimeZoneType) SmallintType(com.facebook.presto.common.type.SmallintType) DateType(com.facebook.presto.common.type.DateType) DoubleType(com.facebook.presto.common.type.DoubleType) TimestampType(com.facebook.presto.common.type.TimestampType) DoubleType(com.facebook.presto.common.type.DoubleType) Slice(io.airlift.slice.Slice) TimestampWithTimeZoneType(com.facebook.presto.common.type.TimestampWithTimeZoneType) DecimalType(com.facebook.presto.common.type.DecimalType) TimestampType(com.facebook.presto.common.type.TimestampType) SmallintType(com.facebook.presto.common.type.SmallintType) CharType(com.facebook.presto.common.type.CharType) DateType(com.facebook.presto.common.type.DateType)

Aggregations

BigintType (com.facebook.presto.common.type.BigintType)8 DoubleType (com.facebook.presto.common.type.DoubleType)7 IntegerType (com.facebook.presto.common.type.IntegerType)7 TimestampType (com.facebook.presto.common.type.TimestampType)7 BooleanType (com.facebook.presto.common.type.BooleanType)6 DateType (com.facebook.presto.common.type.DateType)6 DecimalType (com.facebook.presto.common.type.DecimalType)6 RealType (com.facebook.presto.common.type.RealType)6 SmallintType (com.facebook.presto.common.type.SmallintType)6 TinyintType (com.facebook.presto.common.type.TinyintType)6 VarcharType (com.facebook.presto.common.type.VarcharType)6 Slice (io.airlift.slice.Slice)6 CharType (com.facebook.presto.common.type.CharType)5 Type (com.facebook.presto.common.type.Type)5 PrestoException (com.facebook.presto.spi.PrestoException)4 TimestampWithTimeZoneType (com.facebook.presto.common.type.TimestampWithTimeZoneType)2 VarbinaryType (com.facebook.presto.common.type.VarbinaryType)2 Page (com.facebook.presto.common.Page)1 Subfield (com.facebook.presto.common.Subfield)1 Arrays.ensureCapacity (com.facebook.presto.common.array.Arrays.ensureCapacity)1