Construct "proper literal" for CHAR in LiteralInterpreter.toExpression
"proper literal" means just a literal or a literal wrapped with a CAST.
Previously, `toExpression(..., CHAR(x))` would return a "magic literal
function call" which is hard to analyze.
@@ -20,6 +20,7 @@ import com.facebook.presto.metadata.Signature;
import com.facebook.presto.operator.scalar.VarbinaryFunctions;
import com.facebook.presto.spi.ConnectorSession;
import com.facebook.presto.spi.block.Block;
+import com.facebook.presto.spi.type.CharType;
import com.facebook.presto.spi.type.Decimals;
import com.facebook.presto.spi.type.StandardTypes;
import com.facebook.presto.spi.type.Type;
@@ -180,6 +181,11 @@ public final class LiteralInterpreter
return new Cast(new StringLiteral(value.toStringUtf8()), type.getDisplayName(), false, true);
}
+ if (type instanceof CharType) {
+ StringLiteral stringLiteral = new StringLiteral(((Slice) object).toStringUtf8());
+ return new Cast(stringLiteral, type.getDisplayName(), false, true);
+ }
+
if (type.equals(BOOLEAN)) {
return new BooleanLiteral(object.toString());
}
