Skip to content

Commit 848fdfe

Browse files
committed
Enable ODBC Build On Linux
- Enable Linux ODBC build with unicode support - Added `docker-compose` for Flight SQL ODBC - Register ODBC after build - Replaced `boost::lexicographical_compare` with `std::lexicographical_compare` - Fixed conversion bugs in `SetAttributeSQLWCHAR` - Convert from std::string to std::u16string directly without involving wide string (wstring) * Add patch for Windows build
1 parent d08d5e6 commit 848fdfe

37 files changed

Lines changed: 361 additions & 117 deletions

.github/workflows/cpp_extra.yml

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,64 @@ jobs:
336336
cd cpp/examples/minimal_build
337337
../minimal_build.build/arrow-example
338338
339+
odbc-linux:
340+
needs: check-labels
341+
name: ODBC Linux
342+
runs-on: ubuntu-latest
343+
if: >-
344+
needs.check-labels.outputs.force == 'true' ||
345+
contains(fromJSON(needs.check-labels.outputs.ci-extra-labels || '[]'), 'CI: Extra') ||
346+
contains(fromJSON(needs.check-labels.outputs.ci-extra-labels || '[]'), 'CI: Extra: C++')
347+
timeout-minutes: 75
348+
strategy:
349+
fail-fast: false
350+
env:
351+
ARCH: amd64
352+
ARCHERY_DEBUG: 1
353+
ARROW_ENABLE_TIMING_TESTS: OFF
354+
CLANG_TOOLS: 18
355+
DOCKER_VOLUME_PREFIX: ".docker/"
356+
LLVM: 18
357+
UBUNTU: 24.04
358+
steps:
359+
- name: Checkout Arrow
360+
uses: actions/checkout@v6
361+
with:
362+
fetch-depth: 0
363+
submodules: recursive
364+
- name: Cache Docker Volumes
365+
uses: actions/cache@v5
366+
with:
367+
path: .docker
368+
key: ubuntu-cpp-odbc-${{ hashFiles('cpp/**') }}
369+
restore-keys: ubuntu-cpp-odbc-
370+
- name: Setup Python on hosted runner
371+
uses: actions/setup-python@v6
372+
with:
373+
python-version: 3
374+
- name: Setup Archery
375+
run: python3 -m pip install -e dev/archery[docker]
376+
- name: Execute Docker Build
377+
env:
378+
ARCHERY_DOCKER_USER: ${{ secrets.DOCKERHUB_USER }}
379+
ARCHERY_DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}
380+
run: |
381+
# GH-40558: reduce ASLR to avoid ASAN/LSAN crashes
382+
sudo sysctl -w vm.mmap_rnd_bits=28
383+
source ci/scripts/util_enable_core_dumps.sh
384+
archery docker run ubuntu-cpp-odbc
385+
- name: Docker Push
386+
if: >-
387+
success() &&
388+
github.event_name == 'push' &&
389+
github.repository == 'apache/arrow' &&
390+
github.ref_name == 'main'
391+
env:
392+
ARCHERY_DOCKER_USER: ${{ secrets.DOCKERHUB_USER }}
393+
ARCHERY_DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}
394+
continue-on-error: true
395+
run: archery docker push ubuntu-cpp-odbc
396+
339397
odbc-macos:
340398
needs: check-labels
341399
name: ODBC ${{ matrix.build-type }} ${{ matrix.architecture }} macOS ${{ matrix.macos-version }}
@@ -435,7 +493,7 @@ jobs:
435493
"$(pwd)/build/cpp/${{ matrix.build-type }}/libarrow_flight_sql_odbc.dylib"
436494
- name: Register Flight SQL ODBC Driver
437495
run: |
438-
sudo cpp/src/arrow/flight/sql/odbc/install/mac/install_odbc.sh $(pwd)/build/cpp/${{ matrix.build-type }}/libarrow_flight_sql_odbc.dylib
496+
sudo cpp/src/arrow/flight/sql/odbc/install/unix/install_odbc.sh $(pwd)/build/cpp/${{ matrix.build-type }}/libarrow_flight_sql_odbc.dylib
439497
- name: Test
440498
shell: bash
441499
run: |
@@ -698,6 +756,7 @@ jobs:
698756
- jni-linux
699757
- jni-macos
700758
- msvc-arm64
759+
- odbc-linux
701760
- odbc-macos
702761
- odbc-msvc
703762
- odbc-nightly

