Beispiel #1
0
def test_compound_aggregate_expr(table):
    # See ibis #24
    compound_expr = (table['a'].sum() / table['a'].mean()).name('foo')
    assert ops.is_reduction(compound_expr)

    # Validates internally
    table.aggregate([compound_expr])
Beispiel #2
0
    def test_compound_aggregate_expr(self):
        # See ibis #24
        compound_expr = (self.table['a'].sum() /
                         self.table['a'].mean()).name('foo')
        assert ops.is_reduction(compound_expr)

        # Validates internally
        self.table.aggregate([compound_expr])
Beispiel #3
0
    def test_any_all_notany(self):
        col = self.table['h']

        expr1 = col.any()
        expr2 = col.notany()
        expr3 = col.all()
        expr4 = (self.table.c == 0).any()
        expr5 = (self.table.c == 0).all()

        for expr in [expr1, expr2, expr3, expr4, expr5]:
            assert isinstance(expr, api.BooleanScalar)
            assert ops.is_reduction(expr)
Beispiel #4
0
    def test_any_all_notany(self):
        col = self.table['h']

        expr1 = col.any()
        expr2 = col.notany()
        expr3 = col.all()
        expr4 = (self.table.c == 0).any()
        expr5 = (self.table.c == 0).all()

        for expr in [expr1, expr2, expr3, expr4, expr5]:
            assert isinstance(expr, api.BooleanScalar)
            assert ops.is_reduction(expr)
Beispiel #5
0
    def _visit_filter(self, expr):
        # Dumping ground for analysis of WHERE expressions
        # - Subquery extraction
        # - Conversion to explicit semi/anti joins
        # - Rewrites to generate subqueries

        op = expr.op()

        method = '_visit_filter_{0}'.format(type(op).__name__)
        if hasattr(self, method):
            f = getattr(self, method)
            return f(expr)

        unchanged = True
        if isinstance(expr, ir.ScalarExpr):
            if ops.is_reduction(expr):
                return self._rewrite_reduction_filter(expr)

        if isinstance(op, ops.BinaryOp):
            left = self._visit_filter(op.left)
            right = self._visit_filter(op.right)
            unchanged = left is op.left and right is op.right
            if not unchanged:
                return type(expr)(type(op)(left, right))
            else:
                return expr
        elif isinstance(
                op,
            (ops.Any, ops.BooleanValueOp, ops.TableColumn, ir.Literal)):
            return expr
        elif isinstance(op, ops.ValueNode):
            visited = [
                self._visit_filter(arg) if isinstance(arg, ir.Expr) else arg
                for arg in op.args
            ]
            unchanged = True
            for new, old in zip(visited, op.args):
                if new is not old:
                    unchanged = False
            if not unchanged:
                return type(expr)(type(op)(*visited))
            else:
                return expr
        else:
            raise NotImplementedError(type(op))
Beispiel #6
0
    def _visit_filter(self, expr):
        # Dumping ground for analysis of WHERE expressions
        # - Subquery extraction
        # - Conversion to explicit semi/anti joins
        # - Rewrites to generate subqueries

        op = expr.op()

        method = '_visit_filter_{0}'.format(type(op).__name__)
        if hasattr(self, method):
            f = getattr(self, method)
            return f(expr)

        unchanged = True
        if isinstance(expr, ir.ScalarExpr):
            if ops.is_reduction(expr):
                return self._rewrite_reduction_filter(expr)

        if isinstance(op, ops.BinaryOp):
            left = self._visit_filter(op.left)
            right = self._visit_filter(op.right)
            unchanged = left is op.left and right is op.right
            if not unchanged:
                return type(expr)(type(op)(left, right))
            else:
                return expr
        elif isinstance(op, (ops.Any, ops.BooleanValueOp,
                             ops.TableColumn, ir.Literal)):
            return expr
        elif isinstance(op, ops.ValueNode):
            visited = [self._visit_filter(arg)
                       if isinstance(arg, ir.Expr) else arg
                       for arg in op.args]
            unchanged = True
            for new, old in zip(visited, op.args):
                if new is not old:
                    unchanged = False
            if not unchanged:
                return type(expr)(type(op)(*visited))
            else:
                return expr
        else:
            raise NotImplementedError(type(op))
Beispiel #7
0
def test_any_all_notany(table, column, operation):
    expr = operation(table[column])
    assert isinstance(expr, api.BooleanScalar)
    assert ops.is_reduction(expr)
Beispiel #8
0
 def _scalar_reduce(x):
     return isinstance(x, ir.ScalarExpr) and ops.is_reduction(x)
Beispiel #9
0
 def _scalar_reduce(x):
     return isinstance(x, ir.ScalarExpr) and ops.is_reduction(x)
Beispiel #10
0
def test_arbitrary(table, column, how, condition_fn):
    col = table[column]
    where = condition_fn(table)
    expr = col.arbitrary(how=how, where=where)
    assert isinstance(expr, col.type().scalar_type())
    assert ops.is_reduction(expr)
Beispiel #11
0
def test_any_all_notany(table, column, operation):
    expr = operation(table[column])
    assert isinstance(expr, api.BooleanScalar)
    assert ops.is_reduction(expr)