From aa6568bac288fb5bf7a2c9c016ddab562cd6d5b4 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Sun, 14 Jun 2020 22:30:39 +0200 Subject: [PATCH] Check class too when matching --- relational/optimizations.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/relational/optimizations.py b/relational/optimizations.py index 51819a7..d9f15e2 100644 --- a/relational/optimizations.py +++ b/relational/optimizations.py @@ -72,7 +72,7 @@ def duplicated_select(n: parser.Node) -> Tuple[parser.Node, int]: in and ''' changes = 0 - while n.name == SELECTION and n.child.name == SELECTION: + while isinstance(n, parser.UNARY) and n.name == SELECTION and isinstance(n.child, parser.UNARY) and n.child.name == SELECTION: changes += 1 prop = n.prop @@ -147,7 +147,7 @@ def down_to_unions_subtractions_intersections(n: parser.Node) -> Tuple[parser.No ''' changes = 0 _o = (UNION, DIFFERENCE, INTERSECTION) - if n.name == SELECTION and n.child.name in _o: + if isinstance(n, parser.UNARY) and n.name == SELECTION and n.child.name in _o: l = parser.Unary(SELECTION, n.prop, n.child.left) r = parser.Unary(SELECTION, n.prop, n.child.right) @@ -170,7 +170,7 @@ def duplicated_projection(n: parser.Node) -> Tuple[parser.Node, int]: def selection_inside_projection(n: parser.Node) -> Tuple[parser.Node, int]: '''This function locates things like σ j (π k(R)) and converts them into π k(σ j (R))''' - if n.name == SELECTION and n.child.name == PROJECTION: + if isinstance(n, parser.UNARY) and n.name == SELECTION and n.child.name == PROJECTION: child = parser.Unary( SELECTION, n.prop, @@ -338,7 +338,7 @@ def swap_rename_select(n: parser.Node) -> int: Renaming the attributes used in the selection, so the operation is still valid.''' - if n.name == SELECTION and n.child.name == RENAME: + if isinstance(n, parser.UNARY) and n.name == SELECTION and n.child.name == RENAME: # This is an inverse mapping for the rename renames = {v: k for k, v in n.child.get_rename_prop().items()} @@ -438,7 +438,7 @@ def selection_and_product(n: parser.Node, rels: Dict[str, Relation]) -> parser.N σ l (σ j (R) * σ i (Q)). Where j contains only attributes belonging to R, i contains attributes belonging to Q and l contains attributes belonging to both''' - if n.name == SELECTION and n.child.name in (PRODUCT, JOIN): + if isinstance(n, parser.UNARY) and n.name == SELECTION and n.child.name in (PRODUCT, JOIN): l_attr = n.child.left.result_format(rels) r_attr = n.child.right.result_format(rels)