Exemplo 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
Exemplo n.º 2
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
Exemplo n.º 3
0
    def query(self, query, groupby=[], output_sql=False):
        groupby = [tuple(x.split('.')) for x in groupby]
        root_ast = gavl.parse(query)
        root_ast = VariableSaver(self).visit(root_ast)

        root_relalg = gavl.plan(root_ast)
        root_relalg = VariableReplacer(self).visit(root_relalg)

        root_plan = QueryPlanner(self).visit(root_relalg)
        if output_sql:
            SQLQueryPrinter().visit(root_plan)
        result = QueryExecutor(self, groupby).visit(root_plan)

        active_field = list(ActiveFieldResolver().visit(root_relalg))

        result.rename(columns={active_field[0]: "result"}, inplace=True)

        return result
Exemplo n.º 4
0
def test_simple_apply():
    test = "foo(1)"
    expected = ApplyNode('foo', IntNode(1))
    assert gavl.parse(test) == expected
Exemplo n.º 5
0
def test_two_args_apply():
    test = "LEAST(1, 2)"
    expected = BinaryOpNode(OpCodes.LEAST, IntNode(1), IntNode(2))
    assert gavl.parse(test) == expected
Exemplo 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
Exemplo n.º 7
0
def test_simple_var():
    test = "foo.bar"
    expected = VarNode('bar', RelationNode(name='foo'))
    assert parse(test) == expected
Exemplo n.º 8
0
def test_simple_filter():
    test = "foo | True"
    expected = BarOpNode(VarNode('foo', None), BoolLiteral(True))
    assert parse(test) == expected
Exemplo n.º 9
0
def test_simple_string():
    test = "foo | 'hello, world'"
    expected = BarOpNode(VarNode('foo', None), StrNode('hello, world'))
    assert parse(test) == expected
Exemplo n.º 10
0
def test_simple_constant():
    test = "1"
    expected = IntNode(1)
    assert parse(test) == expected
Exemplo n.º 11
0
def test_simple_assign():
    test = "foo = bar"
    expected = AssignNode('foo', VarNode('bar', None))
    assert parse(test) == expected
Exemplo n.º 12
0
def test_simple_agg():
    test = "SUM(foo)"
    expected = ApplyNode('SUM', VarNode('foo', None))
    assert parse(test) == expected
Exemplo n.º 13
0
def test_simple_arith():
    test = "A + B"
    expected = BinaryOpNode(OpCodes.ADD, VarNode("A", relation=None),
                            VarNode("B", relation=None))
    assert parse(test) == expected