@@ -113,10 +113,12 @@ def connection(self, extra_params=()):
113113 conn .close ()
114114
115115 @contextmanager
116- def cursor (self , extra_params = ()):
116+ def cursor (self , extra_params = (), extra_cursor_params = () ):
117117 with self .connection (extra_params ) as conn :
118118 cursor = conn .cursor (
119- arraysize = self .arraysize , buffer_size_bytes = self .buffer_size_bytes
119+ arraysize = self .arraysize ,
120+ buffer_size_bytes = self .buffer_size_bytes ,
121+ ** dict (extra_cursor_params ),
120122 )
121123 try :
122124 yield cursor
@@ -988,6 +990,60 @@ def test_catalogs_returns_arrow_table(self):
988990 results = cursor .fetchall_arrow ()
989991 assert isinstance (results , pyarrow .Table )
990992
993+ def test_row_limit_with_larger_result (self ):
994+ """Test that row_limit properly constrains results when query would return more rows"""
995+ row_limit = 1000
996+ with self .cursor (extra_cursor_params = {"row_limit" : row_limit }) as cursor :
997+ # Execute a query that returns more than row_limit rows
998+ cursor .execute ("SELECT * FROM range(2000)" )
999+ rows = cursor .fetchall ()
1000+
1001+ # Check if the number of rows is limited to row_limit
1002+ assert len (rows ) == row_limit , f"Expected { row_limit } rows, got { len (rows )} "
1003+
1004+ def test_row_limit_with_smaller_result (self ):
1005+ """Test that row_limit doesn't affect results when query returns fewer rows than limit"""
1006+ row_limit = 100
1007+ expected_rows = 50
1008+ with self .cursor (extra_cursor_params = {"row_limit" : row_limit }) as cursor :
1009+ # Execute a query that returns fewer than row_limit rows
1010+ cursor .execute (f"SELECT * FROM range({ expected_rows } )" )
1011+ rows = cursor .fetchall ()
1012+
1013+ # Check if all rows are returned (not limited by row_limit)
1014+ assert (
1015+ len (rows ) == expected_rows
1016+ ), f"Expected { expected_rows } rows, got { len (rows )} "
1017+
1018+ @skipUnless (pysql_supports_arrow (), "arrow test needs arrow support" )
1019+ def test_row_limit_with_arrow_larger_result (self ):
1020+ """Test that row_limit properly constrains arrow results when query would return more rows"""
1021+ row_limit = 800
1022+ with self .cursor (extra_cursor_params = {"row_limit" : row_limit }) as cursor :
1023+ # Execute a query that returns more than row_limit rows
1024+ cursor .execute ("SELECT * FROM range(1500)" )
1025+ arrow_table = cursor .fetchall_arrow ()
1026+
1027+ # Check if the number of rows in the arrow table is limited to row_limit
1028+ assert (
1029+ arrow_table .num_rows == row_limit
1030+ ), f"Expected { row_limit } rows, got { arrow_table .num_rows } "
1031+
1032+ @skipUnless (pysql_supports_arrow (), "arrow test needs arrow support" )
1033+ def test_row_limit_with_arrow_smaller_result (self ):
1034+ """Test that row_limit doesn't affect arrow results when query returns fewer rows than limit"""
1035+ row_limit = 200
1036+ expected_rows = 100
1037+ with self .cursor (extra_cursor_params = {"row_limit" : row_limit }) as cursor :
1038+ # Execute a query that returns fewer than row_limit rows
1039+ cursor .execute (f"SELECT * FROM range({ expected_rows } )" )
1040+ arrow_table = cursor .fetchall_arrow ()
1041+
1042+ # Check if all rows are returned (not limited by row_limit)
1043+ assert (
1044+ arrow_table .num_rows == expected_rows
1045+ ), f"Expected { expected_rows } rows, got { arrow_table .num_rows } "
1046+
9911047
9921048# use a RetrySuite to encapsulate these tests which we'll typically want to run together; however keep
9931049# the 429/503 subsuites separate since they execute under different circumstances.
0 commit comments