Skip to content

Commit 98677d5

Browse files
SNOW-460809 Attempt to add INFO level logging message regarding first chunk rowcount (#1249)
* Attempt to add INFO level logging message regarding first chunk rowcount * Added test for logging results in first chunk * Moved log tests to test_insert_select, test_insert_and_select_by_separate_connection, and test_fetchmany
1 parent 0b24148 commit 98677d5

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/snowflake/connector/cursor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,11 @@ def _init_result_and_meta(self, data):
850850
self, self._query_result_format, data, self._description
851851
)
852852

853+
if not (is_dml or self.is_file_transfer):
854+
logger.info(
855+
"Number of results in first chunk: %s", result_chunks[0].rowcount
856+
)
857+
853858
self._result_set = ResultSet(
854859
self,
855860
result_chunks,

test/integ/test_cursor.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ def _check_results(cursor, results):
131131
assert results[2] == 123456, "the third result was wrong"
132132

133133

134-
def test_insert_select(conn, db_parameters):
134+
@pytest.mark.skipolddriver
135+
def test_insert_select(conn, db_parameters, caplog):
135136
"""Inserts and selects integer data."""
136137
with conn() as cnx:
137138
c = cnx.cursor()
@@ -157,20 +158,25 @@ def test_insert_select(conn, db_parameters):
157158
for rec in c:
158159
results.append(rec[0])
159160
_check_results(c, results)
161+
assert "Number of results in first chunk: 3" in caplog.text
160162
finally:
161163
c.close()
162164

163165
with cnx.cursor(snowflake.connector.DictCursor) as c:
166+
caplog.clear()
167+
assert "Number of results in first chunk: 3" not in caplog.text
164168
c.execute(
165169
"select aa from {name} order by aa".format(name=db_parameters["name"])
166170
)
167171
results = []
168172
for rec in c:
169173
results.append(rec["AA"])
170174
_check_results(c, results)
175+
assert "Number of results in first chunk: 3" in caplog.text
171176

172177

173-
def test_insert_and_select_by_separate_connection(conn, db_parameters):
178+
@pytest.mark.skipolddriver
179+
def test_insert_and_select_by_separate_connection(conn, db_parameters, caplog):
174180
"""Inserts a record and select it by a separate connection."""
175181
with conn() as cnx:
176182
result = cnx.cursor().execute(
@@ -204,6 +210,7 @@ def test_insert_and_select_by_separate_connection(conn, db_parameters):
204210
c.close()
205211
assert results[0] == 1234, "the first result was wrong"
206212
assert result.rowcount == 1, "wrong number of records were selected"
213+
assert "Number of results in first chunk: 1" in caplog.text
207214
finally:
208215
cnx2.close()
209216

@@ -752,7 +759,9 @@ def test_closed_cursor(conn, db_parameters):
752759
), "SNOW-647539: rowcount should remain available after cursor is closed"
753760

754761

755-
def test_fetchmany(conn, db_parameters):
762+
@pytest.mark.skipolddriver
763+
def test_fetchmany(conn, db_parameters, caplog):
764+
756765
table_name = random_string(5, "test_fetchmany_")
757766
with conn() as cnx:
758767
with cnx.cursor() as c:
@@ -773,6 +782,7 @@ def test_fetchmany(conn, db_parameters):
773782

774783
with cnx.cursor() as c:
775784
c.execute(f"select aa from {table_name} order by aa desc")
785+
assert "Number of results in first chunk: 6" in caplog.text
776786

777787
rows = c.fetchmany(2)
778788
assert len(rows) == 2, "The number of records"

0 commit comments

Comments
 (0)