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
15 changes: 1 addition & 14 deletions cpp/src/arrow/flight/sql/odbc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_custom_target(arrow_flight_sql_odbc)

# Ensure fmt is loaded as header only
add_compile_definitions(FMT_HEADER_ONLY)

if(WIN32)
if(MSVC_VERSION GREATER_EQUAL 1900)
set(ODBCINST legacy_stdio_definitions odbccp32 shlwapi)
Expand All @@ -39,15 +36,6 @@ endif()

add_definitions(-DUNICODE=1)

include(FetchContent)
fetchcontent_declare(spdlog
URL https://github.com/gabime/spdlog/archive/refs/tags/v1.15.3.zip
CONFIGURE_COMMAND
""
BUILD_COMMAND
"")
fetchcontent_makeavailable(spdlog)

add_subdirectory(flight_sql)
add_subdirectory(odbcabstraction)
add_subdirectory(tests)
Expand Down Expand Up @@ -104,8 +92,7 @@ add_arrow_lib(arrow_flight_sql_odbc
${ODBC_LIBRARIES}
${ODBCINST}
odbcabstraction
arrow_odbc_spi_impl
spdlog::spdlog)
arrow_odbc_spi_impl)

foreach(LIB_TARGET ${ARROW_FLIGHT_SQL_ODBC_LIBRARIES})
target_compile_definitions(${LIB_TARGET} PRIVATE ARROW_FLIGHT_SQL_ODBC_EXPORTING)
Expand Down
21 changes: 19 additions & 2 deletions cpp/src/arrow/flight/sql/odbc/README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Steps to Register the 64-bit Apache Arrow ODBC driver on Windows
## Steps to Register the 64-bit Apache Arrow ODBC driver on Windows

After the build succeeds, the ODBC DLL will be located in
`build\debug\Debug` for a debug build and `build\release\Release` for a release build.
Expand All @@ -18,9 +18,26 @@ After the build succeeds, the ODBC DLL will be located in
If the registration is successful, then Apache Arrow Flight SQL ODBC Driver
should show as an available ODBC driver in the x64 ODBC Driver Manager.

Steps to Generate Windows Installer
## Steps to Generate Windows Installer
1. Build with `ARROW_FLIGHT_SQL_ODBC=ON` and `ARROW_FLIGHT_SQL_ODBC_INSTALLER=ON`.
2. `cd` to `build` folder.
3. Run `cpack`.

If the generation is successful, you will find `Apache Arrow Flight SQL ODBC-<version>-win64.msi` generated under the `build` folder.


## Steps to Enable Logging
Arrow Flight SQL ODBC driver uses Arrow's internal logging framework. By default, the log messages are printed to the terminal.
1. Set environment variable `ARROW_ODBC_LOG_LEVEL` to any of the following valid value.

| LogLevel | Description |
|----------|-------------|
| -2 | TRACE |
| -1 | DEBUG |
| 0 | INFO |
| 1 | WARNING |
| 2 | ERROR |
| 3 | FATAL |
| Empty String or not set | No log messages displayed.|

The Windows ODBC driver currently does not support writing log files. `ARROW_USE_GLOG` is required to write log files, and `ARROW_USE_GLOG` is disabled on Windows platform since plasma using `glog` is not fully tested on windows.
42 changes: 22 additions & 20 deletions cpp/src/arrow/flight/sql/odbc/entry_points.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/odbc_environment.h"
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/odbc_impl/odbc_statement.h"

#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/logger.h"
#include "arrow/util/logging.h"