ci/docker/ubuntu-24.04-cpp.dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ RUN apt-get update -y -q && \
121121
rsync \
122122
tzdata \
123123
tzdata-legacy \
124+
unixodbc-dev \
124125
uuid-runtime \
125126
unzip \
126127
wget && \

compose.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ x-hierarchy:
151151
- ubuntu-r-only-r
152152
- ubuntu-cpp-bundled
153153
- ubuntu-cpp-bundled-offline
154+
- ubuntu-cpp-odbc
154155
- ubuntu-cpp-minimal
155156
- ubuntu-cuda-cpp:
156157
- ubuntu-cuda-python
@@ -496,6 +497,43 @@ services:
496497
volumes: *ubuntu-volumes
497498
command: *cpp-command
498499

500+
ubuntu-cpp-odbc:
501+
# Arrow Flight SQL ODBC build with BUNDLED dependencies with downloaded dependencies.
502+
image: ${REPO}:${ARCH}-ubuntu-${UBUNTU}-cpp
503+
build:
504+
context: .
505+
dockerfile: ci/docker/ubuntu-${UBUNTU}-cpp.dockerfile
506+
cache_from:
507+
- ${REPO}:${ARCH}-ubuntu-${UBUNTU}-cpp
508+
args:
509+
arch: ${ARCH}
510+
base: "${ARCH}/ubuntu:${UBUNTU}"
511+
clang_tools: ${CLANG_TOOLS}
512+
cmake: ${CMAKE}
513+
gcc: ${GCC}
514+
llvm: ${LLVM}
515+
shm_size: *shm-size
516+
cap_add:
517+
- SYS_ADMIN
518+
devices:
519+
- "/dev/fuse:/dev/fuse"
520+
security_opt:
521+
- apparmor:unconfined
522+
ulimits: *ulimits
523+
environment:
524+
<<: [*common, *ccache, *sccache, *cpp]
525+
ARROW_BUILD_TYPE: RELEASE
526+
ARROW_DEPENDENCY_SOURCE: BUNDLED
527+
ARROW_DEPENDENCY_USE_SHARED: OFF
528+
ARROW_FLIGHT_SQL_ODBC: ON
529+
volumes: *ubuntu-volumes
530+
# Register ODBC before running tests
531+
command: >
532+
/bin/bash -c "
533+
/arrow/ci/scripts/cpp_build.sh /arrow /build &&
534+
sudo /arrow/cpp/src/arrow/flight/sql/odbc/install/unix/install_odbc.sh /usr/local/lib/libarrow_flight_sql_odbc.so &&
535+
/arrow/ci/scripts/cpp_test.sh /arrow /build"
536+
499537
ubuntu-cpp-minimal:
500538
# Arrow build with minimal components/dependencies
501539
image: ${REPO}:${ARCH}-ubuntu-${UBUNTU}-cpp-minimal

cpp/cmake_modules/DefineOptions.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ macro(tsort_bool_option_dependencies)
107107
endmacro()
108108

109109
macro(resolve_option_dependencies)
110-
# Arrow Flight SQL ODBC is available only for Windows and macOS for now.
111-
if(NOT WIN32 AND NOT APPLE)
112-
set(ARROW_FLIGHT_SQL_ODBC OFF)
113-
endif()
114110
if(MSVC_TOOLCHAIN)
115111
set(ARROW_USE_GLOG OFF)
116112
endif()

cpp/cmake_modules/ThirdpartyToolchain.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ function(build_boost)
10901090
set(ARROW_BOOST_NEED_MULTIPRECISION FALSE)
10911091
endif()
10921092
if(ARROW_ENABLE_THREADING)
1093-
if(ARROW_WITH_THRIFT OR (ARROW_FLIGHT_SQL_ODBC AND MSVC))
1093+
if(ARROW_WITH_THRIFT OR ARROW_FLIGHT_SQL_ODBC)
10941094
list(APPEND BOOST_INCLUDE_LIBRARIES locale)
10951095
endif()
10961096
if(ARROW_BOOST_NEED_MULTIPRECISION)

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ else()
2828
endif()
2929

