Skip to content

Commit fa40692

Browse files
committed
Add Arrow Flight SQL ODBC driver
Co-authored-by: rscales <[email protected]> Add initial framework for odbc dll - Add ARROW_FLIGHT_SQL_ODBC option. If we set `ARROW_FLIGHT_SQL_ODBC=ON`, the flightsql odbc folder will be built - Add odbc api layer for entry_point.cc - builds odbc dll file, with ODBC APIs exported in odbc.def Address James' comments Fix `odbcabstraction` build errors and partially fix `flightsql_odbc` errors Fix boost-variant not found error - Adding dependencies from odbc/vcpkg.json to cpp/vcpkg.json - Fix whereami.cc and .h dependency; ported lates code Update whereami.cc - use `long` instead of `int64`. Fixed namespace issues. - PR CI fix: Add `parquet-testing` back Partial build fix for `flight_sql` folder - Replaced `namespace arrow` and `namespace odbcabstraction` with `using namespace ...` - fix flight_sql_connection.cc Fix `util::nullopt` to use `std::nullopt` - fix std::optional - fix BufferReader - Fix GetSchema - fix json_converter.cc - partial fix configuration.h - partial fix get_info_cache.cc - Fix winsock build error - Comment out `flight_sql` files that cannot build - Comment out configuration and unit tests - Comment out get info cache and system trust store Create initial odbc tests folder Implement SQLAllocEnv Fix cmake build Implement SQLFreeEnv Fix rest of build errors from `flightsql-odbc` - Fix get info errors - Fix for configuration window - added odbcinst library - Fix system trust store - unit test fixes - Add dependency of ARROW_COMPUTE. `arrow/compute/api.h` is used in `flight_sql`. Adding `ARROW_COMPUTE=ON` during build fixed run time unit tests failures. Implement SQLAllocConnect and SQLFreeConnect Fix build issue from static flight sql driver Lint and code style fixes Re-add deleted submodule parquet-testing clang-format lint fix cpplint lint fix Exclude whereami in rat exclude list C++/CLI lint fix Update parquet-testing to match commit from `main` Address Kou's comments ODBC directory lint fixes Catching the lint fixes outside of `flightsql-odbc` code Fix build warnings that get treated as error Implement SQLSetEnvAttr and SQLGetEnvAttr Implement use of ExecuteWithDiagnostics Doxygen Error Fixes and Address comments from Kou and James Address comments from Kou - Updates License.txt - Update cmake toolchain - Move whereami to `vendored` - Use string_view instead of NOLINT std::string Remove `whereami.cc` from arrow util build We are building whereami.cc as part of odbc Fix include headers to replace <> with "" Address comments from James Implement SQLGetDiagField
1 parent 3cc284f commit fa40692

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1116
-83
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
# This config sets the following variables in your project::
19+
#
20+
# ArrowFlightSqlOdbc_FOUND - true if Arrow Flight SQL ODBC found on the system
21+
#
22+
# This config sets the following targets in your project::
23+
#
24+
# ArrowFlightSqlOdbc::arrow_flight_sql_odbc_shared - for linked as shared library if shared library is built
25+
# ArrowFlightSqlOdbc::arrow_flight_sql_odbc_static - for linked as static library if static library is built
26+
27+
@PACKAGE_INIT@
28+
29+
include(CMakeFindDependencyMacro)
30+
find_dependency(ArrowFlightSql)
31+
32+
include("${CMAKE_CURRENT_LIST_DIR}/ArrowFlightSqlOdbcTargets.cmake")
33+
34+
arrow_keep_backward_compatibility(ArrowFlightSqlOdbc arrow_flight_sql_odbc)
35+
36+
check_required_components(ArrowFlightSqlOdbc)
37+
38+
arrow_show_details(ArrowFlightSqlOdbc ARROW_FLIGHT_SQL_ODBC)

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,53 @@ add_custom_target(arrow_flight_sql_odbc)
1919

