Search in sources :

Example 1 with TimestampWithTimeZoneType

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

the class AbstractRowEncoder method appendColumnValue.

@Override
public void appendColumnValue(Block block, int position) {
    checkArgument(currentColumnIndex < columnHandles.size(), format("currentColumnIndex '%d' is greater than number of columns '%d'", currentColumnIndex, columnHandles.size()));
    Type type = columnHandles.get(currentColumnIndex).getType();
    if (block.isNull(position)) {
        appendNullValue();
    } else if (type == BOOLEAN) {
        appendBoolean(type.getBoolean(block, position));
    } else if (type == BIGINT) {
        appendLong(type.getLong(block, position));
    } else if (type == INTEGER) {
        appendInt(toIntExact(type.getLong(block, position)));
    } else if (type == SMALLINT) {
        appendShort(Shorts.checkedCast(type.getLong(block, position)));
    } else if (type == TINYINT) {
        appendByte(SignedBytes.checkedCast(type.getLong(block, position)));
    } else if (type == DOUBLE) {
        appendDouble(type.getDouble(block, position));
    } else if (type == REAL) {
        appendFloat(intBitsToFloat(toIntExact(type.getLong(block, position))));
    } else if (isVarcharType(type)) {
        appendString(type.getSlice(block, position).toStringUtf8());
    } else if (isVarbinaryType(type)) {
        appendByteBuffer(type.getSlice(block, position).toByteBuffer());
    } else if (type == DATE) {
        appendSqlDate((SqlDate) type.getObjectValue(session.getSqlFunctionProperties(), block, position));
    } else if (type == TIME) {
        appendSqlTime((SqlTime) type.getObjectValue(session.getSqlFunctionProperties(), block, position));
    } else if (type == TIME_WITH_TIME_ZONE) {
        appendSqlTimeWithTimeZone((SqlTimeWithTimeZone) type.getObjectValue(session.getSqlFunctionProperties(), block, position));
    } else if (type instanceof TimestampType) {
        appendSqlTimestamp((SqlTimestamp) type.getObjectValue(session.getSqlFunctionProperties(), block, position));
    } else if (type instanceof TimestampWithTimeZoneType) {
        appendSqlTimestampWithTimeZone((SqlTimestampWithTimeZone) type.getObjectValue(session.getSqlFunctionProperties(), block, position));
    } else {
        throw new UnsupportedOperationException(format("Column '%s' does not support 'null' value", columnHandles.get(currentColumnIndex).getName()));
    }
    currentColumnIndex++;
}
Also used : Varchars.isVarcharType(com.facebook.presto.common.type.Varchars.isVarcharType) VarbinaryType.isVarbinaryType(com.facebook.presto.common.type.VarbinaryType.isVarbinaryType) Type(com.facebook.presto.common.type.Type) TimestampWithTimeZoneType(com.facebook.presto.common.type.TimestampWithTimeZoneType) TimestampType(com.facebook.presto.common.type.TimestampType) TimestampWithTimeZoneType(com.facebook.presto.common.type.TimestampWithTimeZoneType) SqlTime(com.facebook.presto.common.type.SqlTime) TimestampType(com.facebook.presto.common.type.TimestampType) SqlTimestamp(com.facebook.presto.common.type.SqlTimestamp)

Example 2 with TimestampWithTimeZoneType

use of com.facebook.presto.common.type.TimestampWithTimeZoneType 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 3 with TimestampWithTimeZoneType

use of com.facebook.presto.common.type.TimestampWithTimeZoneType 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

TimestampType (com.facebook.presto.common.type.TimestampType)3 TimestampWithTimeZoneType (com.facebook.presto.common.type.TimestampWithTimeZoneType)3 Type (com.facebook.presto.common.type.Type)3 BigintType (com.facebook.presto.common.type.BigintType)2 BooleanType (com.facebook.presto.common.type.BooleanType)2 CharType (com.facebook.presto.common.type.CharType)2 DecimalType (com.facebook.presto.common.type.DecimalType)2 DoubleType (com.facebook.presto.common.type.DoubleType)2 IntegerType (com.facebook.presto.common.type.IntegerType)2 RealType (com.facebook.presto.common.type.RealType)2 SmallintType (com.facebook.presto.common.type.SmallintType)2 TinyintType (com.facebook.presto.common.type.TinyintType)2 VarcharType (com.facebook.presto.common.type.VarcharType)2 Slice (io.airlift.slice.Slice)2 DateType (com.facebook.presto.common.type.DateType)1 SqlTime (com.facebook.presto.common.type.SqlTime)1 SqlTimestamp (com.facebook.presto.common.type.SqlTimestamp)1 SqlTimestampWithTimeZone (com.facebook.presto.common.type.SqlTimestampWithTimeZone)1 VarbinaryType.isVarbinaryType (com.facebook.presto.common.type.VarbinaryType.isVarbinaryType)1 Varchars.isVarcharType (com.facebook.presto.common.type.Varchars.isVarcharType)1