Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
43 changes: 0 additions & 43 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2280,46 +2280,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

--------------------------------------------------------------------------------
The files cpp/src/arrow/vendored/whereami/whereami.h,
cpp/src/arrow/vendored/whereami/whereami.cc are adapted from
Grégory Pakosz's whereami library (https://github.com/gpakosz/whereami)
It is dual licensed under both the WTFPLv2 and MIT licenses.

The WTFPLv2 License
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
1. Bla bla bla
2. Montesqieu et camembert, vive la France, zut alors!

The MIT License (MIT)
Copyright Gregory Pakosz

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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.
40 changes: 21 additions & 19 deletions cpp/src/arrow/flight/sql/odbc/entry_points.cc
Original file line number Diff line number Diff line change
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);
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);
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);
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
99 changes: 36 additions & 63 deletions cpp/src/arrow/flight/sql/odbc/flight_sql/flight_sql_driver.cc
Copy link
Copy Markdown
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 @@ -19,47 +19,46 @@
#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/logger.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"

#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
Copy Markdown
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
Loading
Loading