This is an automated email from the ASF dual-hosted git repository.
kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new a13525d230 GH-47679: [C++] Register arrow compute calls in ODBC
(#47680)
a13525d230 is described below
commit a13525d230e9029c9940cca8ab45291dc0930aae
Author: Alina (Xi) Li <[email protected]>
AuthorDate: Thu Oct 2 17:29:20 2025 -0700
GH-47679: [C++] Register arrow compute calls in ODBC (#47680)
### Rationale for this change
Need to call function to register Arrow compute calls which is needed due
to https://github.com/apache/arrow/issues/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 GH-47434.
### Are these changes tested?
- `arrow-odbc-spi-impl-test` pass locally.
### Are there any user-facing changes?
No
PR is extracted from PR https://github.com/apache/arrow/pull/46099
* GitHub Issue: #47679
Authored-by: Alina (Xi) Li <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
---
cpp/src/arrow/flight/sql/odbc/flight_sql/CMakeLists.txt | 10 ++++++----
.../sql/odbc/flight_sql/flight_sql_connection_test.cc | 5 -----
.../arrow/flight/sql/odbc/flight_sql/flight_sql_driver.cc | 15 +++++++++++++++
.../flight_sql/include/flight_sql/flight_sql_driver.h | 3 +++
cpp/src/arrow/flight/sql/odbc/flight_sql/utils_test.cc | 11 +++++++++++
5 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/cpp/src/arrow/flight/sql/odbc/flight_sql/CMakeLists.txt
b/cpp/src/arrow/flight/sql/odbc/flight_sql/CMakeLists.txt
index 56aabb54db..02bb58c4b8 100644
--- a/cpp/src/arrow/flight/sql/odbc/flight_sql/CMakeLists.txt
+++ b/cpp/src/arrow/flight/sql/odbc/flight_sql/CMakeLists.txt
@@ -99,10 +99,12 @@ if(WIN32)
system_dsn.cc)
endif()
-target_link_libraries(arrow_odbc_spi_impl PUBLIC odbcabstraction
arrow_flight_sql_shared)
+target_link_libraries(arrow_odbc_spi_impl PUBLIC odbcabstraction
arrow_flight_sql_shared
+ arrow_compute_shared
Boost::locale)
-if(MSVC)
- target_link_libraries(arrow_odbc_spi_impl PUBLIC Boost::locale)
+# Link libraries on MINGW64 and macOS
+if(MINGW OR APPLE)
+ target_link_libraries(arrow_odbc_spi_impl PUBLIC ${ODBCINST})
endif()
set_target_properties(arrow_odbc_spi_impl
@@ -121,7 +123,7 @@ set_target_properties(arrow_odbc_spi_impl_cli
target_link_libraries(arrow_odbc_spi_impl_cli arrow_odbc_spi_impl)
# Unit tests
-add_arrow_test(arrow_odbc_spi_impl_test
+add_arrow_test(odbc_spi_impl_test
SOURCES
accessors/boolean_array_accessor_test.cc
accessors/binary_array_accessor_test.cc
diff --git
a/cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_connection_test.cc
b/cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_connection_test.cc
index 6a519138b6..56d6f73af9 100644
--- a/cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_connection_test.cc
+++ b/cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_connection_test.cc
@@ -204,8 +204,3 @@ TEST(PopulateCallOptionsTest, GenericOptionWithSpaces) {
} // namespace flight_sql
} // namespace driver
-
-int main(int argc, char** argv) {
- ::testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_driver.cc
b/cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_driver.cc
index 70e94def22..e815775516 100644
--- a/cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_driver.cc
+++ b/cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_driver.cc
@@ -16,7 +16,9 @@
// under the License.
#include
"arrow/flight/sql/odbc/flight_sql/include/flight_sql/flight_sql_driver.h"
+#include "arrow/compute/api.h"
#include "arrow/flight/sql/odbc/flight_sql/flight_sql_connection.h"
+#include "arrow/flight/sql/odbc/flight_sql/utils.h"
#include
"arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/platform.h"
#include "arrow/util/io_util.h"
#include "arrow/util/logging.h"
@@ -33,6 +35,8 @@ using odbcabstraction::OdbcVersion;
FlightSqlDriver::FlightSqlDriver()
: diagnostics_("Apache Arrow", "Flight SQL", OdbcVersion::V_3),
version_("0.9.0.0") {
+ RegisterComputeKernels();
+ // Register log after compute kernels check to avoid segfaults
RegisterLog();
}
@@ -52,6 +56,17 @@ odbcabstraction::Diagnostics&
FlightSqlDriver::GetDiagnostics() { return diagnos
void FlightSqlDriver::SetVersion(std::string version) { version_ =
std::move(version); }
+void FlightSqlDriver::RegisterComputeKernels() {
+ auto registry = arrow::compute::GetFunctionRegistry();
+
+ // strptime is one of the required compute functions
+ auto strptime_func = registry->GetFunction("strptime");
+ if (!strptime_func.ok()) {
+ // Register Kernel functions to library
+ ThrowIfNotOK(arrow::compute::Initialize());
+ }
+}
+
void FlightSqlDriver::RegisterLog() {
std::string log_level_str = arrow::internal::GetEnvVar(kODBCLogLevel)
.Map(arrow::internal::AsciiToLower)
diff --git
a/cpp/src/arrow/flight/sql/odbc/flight_sql/include/flight_sql/flight_sql_driver.h
b/cpp/src/arrow/flight/sql/odbc/flight_sql/include/flight_sql/flight_sql_driver.h
index f349fa3344..6a2977c7ba 100644
---
a/cpp/src/arrow/flight/sql/odbc/flight_sql/include/flight_sql/flight_sql_driver.h
+++
b/cpp/src/arrow/flight/sql/odbc/flight_sql/include/flight_sql/flight_sql_driver.h
@@ -39,6 +39,9 @@ class FlightSqlDriver : public odbcabstraction::Driver {
void SetVersion(std::string version) override;
+ /// Register Arrow Compute kernels once.
+ void RegisterComputeKernels();
+
void RegisterLog() override;
};
diff --git a/cpp/src/arrow/flight/sql/odbc/flight_sql/utils_test.cc
b/cpp/src/arrow/flight/sql/odbc/flight_sql/utils_test.cc
index 1575bf09fa..fcfffc49e9 100644
--- a/cpp/src/arrow/flight/sql/odbc/flight_sql/utils_test.cc
+++ b/cpp/src/arrow/flight/sql/odbc/flight_sql/utils_test.cc
@@ -19,6 +19,7 @@
#include
"arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/calendar_utils.h"
+#include "arrow/compute/initialize.h"
#include "arrow/testing/builder.h"
#include "arrow/testing/gtest_util.h"
#include "arrow/testing/util.h"
@@ -27,6 +28,16 @@
namespace driver {
namespace flight_sql {
+// A global test "environment", to ensure Arrow compute kernel functions are
registered
+
+class ComputeKernelEnvironment : public ::testing::Environment {
+ public:
+ void SetUp() override { ASSERT_OK(arrow::compute::Initialize()); }
+};
+
+::testing::Environment* kernel_env =
+ ::testing::AddGlobalTestEnvironment(new ComputeKernelEnvironment);
+
void AssertConvertedArray(const std::shared_ptr<arrow::Array>& expected_array,
const std::shared_ptr<arrow::Array>& converted_array,
uint64_t size, arrow::Type::type arrow_type) {