Skip to content

Commit

Permalink
fix(sqlalchemy): ensure that limit on .sql calls works
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Oct 23, 2023
1 parent 249c3b5 commit a5e3062
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ibis/backends/base/sql/alchemy/query_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,10 @@ def _add_limit(self, fragment):
)

if n is not None:
fragment = fragment.limit(n)
try:
fragment = fragment.limit(n)
except AttributeError:
fragment = fragment.subquery().select().limit(n)

offset = self.limit.offset

Expand Down
9 changes: 9 additions & 0 deletions ibis/backends/tests/test_dot_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,12 @@ def test_order_by_no_projection(backend):

result = con.sql(ibis.to_sql(expr)).execute().name.iloc[:2]
assert set(result) == {"Ross, Jerry L.", "Chang-Diaz, Franklin R."}


@dot_sql_notimpl
@dot_sql_notyet
@dot_sql_never
@pytest.mark.notyet(["polars"], raises=PolarsComputeError)
def test_dot_sql_limit(con):
expr = con.sql("SELECT 'abc' ts").limit(1)
assert expr.execute().equals(pd.DataFrame({"ts": ["abc"]}))

0 comments on commit a5e3062

Please sign in to comment.