use of com.facebook.presto.common.type.RealType 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);
}
use of com.facebook.presto.common.type.RealType 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));
}
Aggregations