Ejemplo n.º 1
0
def test_sql_query_limits(alltypes):
    table = alltypes
    with config.option_context('sql.default_limit', 100000):
        # table has 25 rows
        assert len(table.execute()) == 7300
        # comply with limit arg for TableExpr
        assert len(table.execute(limit=10)) == 10
        # state hasn't changed
        assert len(table.execute()) == 7300
        # non-TableExpr ignores default_limit
        assert table.count().execute() == 7300
        # non-TableExpr doesn't observe limit arg
        assert table.count().execute(limit=10) == 7300
    with config.option_context('sql.default_limit', 20):
        # TableExpr observes default limit setting
        assert len(table.execute()) == 20
        # explicit limit= overrides default
        assert len(table.execute(limit=15)) == 15
        assert len(table.execute(limit=23)) == 23
        # non-TableExpr ignores default_limit
        assert table.count().execute() == 7300
        # non-TableExpr doesn't observe limit arg
        assert table.count().execute(limit=10) == 7300
    # eliminating default_limit doesn't break anything
    with config.option_context('sql.default_limit', None):
        assert len(table.execute()) == 7300
        assert len(table.execute(limit=15)) == 15
        assert len(table.execute(limit=10000)) == 7300
        assert table.count().execute() == 7300
        assert table.count().execute(limit=10) == 7300
Ejemplo n.º 2
0
 def test_sql_query_limits(self):
     table = self.con.table('tpch_nation', database=self.test_data_db)
     with config.option_context('sql.default_limit', 100000):
         # table has 25 rows
         assert len(table.execute()) == 25
         # comply with limit arg for TableExpr
         assert len(table.execute(limit=10)) == 10
         # state hasn't changed
         assert len(table.execute()) == 25
         # non-TableExpr ignores default_limit
         assert table.count().execute() == 25
         # non-TableExpr doesn't observe limit arg
         assert table.count().execute(limit=10) == 25
     with config.option_context('sql.default_limit', 20):
         # TableExpr observes default limit setting
         assert len(table.execute()) == 20
         # explicit limit= overrides default
         assert len(table.execute(limit=15)) == 15
         assert len(table.execute(limit=23)) == 23
         # non-TableExpr ignores default_limit
         assert table.count().execute() == 25
         # non-TableExpr doesn't observe limit arg
         assert table.count().execute(limit=10) == 25
     # eliminating default_limit doesn't break anything
     with config.option_context('sql.default_limit', None):
         assert len(table.execute()) == 25
         assert len(table.execute(limit=15)) == 15
         assert len(table.execute(limit=10000)) == 25
         assert table.count().execute() == 25
         assert table.count().execute(limit=10) == 25
Ejemplo n.º 3
0
def test_verbose_log_queries(con, test_data_db):
    queries = []

    with config.option_context('verbose', True):
        with config.option_context('verbose_log', queries.append):
            con.table('tpch_orders', database=test_data_db)

    assert len(queries) == 1
    query, = queries
    expected = 'DESCRIBE {}.`tpch_orders`'.format(test_data_db)
    assert query == expected
Ejemplo n.º 4
0
    def test_disable_query_limit(self):
        table = self.con.table('functional_alltypes')

        with config.option_context('interactive', True):
            with config.option_context('sql.default_limit', None):
                repr(table)

        expected = """\
SELECT *
FROM functional_alltypes"""

        assert self.con.executed_queries[0] == expected
Ejemplo n.º 5
0
    def test_verbose_log_queries(self):
        queries = []

        def logger(x):
            queries.append(x)

        with config.option_context("verbose", True):
            with config.option_context("verbose_log", logger):
                self.con.table("tpch_orders", database=self.test_data_db)

        assert len(queries) == 1
        expected = "SELECT * FROM {0}.`tpch_orders` LIMIT 0".format(self.test_data_db)
        assert queries[0] == expected
