Skip to content

Commit d61d309

Browse files
committed
Respect _limit and _offset kwargs for select distinct
1 parent 5c2dc8d commit d61d309

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

dataset/table.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ def __len__(self):
675675
"""Return the number of rows in the table."""
676676
return self.count()
677677

678-
def distinct(self, *args, **_filter):
678+
def distinct(self, *args, **kwargs):
679679
"""Return all the unique (distinct) values for the given ``columns``.
680680
::
681681
@@ -699,14 +699,18 @@ def distinct(self, *args, **_filter):
699699
raise DatasetException("No such column: %s" % column)
700700
columns.append(self.table.c[column])
701701

702-
clause = self._args_to_clause(_filter, clauses=clauses)
702+
_limit = kwargs.pop("_limit", None)
703+
_offset = kwargs.pop("_offset", 0)
704+
clause = self._args_to_clause(kwargs, clauses=clauses)
703705
if not len(columns):
704706
return iter([])
705707

706708
q = expression.select(
707709
columns,
708710
distinct=True,
709711
whereclause=clause,
712+
limit=_limit,
713+
offset=_offset,
710714
order_by=[c.asc() for c in columns],
711715
)
712716
return self.db.query(q)

test/test_dataset.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ def test_distinct(self):
384384
assert len(x) == 3, x
385385
x = list(self.tbl.distinct("temperature", place=["B€rkeley", "G€lway"]))
386386
assert len(x) == 6, x
387+
x = list(self.tbl.distinct("temperature", _limit=3, place=["B€rkeley", "G€lway"]))
388+
assert len(x) == 3, x
389+
x = list(self.tbl.distinct("temperature", _limit=6, _offset=1, place=["B€rkeley", "G€lway"]))
390+
assert len(x) == 5, x
387391

388392
def test_insert_many(self):
389393
data = TEST_DATA * 100

0 commit comments

Comments
 (0)