Skip to content

Commit d74546b

Browse files
Add test for tab and newline characters in S3FS cursor result data
Test that the S3FS cursor correctly handles data containing tab and newline characters, which are special characters in CSV/TSV parsing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e320183 commit d74546b

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

tests/pyathena/s3fs/test_cursor.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,39 @@ def callback(query_id):
275275
):
276276
cursor.execute("SELECT * FROM one_row", on_start_query_execution=callback)
277277
assert callback_query_id == cursor.query_id
278+
279+
def test_contain_tab_character(self, s3fs_cursor):
280+
"""Test that tab characters in result data are handled correctly.
281+
282+
S3FS cursor uses tab as delimiter for parsing Athena's CSV output.
283+
This test verifies that data containing tab characters is correctly
284+
parsed when Athena properly quotes such fields.
285+
"""
286+
# Test with tab character in string using CHR(9)
287+
s3fs_cursor.execute("SELECT 'before' || CHR(9) || 'after' AS col_with_tab")
288+
result = s3fs_cursor.fetchone()
289+
assert result == ("before\tafter",)
290+
291+
# Test with multiple columns where one contains tab
292+
s3fs_cursor.execute(
293+
"""
294+
SELECT
295+
'normal' AS col1,
296+
'has' || CHR(9) || 'tab' AS col2,
297+
'also_normal' AS col3
298+
"""
299+
)
300+
result = s3fs_cursor.fetchone()
301+
assert result == ("normal", "has\ttab", "also_normal")
302+
303+
# Test with newline character as well
304+
s3fs_cursor.execute("SELECT 'line1' || CHR(10) || 'line2' AS col_with_newline")
305+
result = s3fs_cursor.fetchone()
306+
assert result == ("line1\nline2",)
307+
308+
# Test with both tab and newline
309+
s3fs_cursor.execute(
310+
"SELECT 'a' || CHR(9) || 'b' || CHR(10) || 'c' AS col_with_special_chars"
311+
)
312+
result = s3fs_cursor.fetchone()
313+
assert result == ("a\tb\nc",)

0 commit comments

Comments
 (0)