def _check_fusion(self, root): roots = root.table._root_tables() validator = ExprValidator([root.table]) fused_exprs = [] can_fuse = False for val in self.clean_exprs: # XXX lifted_val = substitute_parents(val) # a * projection if (isinstance(val, ir.TableExpr) and (self.parent.op().is_ancestor(val) or # gross we share the same table root. Better way to # detect? len(roots) == 1 and val._root_tables()[0] is roots[0])): can_fuse = True fused_exprs.extend(root.selections) elif validator.validate(lifted_val): fused_exprs.append(lifted_val) elif not validator.validate(val): can_fuse = False break else: fused_exprs.append(val) if can_fuse: return ops.Projection(root.table, fused_exprs) else: return None
def get_result(self): roots = self.parent_roots if len(roots) == 1 and isinstance(roots[0], ops.Projection): fused_op = self._check_fusion(roots[0]) if fused_op is not None: return fused_op return ops.Projection(self.parent, self.clean_exprs)
def _lift_Projection(self, expr, block=None): if block is None: block = self.block_projection op = expr.op() if block: # GH #549: dig no further return expr else: lifted_table, unch = self._lift_arg(op.table, block=True) lifted_selections, unch_sel = self._lift_arg(op.selections, block=True) unchanged = unch and unch_sel if not unchanged: lifted_projection = ops.Projection(lifted_table, lifted_selections) result = ir.TableExpr(lifted_projection) else: result = expr return result