private static Expression booleanConstant(@Nullable Boolean value) { if (value == null) { return new Cast(new NullLiteral(), BOOLEAN.toString()); } return new BooleanLiteral(value.toString()); }
@Override public Object visitCast(Cast node, Object context) Object value = process(node.getExpression(), context); Type targetType = metadata.getType(parseTypeSignature(node.getType())); if (targetType == null) { throw new IllegalArgumentException("Unsupported type: " + node.getType()); Type sourceType = type(node.getExpression()); if (value instanceof Expression) { if (targetType.equals(sourceType)) { return new Cast((Expression) value, node.getType(), node.isSafe(), node.isTypeOnly()); if (node.isTypeOnly()) { return value; return new Cast(toExpression(value, sourceType), node.getType(), node.isSafe(), node.isTypeOnly()); if (node.isSafe()) { return null;
@Override public String visitCast(Cast node, Void context) { return (node.isSafe() ? "TRY_CAST" : "CAST") + "(" + process(node.getExpression(), context) + " AS " + node.getType() + ")"; }
@Override protected Boolean visitCast(Cast actual, Node expectedExpression) { if (!(expectedExpression instanceof Cast)) { return false; } Cast expected = (Cast) expectedExpression; if (!actual.getType().equals(expected.getType())) { return false; } return process(actual.getExpression(), expected.getExpression()); }
@Override protected Boolean visitCast(Cast node, Void context) { return process(node.getExpression(), context); }
@Override public Type visitCast(Cast node, StackableAstVisitorContext<Context> context) { Type type; try { type = typeManager.getType(parseTypeSignature(node.getType())); } catch (IllegalArgumentException e) { throw new SemanticException(TYPE_MISMATCH, node, "Unknown type: " + node.getType()); } if (type.equals(UNKNOWN)) { throw new SemanticException(TYPE_MISMATCH, node, "UNKNOWN is not a valid type"); } Type value = process(node.getExpression(), context); if (!value.equals(UNKNOWN) && !node.isTypeOnly()) { try { functionRegistry.getCoercion(value, type); } catch (OperatorNotFoundException e) { throw new SemanticException(TYPE_MISMATCH, node, "Cannot cast %s to %s", value, type); } } return setExpressionType(node, type); }
@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 Boolean visitCast(Cast actual, Node expectedExpression) { if (!(expectedExpression instanceof Cast)) { return false; } Cast expected = (Cast) expectedExpression; if (!actual.getType().equals(expected.getType())) { return false; } return process(actual.getExpression(), expected.getExpression()); }
@Override public String visitCast(Cast node, Void context) { return (node.isSafe() ? "TRY_CAST" : "CAST") + "(" + process(node.getExpression(), context) + " AS " + node.getType() + ")"; }
@Override protected R visitCast(Cast node, C context) { return process(node.getExpression(), context); }
@Override public Type visitCast(Cast node, StackableAstVisitorContext<Context> context) { Type type; try { type = typeManager.getType(parseTypeSignature(node.getType())); } catch (IllegalArgumentException e) { throw new SemanticException(TYPE_MISMATCH, node, "Unknown type: " + node.getType()); } if (type.equals(UNKNOWN)) { throw new SemanticException(TYPE_MISMATCH, node, "UNKNOWN is not a valid type"); } Type value = process(node.getExpression(), context); if (!value.equals(UNKNOWN) && !node.isTypeOnly()) { try { functionRegistry.getCoercion(value, type); } catch (OperatorNotFoundException e) { throw new SemanticException(TYPE_MISMATCH, node, "Cannot cast %s to %s", value, type); } } return setExpressionType(node, type); }
@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); }
private static Expression bigint(long value) { return new Cast(new LongLiteral(String.valueOf(value)), BIGINT.toString()); }
@Override public Object visitCast(Cast node, Object context) Object value = process(node.getExpression(), context); Type targetType = metadata.getType(parseTypeSignature(node.getType())); if (targetType == null) { throw new IllegalArgumentException("Unsupported type: " + node.getType()); Type sourceType = type(node.getExpression()); if (value instanceof Expression) { if (targetType.equals(sourceType)) { return new Cast((Expression) value, node.getType(), node.isSafe(), node.isTypeOnly()); if (node.isTypeOnly()) { return value; return new Cast(toExpression(value, sourceType), node.getType(), node.isSafe(), node.isTypeOnly()); if (node.isSafe()) { return null;
@Override protected SymbolStatsEstimate visitCast(Cast node, Void context) SymbolStatsEstimate sourceStats = process(node.getExpression()); TypeSignature targetType = TypeSignature.parseTypeSignature(node.getType());
@Override protected R visitCast(Cast node, C context) { return process(node.getExpression(), context); }
private static Expression bigint(long value) { return new Cast(new LongLiteral(String.valueOf(value)), BIGINT.toString()); }
@Override protected SymbolStatsEstimate visitCast(Cast node, Void context) SymbolStatsEstimate sourceStats = process(node.getExpression()); TypeSignature targetType = TypeSignature.parseTypeSignature(node.getType());
@Override protected Boolean visitCast(Cast node, Void context) { return process(node.getExpression(), context); }
private static Expression booleanConstant(@Nullable Boolean value) { if (value == null) { return new Cast(new NullLiteral(), BOOLEAN.toString()); } return new BooleanLiteral(value.toString()); }