@Test public void testArithmeticExpressionWithNulls() { for (ArithmeticBinaryExpression.Operator operator : ArithmeticBinaryExpression.Operator.values()) { assertProjection("CAST(NULL AS INTEGER) " + operator.getValue() + " CAST(NULL AS INTEGER)", null); assertProjection("42 " + operator.getValue() + " NULL", null); assertProjection("NULL " + operator.getValue() + " 42", null); assertProjection("11.1 " + operator.getValue() + " CAST(NULL AS INTEGER)", null); assertProjection("CAST(NULL AS INTEGER) " + operator.getValue() + " 11.1", null); } }
@Override protected Object visitArithmeticBinary(ArithmeticBinaryExpression node, Object context) { Object left = process(node.getLeft(), context); if (left == null) { return null; } Object right = process(node.getRight(), context); if (right == null) { return null; } if (hasUnresolvedValue(left, right)) { return new ArithmeticBinaryExpression(node.getOperator(), toExpression(left, type(node.getLeft())), toExpression(right, type(node.getRight()))); } return invokeOperator(OperatorType.valueOf(node.getOperator().name()), types(node.getLeft(), node.getRight()), ImmutableList.of(left, right)); }
@Override protected Object visitArithmeticBinary(ArithmeticBinaryExpression node, Object context) { Object left = process(node.getLeft(), context); if (left == null) { return null; } Object right = process(node.getRight(), context); if (right == null) { return null; } if (hasUnresolvedValue(left, right)) { return new ArithmeticBinaryExpression(node.getOperator(), toExpression(left, type(node.getLeft())), toExpression(right, type(node.getRight()))); } return invokeOperator(OperatorType.valueOf(node.getOperator().name()), types(node.getLeft(), node.getRight()), ImmutableList.of(left, right)); }
public static Signature arithmeticExpressionSignature(ArithmeticBinaryExpression.Operator operator, Type returnType, Type leftType, Type rightType) { return internalOperator(operator.name(), returnType.getTypeSignature(), leftType.getTypeSignature(), rightType.getTypeSignature()); }
public static Signature arithmeticExpressionSignature(ArithmeticBinaryExpression.Operator operator, Type returnType, Type leftType, Type rightType) { return internalOperator(operator.name(), returnType.getTypeSignature(), leftType.getTypeSignature(), rightType.getTypeSignature()); }
@Override protected String visitArithmeticBinary(ArithmeticBinaryExpression node, Void context) { return formatBinaryExpression(node.getOperator().getValue(), node.getLeft(), node.getRight()); }
@Override protected Void visitArithmeticBinary(ArithmeticBinaryExpression node, Integer indentLevel) { print(indentLevel, node.getOperator().toString()); super.visitArithmeticBinary(node, indentLevel + 1); return null; }
@Override protected Type visitArithmeticBinary(ArithmeticBinaryExpression node, StackableAstVisitorContext<Context> context) { return getOperator(context, node, OperatorType.valueOf(node.getOperator().name()), node.getLeft(), node.getRight()); }
@Override protected Void visitArithmeticBinary(ArithmeticBinaryExpression node, Integer indentLevel) { print(indentLevel, node.getOperator().toString()); super.visitArithmeticBinary(node, indentLevel + 1); return null; }
@Override protected Type visitArithmeticBinary(ArithmeticBinaryExpression node, StackableAstVisitorContext<Context> context) { return getOperator(context, node, OperatorType.valueOf(node.getOperator().name()), node.getLeft(), node.getRight()); }
@Override protected String visitArithmeticBinary(ArithmeticBinaryExpression node, Void context) { return formatBinaryExpression(node.getOperator().getValue(), node.getLeft(), node.getRight()); }
@Test public void testArithmeticExpressionWithNulls() { for (ArithmeticBinaryExpression.Operator operator : ArithmeticBinaryExpression.Operator.values()) { assertProjection("CAST(NULL AS INTEGER) " + operator.getValue() + " CAST(NULL AS INTEGER)", null); assertProjection("42 " + operator.getValue() + " NULL", null); assertProjection("NULL " + operator.getValue() + " 42", null); assertProjection("11.1 " + operator.getValue() + " CAST(NULL AS INTEGER)", null); assertProjection("CAST(NULL AS INTEGER) " + operator.getValue() + " 11.1", null); } }