Exemplo n.º 1
0
    def test_logical_or(self):
        const_exp1 = ConstantValueExpression(1)
        const_exp2 = ConstantValueExpression(1)

        comparison_expression_left = ComparisonExpression(
            ExpressionType.COMPARE_EQUAL,
            const_exp1,
            const_exp2
        )
        const_exp1 = ConstantValueExpression(1)
        const_exp2 = ConstantValueExpression(2)
        comparison_expression_right = ComparisonExpression(
            ExpressionType.COMPARE_GREATER,
            const_exp1,
            const_exp2
        )
        logical_expr = LogicalExpression(
            ExpressionType.LOGICAL_OR,
            comparison_expression_left,
            comparison_expression_right
        )
        self.assertEqual(
            [True],
            logical_expr.evaluate(None).frames[0].tolist()
        )
Exemplo n.º 2
0
    def test_short_circuiting_or_complete(self):
        # tests whether right-hand side is bypassed completely with or
        tup_val_exp_l = TupleValueExpression(col_name=0)
        tup_val_exp_l.col_alias = 0
        tup_val_exp_r = TupleValueExpression(col_name=1)
        tup_val_exp_r.col_alias = 1

        comp_exp_l = ComparisonExpression(
            ExpressionType.COMPARE_EQUAL,
            tup_val_exp_l,
            tup_val_exp_r
        )
        comp_exp_r = Mock(spec=ComparisonExpression)

        logical_exp = LogicalExpression(
            ExpressionType.LOGICAL_OR,
            comp_exp_l,
            comp_exp_r
        )

        tuples = Batch(pd.DataFrame(
            {0: [1, 2, 3], 1: [1, 2, 3]}))
        self.assertEqual(
            [True, True, True],
            logical_exp.evaluate(tuples).frames[0].tolist()
        )
        comp_exp_r.evaluate.assert_not_called()
Exemplo n.º 3
0
    def test_short_circuiting_or_partial(self):
        # tests whether right-hand side is partially executed with or
        tup_val_exp_l = TupleValueExpression(col_name=0)
        tup_val_exp_l.col_alias = 0
        tup_val_exp_r = TupleValueExpression(col_name=1)
        tup_val_exp_r.col_alias = 1

        comp_exp_l = ComparisonExpression(
            ExpressionType.COMPARE_EQUAL,
            tup_val_exp_l,
            tup_val_exp_r
        )
        comp_exp_r = Mock(spec=ComparisonExpression)
        comp_exp_r.evaluate = Mock(return_value=Mock(frames=[[True], [False]]))

        logical_exp = LogicalExpression(
            ExpressionType.LOGICAL_OR,
            comp_exp_l,
            comp_exp_r
        )

        tuples = Batch(pd.DataFrame(
            {0: [1, 2, 3, 4], 1: [5, 6, 3, 4]}))
        self.assertEqual(
            [True, False, True, True],
            logical_exp.evaluate(tuples).frames[0].tolist()
        )
        comp_exp_r.evaluate.assert_called_once_with(tuples, mask=[0, 1])
Exemplo n.º 4
0
 def visitLogicalExpression(self,
                            ctx: evaql_parser.LogicalExpressionContext):
     if len(ctx.children) < 3:
         # error scenario, should have 3 children
         return None
     left = self.visit(ctx.getChild(0))
     op = self.visit(ctx.getChild(1))
     right = self.visit(ctx.getChild(2))
     return LogicalExpression(op, left, right)
Exemplo n.º 5
0
    def test_should_return_false_for_unequal_expressions(self):
        const_exp1 = ConstantValueExpression(0)
        const_exp2 = ConstantValueExpression(1)
        func_expr = FunctionExpression(lambda x: x + 1, name='test')
        cmpr_exp = ComparisonExpression(ExpressionType.COMPARE_NEQ, const_exp1,
                                        const_exp2)
        tuple_expr = TupleValueExpression(col_name='id')
        aggr_expr = AggregationExpression(ExpressionType.AGGREGATION_MAX, None,
                                          tuple_expr)
        logical_expr = LogicalExpression(ExpressionType.LOGICAL_OR, cmpr_exp,
                                         cmpr_exp)

        self.assertNotEqual(const_exp1, const_exp2)
        self.assertNotEqual(cmpr_exp, const_exp1)
        self.assertNotEqual(func_expr, cmpr_exp)
        self.assertNotEqual(tuple_expr, aggr_expr)
        self.assertNotEqual(aggr_expr, tuple_expr)
        self.assertNotEqual(tuple_expr, cmpr_exp)
        self.assertNotEqual(logical_expr, cmpr_exp)