Beispiel #1
0
def test_and_pushdown_relalg_filter():
    test = BarOpNode(
        BinaryOpNode(
            OpCodes.ADD,
            VarNode('foo', None),
            VarNode('buzz', None),
        ),
        BoolExprNode(
            OpCodes.AND,
            BoolExprNode(OpCodes.EQ, VarNode('bar', RelationNode('foo')),
                         BoolLiteral(True)),
            BoolExprNode(OpCodes.EQ, VarNode('baz', RelationNode('buzz')),
                         BoolLiteral(True))))
    expected = relalg.JoinNode(
        relalg.SelectNode(
            relalg.RelationNode('foo'),
            relalg.BoolOpNode(
                OpCodes.EQ,
                relalg.ProjectNode(relalg.RelationNode('foo'), ['bar']),
                relalg.BoolConstantNode(True))),
        relalg.SelectNode(
            relalg.RelationNode('buzz'),
            relalg.BoolOpNode(
                OpCodes.EQ,
                relalg.ProjectNode(relalg.RelationNode('buzz'), ['baz']),
                relalg.BoolConstantNode(True))),
        JoinTypes.INNER,
        JoinSides.FULL,
    )
    assert GavlToRelAlg().visit(test) == expected
Beispiel #2
0
def test_var_filter():
    test = "foo | foo.bar < baz"
    expected = BarOpNode(
        VarNode('foo', None),
        BoolExprNode(OpCodes.LT, VarNode('bar', RelationNode('foo')),
                     VarNode('baz', None)))
    assert parse(test) == expected
Beispiel #3
0
def process_bool_expr(t):
    if isinstance(t, (VarNode, BoolLiteral, IntNode, StrNode)):
        return t
    if len(t) == 1:
        return process_bool_expr(t[0])
    elif len(t) == 3:
        op = t[1]
        if op == "<=":
            op_code = OpCodes.LTE
        elif op == ">=":
            op_code = OpCodes.GTE
        elif op == "<":
            op_code = OpCodes.LT
        elif op == ">":
            op_code = OpCodes.GT
        elif op == "==":
            op_code = OpCodes.EQ
        elif op == "and":
            op_code = OpCodes.AND
        elif op == "or":
            op_code = OpCodes.OR
        else:
            op_code = None

        return BoolExprNode(op_code, process_bool_expr(t[0]),
                            process_bool_expr(t[2]))
Beispiel #4
0
def test_multiple_filter():
    test = "foo | foo.bar < baz | False"
    expected = BarOpNode(
        BarOpNode(
            VarNode('foo', None),
            BoolExprNode(OpCodes.LT, VarNode('bar', RelationNode('foo')),
                         VarNode('baz', None))),
        BoolLiteral(False),
    )
    assert parse(test) == expected
Beispiel #5
0
def test_expr_relalg_filter():
    test = BarOpNode(
        VarNode('foo', None),
        BoolExprNode(OpCodes.LT, VarNode('bar', RelationNode('foo')),
                     VarNode('baz', None)))
    expected = relalg.SelectNode(
        relalg.RelationNode('foo'),
        relalg.BoolOpNode(
            OpCodes.LT,
            relalg.ProjectNode(relalg.RelationNode('foo'), ['bar']),
            relalg.RelationNode('baz')))
    assert GavlToRelAlg().visit(test) == expected
Beispiel #6
0
def test_equal_filter():
    test = "foo | True == True"
    expected = BarOpNode(
        VarNode('foo', None),
        BoolExprNode(OpCodes.EQ, BoolLiteral(True), BoolLiteral(True)))
    assert parse(test) == expected