@Override protected RowExpression visitGenericLiteral(GenericLiteral node, Void context) { Type type = typeManager.getType(parseTypeSignature(node.getType())); if (type == null) { throw new IllegalArgumentException("Unsupported type: " + node.getType()); } if (JSON.equals(type)) { return call( new Signature("json_parse", SCALAR, types.get(node).getTypeSignature(), VARCHAR.getTypeSignature()), types.get(node), constant(utf8Slice(node.getValue()), VARCHAR)); } return call( castSignature(types.get(node), VARCHAR), types.get(node), constant(utf8Slice(node.getValue()), VARCHAR)); }
@Override protected Type visitGenericLiteral(GenericLiteral node, StackableAstVisitorContext<AnalysisContext> context) { Type type = typeManager.getType(parseTypeSignature(node.getType())); if (type == null) { throw new SemanticException(TYPE_MISMATCH, node, "Unknown type: " + node.getType()); } if (!JSON.equals(type)) { try { functionRegistry.getCoercion(VARCHAR, type); } catch (IllegalArgumentException e) { throw new SemanticException(TYPE_MISMATCH, node, "No literal form for type %s", type); } } expressionTypes.put(node, type); return type; }
@Override public Node visitTypeConstructor(SqlBaseParser.TypeConstructorContext context) { String type = context.identifier().getText(); String value = unquote(context.STRING().getText()); if (type.equalsIgnoreCase("time")) { return new TimeLiteral(getLocation(context), value); } if (type.equalsIgnoreCase("timestamp")) { return new TimestampLiteral(getLocation(context), value); } return new GenericLiteral(getLocation(context), type, value); }
@Override protected String visitGenericLiteral(GenericLiteral node, Void context) { return node.getType() + " '" + node.getValue() + "'"; }
@Override protected String visitGenericLiteral(GenericLiteral node, StackableAstVisitorContext<Integer> indent) { return node.getType() + " " + formatStringLiteral(node.getValue()); }
@Override protected String visitGenericLiteral(GenericLiteral node, Boolean unmangleNames) { return node.getType() + " '" + node.getValue() + "'"; }
public static void assertGenericLiteral(String type) { assertExpression(type + " 'abc'", new GenericLiteral(type, "abc")); }