Skip to content

Commit b5820e4

Browse files
alinaliBQzanmato1984
authored andcommitted
apacheGH-47679: [C++] Register arrow compute calls in ODBC (apache#47680)
### Rationale for this change Need to call function to register Arrow compute calls which is needed due to apache#25025 ### What changes are included in this PR? - Add calls to `arrow::compute::Initialize` - Remove `RUN_ALL_TESTS` that wasn't needed; it is no longer needed after fix of apacheGH-47434. ### Are these changes tested? - `arrow-odbc-spi-impl-test` pass locally. ### Are there any user-facing changes? No PR is extracted from PR apache#46099 * GitHub Issue: apache#47679 Authored-by: Alina (Xi) Li <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
1 parent 3620c12 commit b5820e4

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed

cpp/src/arrow/flight/sql/odbc/flight_sql/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ if(WIN32)
9999
system_dsn.cc)
100100
endif()
101101

102-
target_link_libraries(arrow_odbc_spi_impl PUBLIC odbcabstraction arrow_flight_sql_shared)
102+
target_link_libraries(arrow_odbc_spi_impl PUBLIC odbcabstraction arrow_flight_sql_shared
103+
arrow_compute_shared Boost::locale)
103104

104-
if(MSVC)
105-
target_link_libraries(arrow_odbc_spi_impl PUBLIC Boost::locale)
105+
# Link libraries on MINGW64 and macOS
106+
if(MINGW OR APPLE)
107+
target_link_libraries(arrow_odbc_spi_impl PUBLIC ${ODBCINST})
106108
endif()
107109

108110
set_target_properties(arrow_odbc_spi_impl
@@ -121,7 +123,7 @@ set_target_properties(arrow_odbc_spi_impl_cli
121123
target_link_libraries(arrow_odbc_spi_impl_cli arrow_odbc_spi_impl)
122124

123125
# Unit tests
124-
add_arrow_test(arrow_odbc_spi_impl_test
126+
add_arrow_test(odbc_spi_impl_test
125127
SOURCES
126128
accessors/boolean_array_accessor_test.cc
127129
accessors/binary_array_accessor_test.cc

cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_connection_test.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,3 @@ TEST(PopulateCallOptionsTest, GenericOptionWithSpaces) {
204204

205205
} // namespace flight_sql
206206
} // namespace driver
207-
208-
int main(int argc, char** argv) {
209-
::testing::InitGoogleTest(&argc, argv);
210-
return RUN_ALL_TESTS();
211-
}

cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_driver.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
// under the License.
1717

1818
#include "arrow/flight/sql/odbc/flight_sql/include/flight_sql/flight_sql_driver.h"
19+
#include "arrow/compute/api.h"
1920
#include "arrow/flight/sql/odbc/flight_sql/flight_sql_connection.h"
21+
#include "arrow/flight/sql/odbc/flight_sql/utils.h"
2022
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/platform.h"
2123
#include "arrow/util/io_util.h"
2224
#include "arrow/util/logging.h"
@@ -33,6 +35,8 @@ using odbcabstraction::OdbcVersion;
3335

3436
FlightSqlDriver::FlightSqlDriver()
3537
: diagnostics_("Apache Arrow", "Flight SQL", OdbcVersion::V_3), version_("0.9.0.0") {
38+
RegisterComputeKernels();
39+
// Register log after compute kernels check to avoid segfaults
3640
RegisterLog();
3741
}
3842

@@ -52,6 +56,17 @@ odbcabstraction::Diagnostics& FlightSqlDriver::GetDiagnostics() { return diagnos
5256

5357
void FlightSqlDriver::SetVersion(std::string version) { version_ = std::move(version); }
5458

59+
void FlightSqlDriver::RegisterComputeKernels() {
60+
auto registry = arrow::compute::GetFunctionRegistry();
61+
62+
// strptime is one of the required compute functions
63+
auto strptime_func = registry->GetFunction("strptime");
64+
if (!strptime_func.ok()) {
65+
// Register Kernel functions to library
66+
ThrowIfNotOK(arrow::compute::Initialize());
67+
}
68+
}
69+
5570
void FlightSqlDriver::RegisterLog() {
5671
std::string log_level_str = arrow::internal::GetEnvVar(kODBCLogLevel)
5772
.Map(arrow::internal::AsciiToLower)

cpp/src/arrow/flight/sql/odbc/flight_sql/include/flight_sql/flight_sql_driver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class FlightSqlDriver : public odbcabstraction::Driver {
3939

4040
void SetVersion(std::string version) override;
4141

42+
/// Register Arrow Compute kernels once.
43+
void RegisterComputeKernels();
44+
4245
void RegisterLog() override;
4346
};
4447

cpp/src/arrow/flight/sql/odbc/flight_sql/utils_test.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/calendar_utils.h"
2121

22+
#include "arrow/compute/initialize.h"
2223
#include "arrow/testing/builder.h"
2324
#include "arrow/testing/gtest_util.h"
2425
#include "arrow/testing/util.h"
@@ -27,6 +28,16 @@
2728
namespace driver {
2829
namespace flight_sql {
2930

31+
// A global test "environment", to ensure Arrow compute kernel functions are registered
32+
33+
class ComputeKernelEnvironment : public ::testing::Environment {
34+
public:
35+
void SetUp() override { ASSERT_OK(arrow::compute::Initialize()); }
36+
};
37+
38+
::testing::Environment* kernel_env =
39+
::testing::AddGlobalTestEnvironment(new ComputeKernelEnvironment);
40+
3041
void AssertConvertedArray(const std::shared_ptr<arrow::Array>& expected_array,
3142
const std::shared_ptr<arrow::Array>& converted_array,
3243
uint64_t size, arrow::Type::type arrow_type) {

0 commit comments

Comments
 (0)