SQLRETURN SQL_API SQLAllocHandle(SQLSMALLINT type, SQLHANDLE parent, SQLHANDLE* result) {
return arrow::SQLAllocHandle(type, parent, result);
Expand Down Expand Up @@ -178,7 +178,7 @@ SQLRETURN SQL_API SQLBindCol(SQLHSTMT stmt, SQLUSMALLINT recordNumber, SQLSMALLI
}

SQLRETURN SQL_API SQLCancel(SQLHSTMT stmt) {
LOG_DEBUG("SQLCancel called with stmt: {}", stmt);
ARROW_LOG(DEBUG) << "SQLCancel called with stmt: " << stmt;
return ODBC::ODBCStatement::ExecuteWithDiagnostics(stmt, SQL_ERROR, [=]() {
throw driver::odbcabstraction::DriverException("SQLCancel is not implemented",
"IM001");
Expand Down Expand Up @@ -225,18 +225,19 @@ SQLRETURN SQL_API SQLForeignKeys(SQLHSTMT stmt, SQLWCHAR* pKCatalogName,
SQLSMALLINT fKCatalogNameLength, SQLWCHAR* fKSchemaName,
SQLSMALLINT fKSchemaNameLength, SQLWCHAR* fKTableName,
SQLSMALLINT fKTableNameLength) {
LOG_DEBUG(
"SQLForeignKeysW called with stmt: {}, pKCatalogName: {}, "
"pKCatalogNameLength: "
"{}, pKSchemaName: {}, pKSchemaNameLength: {}, pKTableName: {}, pKTableNameLength: "
"{}, "
"fKCatalogName: {}, fKCatalogNameLength: {}, fKSchemaName: {}, fKSchemaNameLength: "
"{}, "
"fKTableName: {}, fKTableNameLength : {}",
stmt, fmt::ptr(pKCatalogName), pKCatalogNameLength, fmt::ptr(pKSchemaName),
pKSchemaNameLength, fmt::ptr(pKTableName), pKTableNameLength,
fmt::ptr(fKCatalogName), fKCatalogNameLength, fmt::ptr(fKSchemaName),
fKSchemaNameLength, fmt::ptr(fKTableName), fKTableNameLength);
ARROW_LOG(DEBUG) << "SQLForeignKeysW called with stmt: " << stmt
<< ", pKCatalogName: " << static_cast<const void*>(pKCatalogName)
<< ", pKCatalogNameLength: " << pKCatalogNameLength
<< ", pKSchemaName: " << static_cast<const void*>(pKSchemaName)
<< ", pKSchemaNameLength: " << pKSchemaNameLength
<< ", pKTableName: " << static_cast<const void*>(pKTableName)
<< ", pKTableNameLength: " << pKTableNameLength
<< ", fKCatalogName: " << static_cast<const void*>(fKCatalogName)
<< ", fKCatalogNameLength: " << fKCatalogNameLength
<< ", fKSchemaName: " << static_cast<const void*>(fKSchemaName)
<< ", fKSchemaNameLength: " << fKSchemaNameLength
<< ", fKTableName: " << static_cast<const void*>(fKTableName)
<< ", fKTableNameLength: " << fKTableNameLength;
return ODBC::ODBCStatement::ExecuteWithDiagnostics(stmt, SQL_ERROR, [=]() {
throw driver::odbcabstraction::DriverException("SQLForeignKeysW is not implemented",
"IM001");
Expand Down Expand Up @@ -270,12 +271,13 @@ SQLRETURN SQL_API SQLPrimaryKeys(SQLHSTMT stmt, SQLWCHAR* catalogName,
SQLSMALLINT catalogNameLength, SQLWCHAR* schemaName,
SQLSMALLINT schemaNameLength, SQLWCHAR* tableName,
SQLSMALLINT tableNameLength) {
LOG_DEBUG(
"SQLPrimaryKeysW called with stmt: {}, catalogName: {}, "
"catalogNameLength: "
"{}, schemaName: {}, schemaNameLength: {}, tableName: {}, tableNameLength: {}",
stmt, fmt::ptr(catalogName), catalogNameLength, fmt::ptr(schemaName),
schemaNameLength, fmt::ptr(tableName), tableNameLength);
ARROW_LOG(DEBUG) << "SQLPrimaryKeysW called with stmt: " << stmt
<< ", catalogName: " << static_cast<const void*>(catalogName)
<< ", catalogNameLength: " << catalogNameLength
<< ", schemaName: " << static_cast<const void*>(schemaName)
<< ", schemaNameLength: " << schemaNameLength
<< ", tableName: " << static_cast<const void*>(tableName)
<< ", tableNameLength: " << tableNameLength;
return ODBC::ODBCStatement::ExecuteWithDiagnostics(stmt, SQL_ERROR, [=]() {
throw driver::odbcabstraction::DriverException("SQLPrimaryKeysW is not implemented",
"IM001");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ std::shared_ptr<FlightSqlSslConfig> LoadFlightSslConfigs(
AsBool(connPropertyMap, FlightSqlConnection::USE_SYSTEM_TRUST_STORE)
.value_or(SYSTEM_TRUST_STORE_DEFAULT);

// GH-47630: find co-located TLS certificate if `trusted certs` path is not specified
auto trusted_certs_iterator =
connPropertyMap.find(std::string(FlightSqlConnection::TRUSTED_CERTS));
auto trusted_certs = trusted_certs_iterator != connPropertyMap.end()
Expand Down
99 changes: 36 additions & 63 deletions cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_driver.cc
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main file to review

Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,45 @@
#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/flight/sql/odbc/odbcabstraction/include/odbcabstraction/spd_logger.h"
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/utils.h"
#include "arrow/util/io_util.h"
#include "arrow/util/logging.h"

#define DEFAULT_MAXIMUM_FILE_SIZE 16777216
#define CONFIG_FILE_NAME "arrow-odbc.ini"
#define CONFIG_FILE_PATH "CONFIG_FILE_PATH"
#define ODBC_LOG_LEVEL "ARROW_ODBC_LOG_LEVEL"

namespace driver {
namespace flight_sql {

using odbcabstraction::Connection;
using odbcabstraction::LogLevel;
using odbcabstraction::OdbcVersion;
using odbcabstraction::SPDLogger;
using arrow::util::ArrowLogLevel;

namespace {
LogLevel ToLogLevel(int64_t level) {
/// Return the corresponding ArrowLogLevel. Debug level is returned by default.
ArrowLogLevel ToLogLevel(int64_t level) {
switch (level) {
case -2:
return ArrowLogLevel::ARROW_TRACE;
case -1:
return ArrowLogLevel::ARROW_DEBUG;
case 0:
return LogLevel::LogLevel_TRACE;
return ArrowLogLevel::ARROW_INFO;
case 1:
return LogLevel::LogLevel_DEBUG;
return ArrowLogLevel::ARROW_WARNING;
case 2:
return LogLevel::LogLevel_INFO;
return ArrowLogLevel::ARROW_ERROR;
case 3:
return LogLevel::LogLevel_WARN;
case 4:
return LogLevel::LogLevel_ERROR;
return ArrowLogLevel::ARROW_FATAL;
default:
return LogLevel::LogLevel_OFF;
return ArrowLogLevel::ARROW_DEBUG;
}
}
} // namespace

namespace driver {
namespace flight_sql {

using odbcabstraction::Connection;
using odbcabstraction::OdbcVersion;

FlightSqlDriver::FlightSqlDriver()
: diagnostics_("Apache Arrow", "Flight SQL", OdbcVersion::V_3), version_("0.9.0.0") {
RegisterLog();
// Register Kernel functions to library
ThrowIfNotOK(arrow::compute::Initialize());
RegisterComputeKernels();
}

std::shared_ptr<Connection> FlightSqlDriver::CreateConnection(OdbcVersion odbc_version) {
Expand All @@ -70,53 +69,27 @@ odbcabstraction::Diagnostics& FlightSqlDriver::GetDiagnostics() { return diagnos

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

void FlightSqlDriver::RegisterLog() {
std::string config_path = arrow::internal::GetEnvVar(CONFIG_FILE_PATH).ValueOr("");
if (config_path.empty()) {
return;
}

odbcabstraction::PropertyMap propertyMap;
driver::odbcabstraction::ReadConfigFile(propertyMap, config_path, CONFIG_FILE_NAME);

auto log_enable_iterator = propertyMap.find(std::string(SPDLogger::LOG_ENABLED));
auto log_enabled = log_enable_iterator != propertyMap.end()
? odbcabstraction::AsBool(log_enable_iterator->second)
: false;
if (!log_enabled.get()) {
return;
}
void FlightSqlDriver::RegisterComputeKernels() {
auto registry = arrow::compute::GetFunctionRegistry();

auto log_path_iterator = propertyMap.find(std::string(SPDLogger::LOG_PATH));
auto log_path = log_path_iterator != propertyMap.end() ? log_path_iterator->second : "";
if (log_path.empty()) {
return;
// 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());
}
}
Comment on lines -85 to +81
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function resolves the kernel registry issue


auto log_level_iterator = propertyMap.find(std::string(SPDLogger::LOG_LEVEL));
auto log_level = ToLogLevel(log_level_iterator != propertyMap.end()
? std::stoi(log_level_iterator->second)
: 1);
if (log_level == odbcabstraction::LogLevel_OFF) {
void FlightSqlDriver::RegisterLog() {
std::string log_level_str = arrow::internal::GetEnvVar(ODBC_LOG_LEVEL).ValueOr("");
if (log_level_str.empty()) {
return;
}
auto log_level = ToLogLevel(std::stoi(log_level_str));

auto maximum_file_size_iterator =
propertyMap.find(std::string(SPDLogger::MAXIMUM_FILE_SIZE));
auto maximum_file_size = maximum_file_size_iterator != propertyMap.end()
? std::stoi(maximum_file_size_iterator->second)
: DEFAULT_MAXIMUM_FILE_SIZE;

auto maximum_file_quantity_iterator =
propertyMap.find(std::string(SPDLogger::FILE_QUANTITY));
auto maximum_file_quantity = maximum_file_quantity_iterator != propertyMap.end()
? std::stoi(maximum_file_quantity_iterator->second)
: 1;

std::unique_ptr<odbcabstraction::SPDLogger> logger(new odbcabstraction::SPDLogger());

logger->init(maximum_file_quantity, maximum_file_size, log_path, log_level);
odbcabstraction::Logger::SetInstance(std::move(logger));
// Enable driver logging. Log files are not supported on Windows yet, since GLOG is not
// tested fully on Windows.
arrow::util::ArrowLog::StartArrowLog("arrow-flight-sql-odbc", log_level);
}

} // namespace flight_sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class FlightSqlDriver : public odbcabstraction::Driver {

void SetVersion(std::string version) override;

/// Register Arrow Compute kernels once.
void RegisterComputeKernels();

void RegisterLog() override;
};

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/flight/sql/odbc/flight_sql/win_system_dsn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "arrow/flight/sql/odbc/flight_sql/include/flight_sql/ui/window.h"
#include "arrow/flight/sql/odbc/flight_sql/system_dsn.h"
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/exceptions.h"
#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/logger.h"
#include "arrow/util/logging.h"

#include <odbcinst.h>
#include <codecvt>
Expand Down Expand Up @@ -87,7 +87,7 @@ bool DisplayConnectionWindow(void* windowParent, Configuration& config,
properties = config.GetProperties();
return true;
} else {
LOG_INFO("Dialog is cancelled by user");
ARROW_LOG(INFO) << "Dialog is cancelled by user";
return false;
}
}
Expand Down
Loading
Loading