2020
add_subdirectory(flight_sql)
2121
add_subdirectory(odbcabstraction)
22+
add_subdirectory(tests)
23+
24+
arrow_install_all_headers("arrow/flight/sql/odbc")
25+
26+
set(ARROW_FLIGHT_SQL_ODBC_SRCS entry_points.cc odbc_api.cc)
27+
28+
if(WIN32)
29+
list(APPEND ARROW_FLIGHT_SQL_ODBC_SRCS odbc.def)
30+
endif()
31+
32+
if(WIN32)
33+
if(MSVC_VERSION GREATER_EQUAL 1900)
34+
set(ODBCINST legacy_stdio_definitions odbccp32 shlwapi)
35+
endif()
36+
elseif(APPLE)
37+
set(ODBCINST iodbcinst)
38+
else()
39+
set(ODBCINST odbcinst)
40+
endif()
41+
42+
add_arrow_lib(arrow_flight_sql_odbc
43+
CMAKE_PACKAGE_NAME
44+
ArrowFlightSqlOdbc
45+
PKG_CONFIG_NAME
46+
arrow-flight-sql-odbc
47+
OUTPUTS
48+
ARROW_FLIGHT_SQL_ODBC_LIBRARIES
49+
SOURCES
50+
${ARROW_FLIGHT_SQL_ODBC_SRCS}
51+
DEPENDENCIES
52+
arrow_flight_sql
53+
SHARED_LINK_FLAGS
54+
${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt
55+
SHARED_LINK_LIBS
56+
arrow_flight_sql_shared
57+
SHARED_INSTALL_INTERFACE_LIBS
58+
ArrowFlight::arrow_flight_sql_shared
59+
STATIC_LINK_LIBS
60+
arrow_flight_sql_static
61+
STATIC_INSTALL_INTERFACE_LIBS
62+
ArrowFlight::arrow_flight_sql_static
63+
SHARED_PRIVATE_LINK_LIBS
64+
${ODBC_LIBRARIES}
65+
${ODBCINST}
66+
odbcabstraction
67+
arrow_odbc_spi_impl)
68+
69+
foreach(LIB_TARGET ${ARROW_FLIGHT_SQL_ODBC_LIBRARIES})
70+
target_compile_definitions(${LIB_TARGET} PRIVATE ARROW_FLIGHT_SQL_ODBC_EXPORTING)
71+
endforeach()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
prefix=@CMAKE_INSTALL_PREFIX@
19+
includedir=@ARROW_PKG_CONFIG_INCLUDEDIR@
20+
libdir=@ARROW_PKG_CONFIG_LIBDIR@
21+
22+
Name: Apache Arrow Flight SQL ODBC
23+
Description: Apache Arrow Flight SQL ODBC extension
24+
Version: @ARROW_VERSION@
25+
Requires: arrow-flight-sql
26+
Libs: -L${libdir} -larrow_flight_sql_odbc
27+
Cflags.private: -DARROW_FLIGHT_SQL_ODBC_STATIC
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#ifdef _WIN32
19+
# include <windows.h>
20+
#endif
21+
22+
#include <sql.h>
23+
#include <sqlext.h>
24+
#include <sqltypes.h>
25+
#include <sqlucode.h>
26+
27+
#include "arrow/flight/sql/odbc/odbc_api.h"
28+
#include "arrow/flight/sql/odbc/visibility.h"
29+
30+
SQLRETURN SQL_API SQLAllocHandle(SQLSMALLINT type, SQLHANDLE parent, SQLHANDLE* result) {
31+
return arrow::SQLAllocHandle(type, parent, result);
32+
}
33+
34+
SQLRETURN SQL_API SQLAllocEnv(SQLHENV* env) {
35+
return arrow::SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, env);
36+
}
37+
38+
SQLRETURN SQL_API SQLAllocConnect(SQLHENV env, SQLHDBC* conn) {
39+
return arrow::SQLAllocHandle(SQL_HANDLE_DBC, env, conn);
40+
}
41+
42+
SQLRETURN SQL_API SQLFreeHandle(SQLSMALLINT type, SQLHANDLE handle) {
43+
return arrow::SQLFreeHandle(type, handle);
44+
}
45+
46+
SQLRETURN SQL_API SQLFreeEnv(SQLHENV env) {
47+
return arrow::SQLFreeHandle(SQL_HANDLE_ENV, env);
48+
}
49+
50+
SQLRETURN SQL_API SQLFreeConnect(SQLHDBC conn) {
51+
return arrow::SQLFreeHandle(SQL_HANDLE_DBC, conn);
52+
}
53+
54+
SQLRETURN SQL_API SQLGetDiagFieldW(SQLSMALLINT handleType, SQLHANDLE handle,
55+
SQLSMALLINT recNumber, SQLSMALLINT diagIdentifier,
56+
SQLPOINTER diagInfoPtr, SQLSMALLINT bufferLength,
57+
SQLSMALLINT* stringLengthPtr) {
58+
return arrow::SQLGetDiagFieldW(handleType, handle, recNumber, diagIdentifier,
59+
diagInfoPtr, bufferLength, stringLengthPtr);
60+
}
61+
62+
SQLRETURN SQL_API SQLGetEnvAttr(SQLHENV env, SQLINTEGER attr, SQLPOINTER valuePtr,
63+
SQLINTEGER bufferLen, SQLINTEGER* strLenPtr) {
64+
return arrow::SQLGetEnvAttr(env, attr, valuePtr, bufferLen, strLenPtr);
65+
}
66+
67+
SQLRETURN SQL_API SQLSetEnvAttr(SQLHENV env, SQLINTEGER attr, SQLPOINTER valuePtr,
68+
SQLINTEGER strLen) {
69+
return arrow::SQLSetEnvAttr(env, attr, valuePtr, strLen);
70+
}
71+
72+
SQLRETURN SQL_API SQLDriverConnect(SQLHDBC conn, SQLHWND windowHandle,
73+
SQLWCHAR* inConnectionString,
74+
SQLSMALLINT inConnectionStringLen,
75+
SQLWCHAR* outConnectionString,
76+
SQLSMALLINT outConnectionStringBufferLen,
77+
SQLSMALLINT* outConnectionStringLen,
78+
SQLUSMALLINT driverCompletion) {
79+
// TODO: implement SQLDriverConnect by linking to `odbc_impl` //-AL- TODO: create GitHub
80+
// issue for SQLDriverConnect implementation
81+
return SQL_INVALID_HANDLE;
82+
}