Ejemplo n.º 6
0
    def test_verbose_log_queries(self):
        queries = []

        def logger(x):
            queries.append(x)

        with config.option_context('verbose', True):
            with config.option_context('verbose_log', logger):
                self.con.table('tpch_orders', database=self.test_data_db)

        assert len(queries) == 1
        expected = 'DESCRIBE {0}.`tpch_orders`'.format(self.test_data_db)
        assert queries[0] == expected
Ejemplo n.º 7
0
def test_verbose_log_queries(con, db):
    queries = []

    def logger(x):
        queries.append(x)

    with config.option_context('verbose', True):
        with config.option_context('verbose_log', logger):
            con.table('functional_alltypes', database=db.name)

    expected = 'DESC {0}.`functional_alltypes`'.format(db.name)

    assert len(queries) == 1
    assert queries[0] == expected
Ejemplo n.º 8
0
    def test_interactive_execute_on_repr(self):
        table = self.con.table('functional_alltypes')
        expr = table.bigint_col.sum()
        with config.option_context('interactive', True):
            repr(expr)

        assert len(self.con.executed_queries) > 0
Ejemplo n.º 9
0
 def test_histogram_repr_no_query_execute(self):
     t = self.con.table('functional_alltypes')
     tier = t.double_col.histogram(10).name('bucket')
     expr = t.group_by(tier).size()
     with config.option_context('interactive', True):
         expr._repr()
     assert self.con.executed_queries == []
Ejemplo n.º 10
0
    def test_interactive_non_compilable_repr_not_fail(self):
        # #170
        table = self.con.table('functional_alltypes')

        expr = table.string_col.topk(3)

        # it works!
        with config.option_context('interactive', True):
            repr(expr)
Ejemplo n.º 11
0
    def test_projection_unnamed_literal_interactive_blowup(self):
        # #147 and #153 alike
        table = self.con.table('functional_alltypes')

        with config.option_context('interactive', True):
            try:
                table.select([table.bigint_col, ibis.literal(5)])
            except Exception as e:
                assert 'named' in e.message
Ejemplo n.º 12
0
def test_interactive_repr_shows_error(alltypes):
    # #591. Doing this in SQLite because so many built-in functions are not
    # available

    expr = alltypes.double_col.approx_nunique()

    with config.option_context('interactive', True):
        result = repr(expr)
        assert 'no translation rule' in result.lower()
Ejemplo n.º 13
0
    def test_interactive_repr_shows_error(self):
        # #591. Doing this in PostgreSQL because so many built-in functions are
        # not available
        import ibis.config as config

        expr = self.alltypes.double_col.approx_nunique()

        with config.option_context('interactive', True):
            result = repr(expr)
            assert 'no translator rule' in result.lower()
Ejemplo n.º 14
0
    def test_default_limit(self):
        table = self.con.table('functional_alltypes')

        with config.option_context('interactive', True):
            repr(table)

        expected = """\
SELECT *
FROM functional_alltypes
LIMIT {0}""".format(config.options.sql.default_limit)

        assert self.con.executed_queries[0] == expected
Ejemplo n.º 15
0
    def test_respect_set_limit(self):
        table = self.con.table('functional_alltypes').limit(10)

        with config.option_context('interactive', True):
            repr(table)

        expected = """\
SELECT *
FROM functional_alltypes
LIMIT 10"""

        assert self.con.executed_queries[0] == expected
Ejemplo n.º 16
0
    def test_interactive_repr_call_failure(self):
        t = self.con.table("tpch_lineitem").limit(100000)

        t = t[t, t.l_receiptdate.cast("timestamp").name("date")]

        keys = [t.date.year().name("year"), "l_linestatus"]
        filt = t.l_linestatus.isin(["F"])
        expr = t[filt].group_by(keys).aggregate(t.l_extendedprice.mean().name("avg_px"))

        w2 = ibis.trailing_window(9, group_by=expr.l_linestatus, order_by=expr.year)

        metric = expr["avg_px"].mean().over(w2)
        enriched = expr[expr, metric]
        with config.option_context("interactive", True):
            repr(enriched)
