@@ -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
@@ -943,6 +945,60 @@ def test_catalogs_returns_arrow_table(self):
943945 results = cursor .fetchall_arrow ()
944946 assert isinstance (results , pyarrow .Table )
945947
948+ def test_row_limit_with_larger_result (self ):
949+ """Test that row_limit properly constrains results when query would return more rows"""
950+ row_limit = 1000
951+ with self .cursor (extra_cursor_params = {"row_limit" : row_limit }) as cursor :
952+ # Execute a query that returns more than row_limit rows
953+ cursor .execute ("SELECT * FROM range(2000)" )
954+ rows = cursor .fetchall ()
955+
956+ # Check if the number of rows is limited to row_limit
957+ assert len (rows ) == row_limit , f"Expected { row_limit } rows, got { len (rows )} "
958+
959+ def test_row_limit_with_smaller_result (self ):
960+ """Test that row_limit doesn't affect results when query returns fewer rows than limit"""
961+ row_limit = 100
962+ expected_rows = 50
963+ with self .cursor (extra_cursor_params = {"row_limit" : row_limit }) as cursor :
964+ # Execute a query that returns fewer than row_limit rows
965+ cursor .execute (f"SELECT * FROM range({ expected_rows } )" )
966+ rows = cursor .fetchall ()
967+
968+ # Check if all rows are returned (not limited by row_limit)
969+ assert (
970+ len (rows ) == expected_rows
971+ ), f"Expected { expected_rows } rows, got { len (rows )} "
972+
973+ @skipUnless (pysql_supports_arrow (), "arrow test needs arrow support" )
974+ def test_row_limit_with_arrow_larger_result (self ):
975+ """Test that row_limit properly constrains arrow results when query would return more rows"""
976+ row_limit = 800
977+ with self .cursor (extra_cursor_params = {"row_limit" : row_limit }) as cursor :
978+ # Execute a query that returns more than row_limit rows
979+ cursor .execute ("SELECT * FROM range(1500)" )
980+ arrow_table = cursor .fetchall_arrow ()
981+
982+ # Check if the number of rows in the arrow table is limited to row_limit
983+ assert (
984+ arrow_table .num_rows == row_limit
985+ ), f"Expected { row_limit } rows, got { arrow_table .num_rows } "
986+
987+ @skipUnless (pysql_supports_arrow (), "arrow test needs arrow support" )
988+ def test_row_limit_with_arrow_smaller_result (self ):
989+ """Test that row_limit doesn't affect arrow results when query returns fewer rows than limit"""
990+ row_limit = 200
991+ expected_rows = 100
992+ with self .cursor (extra_cursor_params = {"row_limit" : row_limit }) as cursor :
993+ # Execute a query that returns fewer than row_limit rows
994+ cursor .execute (f"SELECT * FROM range({ expected_rows } )" )
995+ arrow_table = cursor .fetchall_arrow ()
996+
997+ # Check if all rows are returned (not limited by row_limit)
998+ assert (
999+ arrow_table .num_rows == expected_rows
1000+ ), f"Expected { expected_rows } rows, got { arrow_table .num_rows } "
1001+
9461002
9471003# use a RetrySuite to encapsulate these tests which we'll typically want to run together; however keep
9481004# the 429/503 subsuites separate since they execute under different circumstances.
0 commit comments