From 46f9f85b56dfc7ab12bd44db92e9b082ee960bdd Mon Sep 17 00:00:00 2001 From: David Li Date: Tue, 14 Jan 2025 19:47:31 -0500 Subject: [PATCH] fix(c/driver/postgresql): return unknown OIDs as opaque Fixes #2448. --- c/driver/postgresql/postgresql_test.cc | 23 +++++++++++++++++++++++ c/driver/postgresql/result_helper.cc | 9 ++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/c/driver/postgresql/postgresql_test.cc b/c/driver/postgresql/postgresql_test.cc index b76ba1cf7d..dbdb7418c0 100644 --- a/c/driver/postgresql/postgresql_test.cc +++ b/c/driver/postgresql/postgresql_test.cc @@ -1696,6 +1696,29 @@ TEST_F(PostgresStatementTest, SetUseCopyFalse) { ASSERT_EQ(reader.array->release, nullptr); } +TEST_F(PostgresStatementTest, UnknownOid) { + // Regression test for https://github.com/apache/arrow-adbc/issues/2448 + ASSERT_THAT(AdbcStatementNew(&connection, &statement, &error), IsOkStatus(&error)); + ASSERT_THAT(AdbcStatementSetSqlQuery( + &statement, "SELECT typacl FROM pg_type WHERE oid <= 6157", &error), + IsOkStatus(&error)); + adbc_validation::StreamReader reader; + ASSERT_THAT(AdbcStatementExecuteQuery(&statement, &reader.stream.value, + &reader.rows_affected, &error), + IsOkStatus(&error)); + ASSERT_NO_FATAL_FAILURE(reader.GetSchema()); + ASSERT_EQ(1, reader.fields.size()); + ASSERT_EQ(NANOARROW_TYPE_BINARY, reader.fields[0].type); + struct ArrowStringView extension_name = reader.fields[0].extension_name; + ASSERT_EQ("arrow.opaque", + std::string_view(extension_name.data, + static_cast(extension_name.size_bytes))); + struct ArrowStringView extension_metadata = reader.fields[0].extension_metadata; + ASSERT_EQ(R"({"type_name": "unnamed", "vendor_name": "PostgreSQL"})", + std::string_view(extension_metadata.data, + static_cast(extension_metadata.size_bytes))); +} + struct TypeTestCase { std::string name; std::string sql_type; diff --git a/c/driver/postgresql/result_helper.cc b/c/driver/postgresql/result_helper.cc index 48c6804883..bc2fbad2d3 100644 --- a/c/driver/postgresql/result_helper.cc +++ b/c/driver/postgresql/result_helper.cc @@ -167,11 +167,10 @@ Status PqResultHelper::ResolveOutputTypes(PostgresTypeResolver& type_resolver, const Oid pg_oid = PQftype(result_, i); PostgresType pg_type; if (type_resolver.Find(pg_oid, &pg_type, &na_error) != NANOARROW_OK) { - Status status = - Status::NotImplemented("[libpq] Column #", i + 1, " (\"", PQfname(result_, i), - "\") has unknown type code ", pg_oid); - ClearResult(); - return status; + // We couldn't look up the OID. + // TODO(apache/arrow-adbc#1243): issue a warning (maybe reloading the + // connection will load the OIDs if it was a newly created type) + pg_type = PostgresType::Unnamed(pg_oid); } root_type.AppendChild(PQfname(result_, i), pg_type);