Skip to content

Commit 92f434f

Browse files
committed
Code Clean up and enable ODBC tests in CI
Still need to modify ODBCUtilEnvironment if we decide to use it. Still need to add ODBC V2 support so a different env and conn is used for ODBC 2 tests.
1 parent dcfa218 commit 92f434f

File tree

6 files changed

+21
-55
lines changed

6 files changed

+21
-55
lines changed

.github/workflows/cpp_windows.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,3 @@ jobs:
164164
for /f "usebackq delims=" %%I in (`bash -c "cygpath -u \"$VCPKG_ROOT_KEEP\""` ) do set VCPKG_ROOT=%%I
165165
166166
bash -c "ci/scripts/cpp_test.sh $(pwd) $(pwd)/build"
167-
168-
# Run ODBC test
169-
${{ github.workspace }}\build\cpp\%ARROW_BUILD_TYPE%\arrow-flight-sql-odbc-test.exe
170-

ci/scripts/cpp_test.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ case "$(uname)" in
8282
exclude_tests+=("gandiva-precompiled-test")
8383
exclude_tests+=("gandiva-projector-test")
8484
exclude_tests+=("gandiva-utf8-test")
85-
exclude_tests+=("arrow-flight-sql-odbc-test")
8685
;;
8786
*)
8887
n_jobs=${NPROC:-1}

cpp/src/arrow/compute/registry.cc

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,14 @@
3030
#include "arrow/util/config.h" // For ARROW_COMPUTE
3131
#include "arrow/util/logging.h"
3232