3030
add_subdirectory(odbc_impl)
31-
add_subdirectory(tests)
31+
if(ARROW_BUILD_TESTS)
32+
if(WIN32 OR APPLE)
33+
# GH-49552 TODO: Enable Linux test build
34+
add_subdirectory(tests)
35+
endif()
36+
endif()
3237

3338
arrow_install_all_headers("arrow/flight/sql/odbc")
3439

cpp/src/arrow/flight/sql/odbc/install/mac/install_odbc.sh renamed to cpp/src/arrow/flight/sql/odbc/install/unix/install_odbc.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@ if [ ! -f "$ODBC_64BIT" ]; then
4040
exit 1
4141
fi
4242

43-
USER_ODBCINST_FILE="$HOME/Library/ODBC/odbcinst.ini"
43+
case "$(uname)" in
44+
Linux)
45+
USER_ODBCINST_FILE="/etc/odbcinst.ini"
46+
;;
47+
*)
48+
# macOS
49+
USER_ODBCINST_FILE="$HOME/Library/ODBC/odbcinst.ini"
50+
;;
51+
esac
52+
4453
DRIVER_NAME="Apache Arrow Flight SQL ODBC Driver"
4554

4655
mkdir -p "$HOME"/Library/ODBC

cpp/src/arrow/flight/sql/odbc/odbc_api.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#endif // defined(_WIN32)
3838

3939
namespace arrow::flight::sql::odbc {
40+
void LoadPropertiesFromDSN(const std::string& dsn, Connection::ConnPropertyMap& props);
41+
4042
SQLRETURN SQLAllocHandle(SQLSMALLINT type, SQLHANDLE parent, SQLHANDLE* result) {
4143
ARROW_LOG(DEBUG) << "SQLAllocHandle called with type: " << type
4244
<< ", parent: " << parent

cpp/src/arrow/flight/sql/odbc/odbc_api_internal.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
#include "arrow/flight/sql/odbc/odbc_impl/platform.h"
2121

2222
#include <sql.h>
23-
#include <sqltypes.h>
24-
#include <sqlucode.h>
23+
#include <sqlext.h>
2524

2625
// \file odbc_api_internal.h
2726
//

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,26 @@ if(WIN32)
130130
win_system_dsn.cc)
131131
endif()
132132

133-
if(APPLE)
133+
if(WIN32)
134+
find_package(ODBC REQUIRED)
135+
target_include_directories(arrow_odbc_spi_impl PUBLIC ${ODBC_INCLUDE_DIR})
136+
target_link_libraries(arrow_odbc_spi_impl
137+
PUBLIC arrow_flight_sql_shared arrow_compute_shared Boost::locale
138+
${ODBCINST})
139+
else()
140+
# Unix
134141
target_include_directories(arrow_odbc_spi_impl SYSTEM BEFORE PUBLIC ${ODBC_INCLUDE_DIR})
135142
target_link_libraries(arrow_odbc_spi_impl
136143
PUBLIC arrow_flight_sql_static
137144
arrow_compute_static
138145
Boost::locale
139146
Boost::headers
140147
RapidJSON)
141-
else()
142-
find_package(ODBC REQUIRED)
143-
target_include_directories(arrow_odbc_spi_impl PUBLIC ${ODBC_INCLUDE_DIR})
144-
target_link_libraries(arrow_odbc_spi_impl
145-
PUBLIC arrow_flight_sql_shared arrow_compute_shared Boost::locale
146-
${ODBCINST})
148+
149+
if(NOT APPLE)
150+
# Explicitly link to unix-odbc on Linux
151+
target_link_libraries(arrow_odbc_spi_impl PUBLIC ${ODBCINST})
152+
endif()
147153
endif()
148154

149155
# CLI

0 commit comments

Comments
 (0)