Java 类com.facebook.presto.sql.tree.ArithmeticBinaryExpression 实例源码

项目:presto    文件:ExpressionInterpreter.java   
@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.getType(), toExpression(left, expressionTypes.get(node.getLeft())), toExpression(right, expressionTypes.get(node.getRight())));
    }

    return invokeOperator(OperatorType.valueOf(node.getType().name()), types(node.getLeft(), node.getRight()), ImmutableList.of(left, right));
}
项目:presto    文件:AstBuilder.java   
private static ArithmeticBinaryExpression.Type getArithmeticBinaryOperator(Token operator)
{
    switch (operator.getType()) {
        case SqlBaseLexer.PLUS:
            return ArithmeticBinaryExpression.Type.ADD;
        case SqlBaseLexer.MINUS:
            return ArithmeticBinaryExpression.Type.SUBTRACT;
        case SqlBaseLexer.ASTERISK:
            return ArithmeticBinaryExpression.Type.MULTIPLY;
        case SqlBaseLexer.SLASH:
            return ArithmeticBinaryExpression.Type.DIVIDE;
        case SqlBaseLexer.PERCENT:
            return ArithmeticBinaryExpression.Type.MODULUS;
    }

    throw new UnsupportedOperationException("Unsupported operator: " + operator.getText());
}
项目:presto    文件:SqlToRowExpressionTranslator.java   
@Override
protected RowExpression visitArithmeticBinary(ArithmeticBinaryExpression node, Void context)
{
    RowExpression left = process(node.getLeft(), context);
    RowExpression right = process(node.getRight(), context);

    return call(
            arithmeticExpressionSignature(node.getType(), types.get(node), left.getType(), right.getType()),
            types.get(node),
            left,
            right);
}
项目:presto    文件:TestInterpretedProjectionFunction.java   
@Test
public void testArithmeticExpressionWithNulls()
{
    for (ArithmeticBinaryExpression.Type type : ArithmeticBinaryExpression.Type.values()) {
        assertProjection("NULL " + type.getValue() + " NULL", null);

        assertProjection("42 " + type.getValue() + " NULL", null);
        assertProjection("NULL " + type.getValue() + " 42", null);

        assertProjection("11.1 " + type.getValue() + " NULL", null);
        assertProjection("NULL " + type.getValue() + " 11.1", null);
    }
}
项目:presto    文件:AstBuilder.java   
@Override
public Node visitArithmeticBinary(SqlBaseParser.ArithmeticBinaryContext context)
{
    return new ArithmeticBinaryExpression(
            getLocation(context.operator),
            getArithmeticBinaryOperator(context.operator),
            (Expression) visit(context.left),
            (Expression) visit(context.right));
}
项目:presto-query-formatter    文件:ExpressionFormatter.java   
@Override
protected String visitArithmeticBinary(ArithmeticBinaryExpression node, StackableAstVisitorContext<Integer> indent)
{
    return formatBinaryExpression(node.getType().getValue(), node.getLeft(), node.getRight(), indent);
}
项目:sql4es    文件:SimpleCalculation.java   
public ArithmeticBinaryExpression.Type getType(){
    return type;
}
项目:sql4es    文件:SelectParser.java   
@Override
protected ICalculation visitArithmeticBinary(ArithmeticBinaryExpression node, QueryState state){
    ICalculation left = visitExpression(node.getLeft(), state);
    ICalculation right = visitExpression(node.getRight(), state);
    return new SimpleCalculation(left, right, node.getType());
}
项目:presto    文件:Signatures.java   
public static Signature arithmeticExpressionSignature(ArithmeticBinaryExpression.Type expressionType, Type returnType, Type leftType, Type rightType)
{
    return internalOperator(expressionType.name(), returnType.getTypeSignature(), leftType.getTypeSignature(), rightType.getTypeSignature());
}
项目:presto    文件:AggregationAnalyzer.java   
@Override
protected Boolean visitArithmeticBinary(ArithmeticBinaryExpression node, Void context)
{
    return process(node.getLeft(), context) && process(node.getRight(), context);
}
项目:presto    文件:ExpressionAnalyzer.java   
@Override
protected Type visitArithmeticBinary(ArithmeticBinaryExpression node, StackableAstVisitorContext<AnalysisContext> context)
{
    return getOperator(context, node, OperatorType.valueOf(node.getType().name()), node.getLeft(), node.getRight());
}
项目:presto    文件:TestEqualityInference.java   
private static Expression add(Expression expression1, Expression expression2)
{
    return new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Type.ADD, expression1, expression2);
}
项目:presto    文件:TestEqualityInference.java   
private static Expression multiply(Expression expression1, Expression expression2)
{
    return new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Type.MULTIPLY, expression1, expression2);
}
项目:presto    文件:ExpressionFormatter.java   
@Override
protected String visitArithmeticBinary(ArithmeticBinaryExpression node, Boolean unmangleNames)
{
    return formatBinaryExpression(node.getType().getValue(), node.getLeft(), node.getRight(), unmangleNames);
}
项目:presto    文件:TestSqlParser.java   
@Test
public void testPrecedenceAndAssociativity()
        throws Exception
{
    assertExpression("1 AND 2 OR 3", new LogicalBinaryExpression(LogicalBinaryExpression.Type.OR,
            new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND,
                    new LongLiteral("1"),
                    new LongLiteral("2")),
            new LongLiteral("3")));

    assertExpression("1 OR 2 AND 3", new LogicalBinaryExpression(LogicalBinaryExpression.Type.OR,
            new LongLiteral("1"),
            new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND,
                    new LongLiteral("2"),
                    new LongLiteral("3"))));

    assertExpression("NOT 1 AND 2", new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND,
            new NotExpression(new LongLiteral("1")),
            new LongLiteral("2")));

    assertExpression("NOT 1 OR 2", new LogicalBinaryExpression(LogicalBinaryExpression.Type.OR,
            new NotExpression(new LongLiteral("1")),
            new LongLiteral("2")));

    assertExpression("-1 + 2", new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Type.ADD,
            negative(new LongLiteral("1")),
            new LongLiteral("2")));

    assertExpression("1 - 2 - 3", new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Type.SUBTRACT,
            new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Type.SUBTRACT,
                    new LongLiteral("1"),
                    new LongLiteral("2")),
            new LongLiteral("3")));

    assertExpression("1 / 2 / 3", new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Type.DIVIDE,
            new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Type.DIVIDE,
                    new LongLiteral("1"),
                    new LongLiteral("2")),
            new LongLiteral("3")));

    assertExpression("1 + 2 * 3", new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Type.ADD,
            new LongLiteral("1"),
            new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Type.MULTIPLY,
                    new LongLiteral("2"),
                    new LongLiteral("3"))));
}
项目:EchoQuery    文件:ExpressionFormatter.java   
@Override
protected String visitArithmeticBinary(ArithmeticBinaryExpression node, Boolean unmangleNames)
{
    return formatBinaryExpression(node.getType().getValue(), node.getLeft(), node.getRight(), unmangleNames);
}