Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
0
def test_simple_relalg_filter():
    test = BarOpNode(VarNode('foo', None), BoolLiteral(True))
    expected = relalg.SelectNode(relalg.RelationNode('foo'),
                                 relalg.BoolConstantNode(True))
    assert GavlToRelAlg().visit(test) == expected
Ejemplo n.º 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
Ejemplo n.º 7
0
def test_simple_var():
    test = "foo.bar"
    expected = VarNode('bar', RelationNode(name='foo'))
    assert parse(test) == expected
Ejemplo n.º 8
0
def test_simple_filter():
    test = "foo | True"
    expected = BarOpNode(VarNode('foo', None), BoolLiteral(True))
    assert parse(test) == expected
Ejemplo n.º 9
0
def test_simple_string():
    test = "foo | 'hello, world'"
    expected = BarOpNode(VarNode('foo', None), StrNode('hello, world'))
    assert parse(test) == expected
Ejemplo n.º 10
0
def test_simple_assign():
    test = "foo = bar"
    expected = AssignNode('foo', VarNode('bar', None))
    assert parse(test) == expected
Ejemplo n.º 11
0
def test_simple_agg():
    test = "SUM(foo)"
    expected = ApplyNode('SUM', VarNode('foo', None))
    assert parse(test) == expected
Ejemplo n.º 12
0
def test_simple_arith():
    test = "A + B"
    expected = BinaryOpNode(OpCodes.ADD, VarNode("A", relation=None),
                            VarNode("B", relation=None))
    assert parse(test) == expected
Ejemplo n.º 13
0
def parseVariable(t):
    if len(t) == 1:
        return VarNode(t[0], relation=None)
    else:
        relation = RelationNode('.'.join(t[:-1]))
        return VarNode(t[-1], relation=relation)