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
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
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
def test_equal_filter(): test = "foo | True == True" expected = BarOpNode( VarNode('foo', None), BoolExprNode(OpCodes.EQ, BoolLiteral(True), BoolLiteral(True))) assert parse(test) == expected
def test_simple_filter(): test = "foo | True" expected = BarOpNode(VarNode('foo', None), BoolLiteral(True)) assert parse(test) == expected
(multop, 2, opAssoc.LEFT), (plusop, 2, opAssoc.LEFT), ]) expr.setParseAction(lambda t: process_expr(t)) def process_stmt(t): if t[0] is None: return t[1] else: return AssignNode(t[0].var_name, t[1]) bool_false = Literal("False") bool_false.setParseAction(lambda t: BoolLiteral(False)) bool_true = Literal("True") bool_true.setParseAction(lambda t: BoolLiteral(True)) bool_atom = bool_true | bool_false | variable | integer | str_literal bool_op = oneOf('== <= >= < >') bool_and = Literal('and') bool_or = Literal('or') bool_expr = operatorPrecedence(bool_atom, [(bool_op, 2, opAssoc.LEFT), (bool_and, 2, opAssoc.LEFT), (bool_or, 2, opAssoc.LEFT)]) bool_expr.setParseAction(lambda t: process_bool_expr(t)) barop << expr + ZeroOrMore(Suppress("|") - bool_expr) barop.setParseAction(lambda t: process_barop(t))