Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions cpp/src/arrow/flight/sql/odbc/flight_sql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
15 changes: 15 additions & 0 deletions cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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();
}

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
11 changes: 11 additions & 0 deletions cpp/src/arrow/flight/sql/odbc/flight_sql/utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down
Loading