Exemplo n.º 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
Exemplo n.º 2
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
Exemplo n.º 3
0
    def visit_relation(self, node):
        symbol = self.engine.get_symbol(node.name)
        if symbol:
            compiled_relalg = VariableReplacer(self.engine).visit(relation)
            return compiled_relalg

        relation = self.engine.get_relation(node.name)
        if relation:
            return relalg.RelationNode(node.name)

        raise Exception("Cannot find relation or symbol "
                            "'{}'".format(node.name))
Exemplo n.º 4
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