From d2aedcfc6aa2db39d9c00f2f7ba49ebaafb434d5 Mon Sep 17 00:00:00 2001 From: HenryNebula <22852427+HenryNebula@users.noreply.github.com> Date: Fri, 24 Apr 2026 02:09:45 -0400 Subject: [PATCH] Verify ARRAY type handling: add mock and integration tests (legacy #159) JDBC ARRAY columns are handled via ExplicitTypeMapper's VARCHAR fallback (toString representation). Add mock driver ARRAY support and regression tests to verify this degraded path works correctly. Co-Authored-By: Claude Opus 4.6 --- .../jaydebeapi/mockdriver/MockConnection.java | 6 ++++++ test/test_integration.py | 18 ++++++++++++++++++ test/test_mock.py | 13 ++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/mockdriver/src/main/java/org/jaydebeapi/mockdriver/MockConnection.java b/mockdriver/src/main/java/org/jaydebeapi/mockdriver/MockConnection.java index 2468344a..6cf0d8f9 100644 --- a/mockdriver/src/main/java/org/jaydebeapi/mockdriver/MockConnection.java +++ b/mockdriver/src/main/java/org/jaydebeapi/mockdriver/MockConnection.java @@ -360,6 +360,12 @@ public final void mockType(String sqlTypesName) throws SQLException { Mockito.when(mockResultSet.getObject(1, LocalDateTime.class)).thenReturn(localDateTime); Mockito.when(mockResultSet.getTimestamp(1)).thenReturn(timestamp); break; + case Types.ARRAY: + // ExplicitTypeMapper remaps ARRAY to VARCHAR (toString fallback). + // Mock getString() so the Arrow adapter can read the degraded value. + object = "{1,2,3}"; + Mockito.when(mockResultSet.getString(1)).thenReturn((String) object); + break; default: object = "DummyObject"; break; diff --git a/test/test_integration.py b/test/test_integration.py index c9242f0d..dc6640b7 100644 --- a/test/test_integration.py +++ b/test/test_integration.py @@ -1227,6 +1227,24 @@ def test_execute_timestamptz_roundtrip_param_binding(self): self.assertEqual(result[1], datetime(2024, 6, 15, 10, 30, 0, tzinfo=timezone.utc)) self.assertIsNotNone(result[1].tzinfo) + def test_array_column_read(self): + """Verify ARRAY columns are readable as strings via ExplicitTypeMapper + VARCHAR fallback. Regression test for legacy issue baztian/jaydebeapi#159.""" + with self.conn.cursor() as cursor: + cursor.execute("CREATE TABLE test_array_type (id INT, data INTEGER ARRAY)") + try: + cursor.execute( + "INSERT INTO test_array_type (id, data) VALUES (1, ARRAY[1,2,3])" + ) + cursor.execute("SELECT data FROM test_array_type WHERE id = 1") + result = cursor.fetchone() + # Verify data is readable (degraded VARCHAR fallback — toString representation) + self.assertIsInstance(result[0], str) + # Verify cursor.description reports ARRAY type code + self.assertIs(cursor.description[0][1], jaydebeapiarrow.ARRAY) + finally: + cursor.execute("DROP TABLE test_array_type") + class MySQLTest(IntegrationTestBase, unittest.TestCase): diff --git a/test/test_mock.py b/test/test_mock.py index c45843d4..b6b7ff92 100644 --- a/test/test_mock.py +++ b/test/test_mock.py @@ -41,7 +41,7 @@ def tearDown(self): self.conn.close() # JDBC types not supported by the Arrow data path (no Arrow type mapping) - _ARROW_UNSUPPORTED_TYPES = {'OTHER', 'NCLOB', 'SQLXML', 'ROWID', 'ARRAY', + _ARROW_UNSUPPORTED_TYPES = {'OTHER', 'NCLOB', 'SQLXML', 'ROWID', 'TIME_WITH_TIMEZONE', 'TIMESTAMP_WITH_TIMEZONE'} def test_all_db_api_type_objects_have_valid_mapping(self): @@ -756,6 +756,17 @@ def test_binary_empty(self): result = cursor.fetchone() self.assertEqual(result[0], b'') + # --- ARRAY type tests (legacy issue #159) --- + + def test_array_column_returns_string_via_varchar_fallback(self): + """ARRAY columns are degraded to VARCHAR by ExplicitTypeMapper and + returned as Python strings (toString representation).""" + self.conn.jconn.mockType("ARRAY") + with self.conn.cursor() as cursor: + cursor.execute("dummy stmt") + result = cursor.fetchone() + self.assertIsInstance(result[0], str) + # --- DBAPITypeObject mapping tests --- def test_description_returns_column_label_not_name(self):