Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Commit 0c70760

Browse files
ruxuezxuebinsu
andcommitted
Fix select slice with [:] (#196)
This patch fixes the following issue when selecting an entire dataframe with slice doesn't contain a LIMIT clause in the query. --------- Co-authored-by: Xuebin Su (苏学斌) <[email protected]>
1 parent cb52c2f commit 0c70760

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

greenplumpython/dataframe.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<https://www.postgresql.org/docs/current/sql-refreshmaterializedview.html>`_ for syncing updates.
2727
"""
2828
import json
29+
import sys
2930
from collections import abc
3031
from functools import partialmethod, singledispatchmethod
3132
from typing import (
@@ -117,12 +118,14 @@ def _(self, rows: slice) -> "DataFrame":
117118
raise NotImplementedError()
118119
offset_clause = "" if rows.start is None else f"OFFSET {rows.start}"
119120
limit_clause = (
120-
""
121+
sys.maxsize
121122
if rows.stop is None
122-
else f"LIMIT {rows.stop if rows.start is None else rows.stop - rows.start}"
123+
else rows.stop
124+
if rows.start is None
125+
else rows.stop - rows.start
123126
)
124127
return DataFrame(
125-
f"SELECT * FROM {self._name} {limit_clause} {offset_clause}",
128+
f"SELECT * FROM {self._name} LIMIT {limit_clause} {offset_clause}",
126129
parents=[self],
127130
)
128131

tests/test_dataframe.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ def test_dataframe_getitem_slice_off_limit(db: gp.Database, t: gp.DataFrame):
6262
assert len(list(t[2:5])) == 3
6363

6464

65+
def test_dataframe_getitem_slice_off_limit(db: gp.Database, t: gp.DataFrame):
66+
query = t[:]._build_full_query()
67+
assert len(list(t[:])) == 10
68+
assert "LIMIT" in query
69+
70+
6571
def test_dataframe_display_repr(db: gp.Database):
6672
# fmt: off
6773
rows = [(1, 1, "Lion",), (2, 2, "Tiger",), (3, 3, "Wolf",), (4, 4, "Fox")]

0 commit comments

Comments
 (0)