33-
#include <iostream> // -AL- TEMP remove later
34-
3533
namespace arrow {
3634
namespace compute {
3735

3836
class FunctionRegistry::FunctionRegistryImpl {
3937
public:
4038
explicit FunctionRegistryImpl(FunctionRegistryImpl* parent = NULLPTR)
41-
: parent_(parent) {// -AL- TEMP remove later
42-
std::cout << "-AL- FunctionRegistryImpl constructor called\n";
43-
}
44-
~FunctionRegistryImpl() { // -AL- TEMP remove later
45-
size_t name_size = name_to_function_.size();
46-
std::cout << "-AL- ~FunctionRegistryImpl name_to_function_ size:" << name_size <<
47-
"\n";
48-
49-
//auto it = name_to_function_.find(std::string("split_pattern"));
50-
//auto func = it->second;
51-
//for (auto& kv : name_to_function_) {
52-
// kv.second.reset();
53-
//}
54-
//name_to_function_.clear();
55-
56-
std::cout << "-AL- ~FunctionRegistryImpl destructor called\n";
57-
}
39+
: parent_(parent) {}
40+
~FunctionRegistryImpl() {}
5841

5942
Status CanAddFunction(std::shared_ptr<Function> function, bool allow_overwrite) {
6043
if (parent_ != NULLPTR) {
@@ -144,8 +127,7 @@ class FunctionRegistry::FunctionRegistryImpl {
144127

145128
const Function* cast_function() { return cast_function_; }
146129

147-
void ClearFunctioRegistry() { name_to_function_.clear();
148-
}
130+
void ClearFunctioRegistry() { name_to_function_.clear(); }
149131

150132
private:
151133
// must not acquire mutex
@@ -235,7 +217,6 @@ class FunctionRegistry::FunctionRegistryImpl {
235217
};
236218

237219
std::unique_ptr<FunctionRegistry> FunctionRegistry::Make() {
238-
std::cout << "-AL- Make is called once TEMP \n";
239220
return std::unique_ptr<FunctionRegistry>(new FunctionRegistry());
240221
}
241222

@@ -298,14 +279,11 @@ int FunctionRegistry::num_functions() const { return impl_->num_functions(); }
298279

299280
const Function* FunctionRegistry::cast_function() const { return impl_->cast_function(); }
300281

301-
void FunctionRegistry::ClearFunctioRegistry() {
302-
impl_->ClearFunctioRegistry();
303-
}
282+
void FunctionRegistry::ClearFunctioRegistry() { impl_->ClearFunctioRegistry(); }
304283

305284
namespace internal {
306285

307286
static std::unique_ptr<FunctionRegistry> CreateBuiltInRegistry() {
308-
std::cout << "-AL- CreateBuiltInRegistry is called once TEMP \n";
309287
auto registry = FunctionRegistry::Make();
310288

311289
// Register core kernels

cpp/src/arrow/compute/registry.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ class ARROW_EXPORT FunctionRegistry {
111111
///
112112
/// Helpful for get cast function as needed.
113113
const Function* cast_function() const;
114-
115-
// -AL- todo docs?
114+
115+
/// \brief Clear function registry
116+
///
117+
/// Helpful to avoid segfault from race condition. Call this function before DLL unload.
116118
void ClearFunctioRegistry();
117119

118120
private:

cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.cc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@
2929

3030
namespace arrow::flight::sql::odbc {
3131

32-
// -AL- todo rename later
33-
auto alinatest_env = ::testing::AddGlobalTestEnvironment(new AlinaTestEnvironment);
32+
auto odbc_util_env = ::testing::AddGlobalTestEnvironment(new OdbcUtilEnvironment);
3433

35-
AlinaTestEnvironment* GetAlinaTestEnv() {
36-
return ::arrow::internal::checked_cast<AlinaTestEnvironment*>(alinatest_env);
34+
OdbcUtilEnvironment* GetOdbcUtilEnv() {
35+
return ::arrow::internal::checked_cast<OdbcUtilEnvironment*>(odbc_util_env);
3736
}
3837

3938
void ODBCRemoteTestBase::AllocEnvConnHandles(SQLINTEGER odbc_ver) {
@@ -63,15 +62,15 @@ void ODBCRemoteTestBase::ConnectWithString(std::string connect_str) {
6362
SQLSMALLINT out_str_len;
6463

6564
// -AL- once local conn handles are removed,can rename back to conn
66-
SQLHDBC global_conn = GetAlinaTestEnv()->getConnHandle();
67-
//SQLHDBC global_conn = conn; //-AL- TEMP
65+
SQLHDBC global_conn = GetOdbcUtilEnv()->getConnHandle();
66+
// SQLHDBC global_conn = conn; //-AL- TEMP
6867

6968
// Connecting to ODBC server.
7069
ASSERT_EQ(SQL_SUCCESS,
7170
SQLDriverConnect(global_conn, NULL, &connect_str0[0],
7271
static_cast<SQLSMALLINT>(connect_str0.size()), out_str,
7372
kOdbcBufferSize, &out_str_len, SQL_DRIVER_NOPROMPT))
74-
<< GetOdbcErrorMessage(SQL_HANDLE_DBC, global_conn);
73+
<< GetOdbcErrorMessage(SQL_HANDLE_DBC, global_conn);
7574

7675
// GH-47710: TODO Allocate a statement using alloc handle
7776
// ASSERT_EQ(SQL_SUCCESS, SQLAllocHandle(SQL_HANDLE_STMT, conn, &stmt));
@@ -81,8 +80,8 @@ void ODBCRemoteTestBase::Disconnect() {
8180
// GH-47710: TODO Close statement
8281
// EXPECT_EQ(SQL_SUCCESS, SQLFreeHandle(SQL_HANDLE_STMT, stmt));
8382

84-
// -AL- once local conn handles are removed,can rename back to conn
85-
SQLHDBC global_conn = GetAlinaTestEnv()->getConnHandle();
83+
// -AL- once local conn handles are removed,can rename back to conn
84+
SQLHDBC global_conn = GetOdbcUtilEnv()->getConnHandle();
8685

8786
// Disconnect from ODBC
8887
EXPECT_EQ(SQL_SUCCESS, SQLDisconnect(global_conn))

cpp/src/arrow/flight/sql/odbc/tests/odbc_test_util.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include "arrow/flight/sql/odbc/odbc_impl/platform.h"
2121

22-
#include "arrow/compute/api.h" // -AL- attempt to keep registry alive
22+
#include "arrow/compute/api.h"
2323

2424
#include <sql.h>
2525
#include <sqlucode.h>
@@ -29,10 +29,9 @@
2929
namespace arrow::flight::sql::odbc {
3030

3131
// -AL- todo update to actual ODBC allocation
32-
class AlinaTestEnvironment : public ::testing::Environment {
32+
class OdbcUtilEnvironment : public ::testing::Environment {
3333
public:
3434
void SetUp() override {
35-
int x = 1;
3635
// -AL- todo add env_v2 for v2 after global setup/teardown works.
3736

3837
// Allocate an environment handle
@@ -45,27 +44,20 @@ class AlinaTestEnvironment : public ::testing::Environment {
4544

4645
// Allocate a connection using alloc handle
4746
ASSERT_EQ(SQL_SUCCESS, SQLAllocHandle(SQL_HANDLE_DBC, env, &conn));
48-
std::cout << "-AL- AlinaTestEnvironment::SetUp\n";
47+
std::cout << "-AL- OdbcUtilEnvironment::SetUp\n";
4948
}
5049

5150
void TearDown() override {
52-
53-
54-
// -AL- this doesn't work
55-
//// Remove function registry before test exits
51+
// Clear function registry before test exits
5652
auto reg = arrow::compute::GetFunctionRegistry();
5753
reg->ClearFunctioRegistry();
58-
// delete reg;
5954

60-
61-
int y = 1;
6255
// Free connection handle
6356
EXPECT_EQ(SQL_SUCCESS, SQLFreeHandle(SQL_HANDLE_DBC, conn));
6457

6558
// Free environment handle
6659
EXPECT_EQ(SQL_SUCCESS, SQLFreeHandle(SQL_HANDLE_ENV, env));
67-
std::cout << "-AL- AlinaTestEnvironment::TearDown\n";
68-
60+
std::cout << "-AL- OdbcUtilEnvironment::TearDown\n";
6961
}
7062

7163
SQLHENV getEnvHandle() { return env; }

0 commit comments

Comments
 (0)