You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "justing-bq (via GitHub)" <gi...@apache.org> on 2026/04/17 19:57:13 UTC

[PR] GH-49783: [C++][FlightRPC][ODBC] Reuse connections across test suite [arrow]

justing-bq opened a new pull request, #49784:
URL: https://github.com/apache/arrow/pull/49784

   ### Rationale for this change
   We avoid crashing tests on Linux if we minimize the number of connect/disconnect attempts. So now we are reusing the same connection as much as possible throughout the tests.
   
   ### What changes are included in this PR?
   All our necessary connections happen during global `SetUp()` and then they get disconnected during global `TearDown()`.
   Test Fixture SetUp logic is now about updating pointers to the correct environment, connection, and statement handles for those tests.
   
   ### Are these changes tested?
   Yes.
   
   ### Are there any user-facing changes?
   No.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49783: [C++][FlightRPC][ODBC] Reuse connections across test suite [arrow]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #49784:
URL: https://github.com/apache/arrow/pull/49784#discussion_r3105065219


##########
cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt:
##########
@@ -42,6 +42,11 @@ set(ARROW_FLIGHT_SQL_ODBC_TEST_SRCS
     # GH-46889: move protobuf_test_util to a more common location
     ../../../../engine/substrait/protobuf_test_util.cc)
 
+# Resolve segmentation fault error on Windows platform due to Arrow Compute Library Initialization
+if(WIN32)
+  list(APPEND ARROW_FLIGHT_SQL_ODBC_TEST_SRCS ../../../../compute/test_env.cc)
+endif()

Review Comment:
   Adding `../../../../compute/test_env.cc` introduces a second `main()` (see `cpp/src/arrow/compute/test_env.cc`), which will likely cause a linker error (multiple definition of `main`) or unintentionally override the test runner entrypoint on Windows. Instead, initialize Arrow Compute from an existing global test environment (e.g., call `arrow::compute::Initialize()` inside `OdbcTestEnvironment::SetUp()` under `#ifdef _WIN32`) or add a small helper source that registers the compute environment but does not define `main()`.
   ```suggestion
   # Do not add ../../../../compute/test_env.cc here: it defines its own main(),
   # which would conflict with this test target's runner on Windows. Any Arrow
   # Compute initialization must be performed from the existing ODBC test
   # environment or from a helper source that does not define main().
   ```



##########
cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.h:
##########
@@ -41,12 +41,26 @@
 static constexpr std::string_view kTestConnectStr = "ARROW_FLIGHT_SQL_ODBC_CONN";
 static constexpr std::string_view kTestDsn = "Apache Arrow Flight SQL Test DSN";
 
-inline SQLHENV env = 0;
-inline SQLHDBC conn = 0;
-inline SQLHSTMT stmt = 0;
+inline std::string remote_test_connect_str = "";
 
-inline bool skipping_test = false;
-inline bool connected = false;
+struct OdbcHandles {
+  SQLHENV env = SQL_NULL_HENV;
+  SQLHDBC conn = SQL_NULL_HDBC;
+  SQLHSTMT stmt = SQL_NULL_HSTMT;
+};
+
+inline OdbcHandles remote_odbcv3_handles;
+inline OdbcHandles remote_odbcv2_handles;
+inline OdbcHandles remote_non_connection_handles;
+inline OdbcHandles mock_odbcv3_handles;
+inline OdbcHandles mock_odbcv2_handles;
+inline OdbcHandles mock_non_connection_handles;
+
+// These handles are meant to point to to the relevant handle above