Ejemplo n.º 17
0
    def test_adapt_scalar_array_results(self):
        table = self.alltypes

        expr = table.double_col.sum()
        result = self.con.execute(expr)
        assert isinstance(result, float)

        with config.option_context("interactive", True):
            result2 = expr.execute()
            assert isinstance(result2, float)

        expr = table.group_by("string_col").aggregate([table.count().name("count")]).string_col

        result = self.con.execute(expr)
        assert isinstance(result, pd.Series)
Ejemplo n.º 18
0
    def test_interactive_repr_call_failure(self):
        t = self.con.table('tpch_lineitem').limit(100000)

        t = t[t, t.l_receiptdate.cast('timestamp').name('date')]

        keys = [t.date.year().name('year'), 'l_linestatus']
        filt = t.l_linestatus.isin(['F'])
        expr = (t[filt]
                .group_by(keys)
                .aggregate(t.l_extendedprice.mean().name('avg_px')))

        w2 = ibis.trailing_window(9, group_by=expr.l_linestatus,
                                  order_by=expr.year)

        metric = expr['avg_px'].mean().over(w2)
        enriched = expr[expr, metric]
        with config.option_context('interactive', True):
            repr(enriched)
Ejemplo n.º 19
0
def test_adapt_scalar_array_results(con, alltypes):
    table = alltypes

    expr = table.double_col.sum()
    result = con.execute(expr)
    assert isinstance(result, float)

    with config.option_context('interactive', True):
        result2 = expr.execute()
        assert isinstance(result2, float)

    expr = (
        table.group_by('string_col')
        .aggregate([table.count().name('count')])
        .string_col
    )

    result = con.execute(expr)
    assert isinstance(result, pd.Series)
Ejemplo n.º 20
0
def test_interactive_repr_shows_error(alltypes):
    expr = alltypes.double_col.approx_median()
    with config.option_context('interactive', True):
        result = repr(expr)
    assert 'no translation rule' in result.lower()
Ejemplo n.º 21
0
def test_limit_equals_none_no_limit(alltypes):
    with config.option_context('sql.default_limit', 10):
        result = alltypes.execute(limit=None)
        assert len(result) > 10
Ejemplo n.º 22
0
    def test_limit_equals_none_no_limit(self):
        t = self.alltypes

        with config.option_context('sql.default_limit', 10):
            result = t.execute(limit=None)
            assert len(result) > 10
Ejemplo n.º 23
0
def test_limit_equals_none_no_limit(alltypes):
    with config.option_context('sql.default_limit', 10):
        result = alltypes.execute(limit=None)
        assert len(result) > 10
Ejemplo n.º 24
0
 def test_isin_rule_supressed_exception_repr_not_fail(self):
     with config.option_context('interactive', True):
         t = self.con.table('functional_alltypes')
         bool_clause = t['string_col'].notin(['1', '4', '7'])
         expr = t[bool_clause]['string_col'].value_counts()
         repr(expr)
Ejemplo n.º 25
0
    def test_repr_png_is_none_in_interactive(self):
        table = self.con.table('functional_alltypes')

        with config.option_context('interactive', True):
            assert table._repr_png_() is None
Ejemplo n.º 26
0
 def test_isin_rule_supressed_exception_repr_not_fail(self):
     with config.option_context('interactive', True):
         t = self.con.table('functional_alltypes')
         bool_clause = t['string_col'].notin(['1', '4', '7'])
         expr = t[bool_clause]['string_col'].value_counts()
         repr(expr)
Ejemplo n.º 27
0
    def test_limit_equals_none_no_limit(self):
        t = self.alltypes

        with config.option_context('sql.default_limit', 10):
            result = t.execute(limit=None)
            assert len(result) > 10