private static RuntimeException throwMissingKeyException(Type type, InterpretedFunctionInvoker functionInvoker, Object value, ConnectorSession session) { String stringValue; try { stringValue = ((Slice) functionInvoker.invoke(castSignature(VarcharType.VARCHAR, type), session, value)).toStringUtf8(); } catch (RuntimeException e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Key not present in map"); } throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Key not present in map: %s", stringValue)); } }
@Override protected RowExpression visitLikePredicate(LikePredicate node, Void context) { RowExpression value = process(node.getValue(), context); RowExpression pattern = process(node.getPattern(), context); if (node.getEscape().isPresent()) { RowExpression escape = process(node.getEscape().get(), context); return likeFunctionCall(value, call(likePatternSignature(), LIKE_PATTERN, pattern, escape)); } return likeFunctionCall(value, call(castSignature(LIKE_PATTERN, VARCHAR), LIKE_PATTERN, pattern)); }
@Override protected RowExpression visitCast(Cast node, Void context) { RowExpression value = process(node.getExpression(), context); if (node.isTypeOnly()) { return changeType(value, getType(node)); } if (node.isSafe()) { return call(tryCastSignature(getType(node), value.getType()), getType(node), value); } return call(castSignature(getType(node), value.getType()), getType(node), value); }
@Override protected RowExpression visitGenericLiteral(GenericLiteral node, Void context) { Type type; try { type = typeManager.getType(parseTypeSignature(node.getType())); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Unsupported type: " + node.getType()); } if (JSON.equals(type)) { return call( new Signature("json_parse", SCALAR, getType(node).getTypeSignature(), VARCHAR.getTypeSignature()), getType(node), constant(utf8Slice(node.getValue()), VARCHAR)); } return call( castSignature(getType(node), VARCHAR), getType(node), constant(utf8Slice(node.getValue()), VARCHAR)); }
@Override protected RowExpression visitCast(Cast node, Void context) { RowExpression value = process(node.getExpression(), context); if (node.isTypeOnly()) { return changeType(value, types.get(node)); } if (node.isSafe()) { return call(tryCastSignature(types.get(node), value.getType()), types.get(node), value); } return call(castSignature(types.get(node), value.getType()), types.get(node), value); }
@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 RowExpression visitLikePredicate(LikePredicate node, Void context) { RowExpression value = process(node.getValue(), context); RowExpression pattern = process(node.getPattern(), context); if (node.getEscape() != null) { RowExpression escape = process(node.getEscape(), context); return call(likeSignature(), BOOLEAN, value, call(likePatternSignature(), LIKE_PATTERN, pattern, escape)); } return call(likeSignature(), BOOLEAN, value, call(castSignature(LIKE_PATTERN, VARCHAR), LIKE_PATTERN, pattern)); }