Review Comment:
   Typo in comment: "point to to" -> "point to".
   ```suggestion
   // These handles are meant to point to the relevant handle above
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49783: [C++][FlightRPC][ODBC] Reuse connections across test suite [arrow]

Posted by "alinaliBQ (via GitHub)" <gi...@apache.org>.
alinaliBQ commented on code in PR #49784:
URL: https://github.com/apache/arrow/pull/49784#discussion_r3113561427


##########
cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt:
##########
@@ -42,6 +42,11 @@ set(ARROW_FLIGHT_SQL_ODBC_TEST_SRCS
     # GH-46889: move protobuf_test_util to a more common location
     ../../../../engine/substrait/protobuf_test_util.cc)
 
+# Resolve segmentation fault error on Windows platform due to Arrow Compute Library Initialization
+if(WIN32)
+  list(APPEND ARROW_FLIGHT_SQL_ODBC_TEST_SRCS ../../../../compute/test_env.cc)
+endif()

Review Comment:
   @lidavidm Is it ok if we only apply `ASSERT_OK(arrow::compute::Initialize());` to Windows (where the crash occurs)? On macOS and Linux, it would be better to test the ODBC driver's behavior of compute call initialization in the tests where possible.
   cc @justing-bq 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49783: [C++][FlightRPC][ODBC] Reuse connections across test suite [arrow]

Posted by "alinaliBQ (via GitHub)" <gi...@apache.org>.
alinaliBQ commented on PR #49784:
URL: https://github.com/apache/arrow/pull/49784#issuecomment-4284179029

   Could we resolve the merge conflict?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49783: [C++][FlightRPC][ODBC] Reuse connections across test suite [arrow]

Posted by "justing-bq (via GitHub)" <gi...@apache.org>.
justing-bq commented on code in PR #49784:
URL: https://github.com/apache/arrow/pull/49784#discussion_r3120217503


##########
cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.h:
##########


Review Comment:
   We still need some of these handles to be defined globally because we want the connections to persist across the entire test suite rather than belonging to a test fixture. However each test fixture now has its own pointers to these handles and the tests reference these pointers only.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49783: [C++][FlightRPC][ODBC] Reuse connections across test suite [arrow]

Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #49784:
URL: https://github.com/apache/arrow/pull/49784#issuecomment-4495202121

   After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 95b514f7ce29b99254fc38a63060b48049caf1c7.
   
   There were no benchmark performance regressions. 🎉
   
   The [full Conbench report](https://github.com/apache/arrow/runs/76899276695) has more details. It also includes information about 8 possible false positives for unstable benchmarks that are known to sometimes produce them.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49783: [C++][FlightRPC][ODBC] Reuse connections across test suite [arrow]

Posted by "justing-bq (via GitHub)" <gi...@apache.org>.
justing-bq commented on PR #49784:
URL: https://github.com/apache/arrow/pull/49784#issuecomment-4492499203

   @lidavidm @kou
   Please take a look when you have time.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49783: [C++][FlightRPC][ODBC] Reuse connections across test suite [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #49784:
URL: https://github.com/apache/arrow/pull/49784#issuecomment-4270864600

   :warning: GitHub issue #49783 **has been automatically assigned in GitHub** to PR creator.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49783: [C++][FlightRPC][ODBC] Reuse connections across test suite [arrow]

Posted by "alinaliBQ (via GitHub)" <gi...@apache.org>.
alinaliBQ commented on PR #49784:
URL: https://github.com/apache/arrow/pull/49784#issuecomment-4284146686

   > Is there an issue for tracking down the cause of the crash?
   
   We have an issue here: https://github.com/apache/arrow/issues/48270


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49783: [C++][FlightRPC][ODBC] Reuse connections across test suite [arrow]

Posted by "justing-bq (via GitHub)" <gi...@apache.org>.
justing-bq commented on PR #49784:
URL: https://github.com/apache/arrow/pull/49784#issuecomment-4270947606

   @lidavidm @kou
   Please take a look when you have a chance.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49783: [C++][FlightRPC][ODBC] Reuse connections across test suite [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou merged PR #49784:
URL: https://github.com/apache/arrow/pull/49784


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49783: [C++][FlightRPC][ODBC] Reuse connections across test suite [arrow]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #49784:
URL: https://github.com/apache/arrow/pull/49784#discussion_r3150968996


##########
cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.h:
##########
@@ -41,12 +41,18 @@
 static constexpr std::string_view kTestConnectStr = "ARROW_FLIGHT_SQL_ODBC_CONN";
 static constexpr std::string_view kTestDsn = "Apache Arrow Flight SQL Test DSN";
 
-inline SQLHENV env = 0;
-inline SQLHDBC conn = 0;
-inline SQLHSTMT stmt = 0;
+inline std::string remote_test_connect_str = "";
 
-inline bool skipping_test = false;
-inline bool connected = false;
+struct OdbcHandles {
+  SQLHENV env = SQL_NULL_HENV;
+  SQLHDBC conn = SQL_NULL_HDBC;
+  SQLHSTMT stmt = SQL_NULL_HSTMT;
+};
+
+inline OdbcHandles remote_odbcv3_handles;
+inline OdbcHandles remote_odbcv2_handles;
+inline OdbcHandles mock_odbcv3_handles;
+inline OdbcHandles mock_odbcv2_handles;

Review Comment:
   `OdbcHandles` includes a `stmt` field, but it is never initialized anywhere (connections are established in `OdbcTestEnvironment`, while statements are allocated per-test in `ODBCTestBase::SetUp()`). Keeping an always-null `stmt` in the shared handle bundle is misleading; consider removing it (and the related assignments) or populating it explicitly if you intend to reuse a single statement handle too.



##########
cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.h:
##########
@@ -61,17 +67,19 @@ namespace arrow::flight::sql::odbc {
 class ODBCTestBase : public ::testing::Test {
  public:
   /// \brief Allocate environment and connection handles
-  static void AllocEnvConnHandles(SQLINTEGER odbc_ver = SQL_OV_ODBC3);
+  static void AllocEnvConnHandles(SQLHENV& env_handle, SQLHDBC& conn_handle,
+                                  SQLINTEGER odbc_ver = SQL_OV_ODBC3);
   /// \brief Free environment and connection handles
-  static void FreeEnvConnHandles();
+  static void FreeEnvConnHandles(SQLHENV& env_handle, SQLHDBC& conn_handle);
   /// \brief Connect to Arrow Flight SQL server using connection string defined in
   /// environment variable "ARROW_FLIGHT_SQL_ODBC_CONN", allocate statement handle.
   /// Connects using ODBC Ver 3 by default
-  static void Connect(std::string connect_str, SQLINTEGER odbc_ver = SQL_OV_ODBC3);
+  static void Connect(std::string connect_str, SQLHENV& env_handle, SQLHDBC& conn_handle,
+                      SQLINTEGER odbc_ver = SQL_OV_ODBC3);
   /// \brief Connect to Arrow Flight SQL server using connection string

Review Comment:
   The doc comment for `Connect` says it allocates a statement handle, but the updated signature only sets up env/conn and `ConnectWithString` only calls `SQLDriverConnect`. Update the comment (and/or function name/docs) to reflect that statement handles are allocated per-test in `ODBCTestBase::SetUp()` now.



##########
cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.cc:
##########
@@ -400,20 +445,24 @@ void ODBCMockTestBase::DropUnicodeTable() {
 }
 
 void FlightSQLODBCMockTestBase::SetUpTestSuite() {
-  std::string connect_str = GetConnectionString();
-  Connect(connect_str, SQL_OV_ODBC3);
-  connected = true;
+  env = mock_odbcv3_handles.env;
+  conn = mock_odbcv3_handles.conn;
+  stmt = mock_odbcv3_handles.stmt;
 }

Review Comment:
   `mock_odbcv3_handles.stmt` is never set (statements are allocated in `ODBCTestBase::SetUp()`), so assigning `stmt = mock_odbcv3_handles.stmt` is redundant/misleading. Consider dropping the `stmt` assignment here (and the `stmt` field from `OdbcHandles`) so the reuse model is clearly env/conn-only.



##########
cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.cc:
##########
@@ -168,68 +228,53 @@ std::wstring ODBCTestBase::GetQueryAllDataTypes() {
 }
 
 void ODBCTestBase::SetUp() {
-  if (connected) {
-    ASSERT_EQ(SQL_SUCCESS, SQLAllocHandle(SQL_HANDLE_STMT, conn, &stmt));
-  }
+  ASSERT_EQ(SQL_SUCCESS, SQLAllocHandle(SQL_HANDLE_STMT, conn, &stmt));
 }
 
 void ODBCTestBase::TearDown() {
-  if (connected) {
-    ASSERT_EQ(SQL_SUCCESS, SQLFreeHandle(SQL_HANDLE_STMT, stmt));
-  }
-}
-
-void ODBCTestBase::TearDownTestSuite() {
-  if (connected) {
-    Disconnect();
-    connected = false;
-  }
-}
-
-void FlightSQLODBCRemoteTestBase::CheckForRemoteTest() {
-  if (arrow::internal::GetEnvVar(kTestConnectStr.data()).ValueOr("").empty()) {
-    skipping_test = true;
-    GTEST_SKIP() << "Skipping test: kTestConnectStr not set";
-  }
+  ASSERT_EQ(SQL_SUCCESS, SQLFreeHandle(SQL_HANDLE_STMT, stmt));
 }
 
 void FlightSQLODBCRemoteTestBase::SetUpTestSuite() {
-  CheckForRemoteTest();
-  if (skipping_test) {
+  if (!RunningRemoteTests()) {
+    GTEST_SKIP() << "Skipping Test Suite: Environment Variable " << kTestConnectStr.data()
+                 << " is not set";
     return;
   }
 
-  std::string connect_str = GetConnectionString();
-  Connect(connect_str, SQL_OV_ODBC3);
-  connected = true;
+  env = remote_odbcv3_handles.env;
+  conn = remote_odbcv3_handles.conn;
+  stmt = remote_odbcv3_handles.stmt;
 }

Review Comment:
   `remote_odbcv3_handles.stmt` is never set (statements are allocated in `ODBCTestBase::SetUp()`), so assigning `stmt = remote_odbcv3_handles.stmt` just forces `ODBCTestBase::stmt` to `SQL_NULL_HSTMT` at suite setup. Consider removing the `stmt` assignment here (and the `stmt` field from `OdbcHandles`) to avoid confusion about what is actually being reused.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49783: [C++][FlightRPC][ODBC] Reuse connections across test suite [arrow]

Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on code in PR #49784:
URL: https://github.com/apache/arrow/pull/49784#discussion_r3107669091


##########
cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.h:
##########


Review Comment:
   Instead of globals, could we keep them as fields on the test fixture? Those would still be accessible by tests



##########
cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt:
##########
@@ -42,6 +42,11 @@ set(ARROW_FLIGHT_SQL_ODBC_TEST_SRCS
     # GH-46889: move protobuf_test_util to a more common location
     ../../../../engine/substrait/protobuf_test_util.cc)
 
+# Resolve segmentation fault error on Windows platform due to Arrow Compute Library Initialization
+if(WIN32)
+  list(APPEND ARROW_FLIGHT_SQL_ODBC_TEST_SRCS ../../../../compute/test_env.cc)
+endif()

Review Comment:
   If this is needed, I'd rather we copy `ASSERT_OK(arrow::compute::Initialize());` to our own googletest environment



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49783: [C++][FlightRPC][ODBC] Reuse connections across test suite [arrow]

Posted by "justing-bq (via GitHub)" <gi...@apache.org>.
justing-bq commented on code in PR #49784:
URL: https://github.com/apache/arrow/pull/49784#discussion_r3120217503


##########
cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.h:
##########


Review Comment:
   We still need some of these handles to be defined globally because we want the connections to persist across the entire test suite rather than belonging to a test fixture. However each test fixture has its own pointers to these handles and the tests reference these pointers only.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49783: [C++][FlightRPC][ODBC] Reuse connections across test suite [arrow]

Posted by "justing-bq (via GitHub)" <gi...@apache.org>.
justing-bq commented on PR #49784:
URL: https://github.com/apache/arrow/pull/49784#issuecomment-4309441673

   @lidavidm @kou
   Please take a look when you have time.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org