cpp/src/arrow/flight/sql/odbc/flight_sql/accessors/primitive_array_accessor_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// under the License.
1717

1818
#include "arrow/flight/sql/odbc/flight_sql/accessors/primitive_array_accessor.h"
19-
#include <arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/diagnostics.h>
19+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/diagnostics.h"
2020
#include "arrow/testing/builder.h"
2121
#include "gtest/gtest.h"
2222

cpp/src/arrow/flight/sql/odbc/flight_sql/config/configuration.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,15 @@ std::string ReadDsnString(const std::string& dsn, const std::string_view& key,
3838
const std::string& dflt = "") {
3939
#define BUFFER_SIZE (1024)
4040
std::vector<char> buf(BUFFER_SIZE);
41-
42-
std::string key_str = std::string(key);
4341
int ret =
44-
SQLGetPrivateProfileString(dsn.c_str(), key_str.c_str(), dflt.c_str(), buf.data(),
42+
SQLGetPrivateProfileString(dsn.c_str(), key.data(), dflt.c_str(), buf.data(),
4543
static_cast<int>(buf.size()), "ODBC.INI");
4644

4745
if (ret > BUFFER_SIZE) {
4846
// If there wasn't enough space, try again with the right size buffer.
4947
buf.resize(ret + 1);
5048
ret =
51-
SQLGetPrivateProfileString(dsn.c_str(), key_str.c_str(), dflt.c_str(), buf.data(),
49+
SQLGetPrivateProfileString(dsn.c_str(), key.data(), dflt.c_str(), buf.data(),
5250
static_cast<int>(buf.size()), "ODBC.INI");
5351
}
5452

cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_result_set_accessors.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
#pragma once
1919

20-
#include <arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/types.h>
21-
#include <arrow/type_fwd.h>
2220
#include <memory>
21+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/types.h"
22+
#include "arrow/type_fwd.h"
2323

2424
namespace driver {
2525
namespace flight_sql {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
// under the License.
1717

1818
#include "arrow/flight/sql/odbc/flight_sql/flight_sql_result_set_metadata.h"
19-
#include <arrow/flight/sql/column_metadata.h>
20-
#include <arrow/util/key_value_metadata.h>
19+
#include "arrow/flight/sql/column_metadata.h"
2120
#include "arrow/flight/sql/odbc/flight_sql/utils.h"
2221
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/platform.h"
22+
#include "arrow/util/key_value_metadata.h"
2323

2424
#include <utility>
2525
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/exceptions.h"

cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_ssl_config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
#pragma once
1919

20-
#include <arrow/flight/types.h>
21-
#include <arrow/status.h>
2220
#include <string>
21+
#include "arrow/flight/types.h"
22+
#include "arrow/status.h"
2323

2424
namespace driver {
2525
namespace flight_sql {

cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_stream_chunk_buffer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
#pragma once
1919

20-
#include <arrow/flight/client.h>
21-
#include <arrow/flight/sql/client.h>
22-
#include <arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/blocking_queue.h>
20+
#include "arrow/flight/client.h"
21+
#include "arrow/flight/sql/client.h"
22+
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/blocking_queue.h"
2323

2424
namespace driver {
2525
namespace flight_sql {

0 commit comments

Comments
 (0)