Skip to content

Conversation

@alinaliBQ
Copy link
Contributor

@alinaliBQ alinaliBQ commented Oct 27, 2025

Rationale for this change

Add ODBC driver connection support for the driver, so the driver can connect to servers.

What changes are included in this PR?

Implementation of unicode APIs:

  • SQLDriverConnect
  • SQLDisconnect
  • SQLConnect
  • DSN Window
  • Test refactoring

Are these changes tested?

Tested locally on MSVC Windows.

Are there any user-facing changes?

N/A

@github-actions
Copy link

⚠️ GitHub issue #46574 has been automatically assigned in GitHub to PR creator.

@github-actions github-actions bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Oct 27, 2025
@alinaliBQ alinaliBQ force-pushed the gh-46574-driver-connectivity branch 2 times, most recently from f28ed1f to 8ad5b6a Compare October 28, 2025 22:29
@alinaliBQ
Copy link
Contributor Author

@lidavidm @kou Changes in this PR are ready for review, please let me know if you have any comments. Thank you! This PR is in draft because it depends on #47763 to get 2 of its tests passing.

alinaliBQ referenced this pull request in Bit-Quill/arrow Oct 29, 2025
* use suggestion from James for one-liner change to return `Status::OK` directly

* fix for iterating endpoints, it is based on JDBC's fix for the same bug

* save value of `FlightClientOptions`

* Use `TestFlightServer`

Add `arrow_flight_sql_shared` to enable usages for `TestFlightServer`

* Fix build errors from missing `gmock`

* Add checks for array data

Update flight_sql_stream_chunk_buffer_test.cc

Add `FlightStreamChunkBufferTest` unit test

Draft test with `FlightSQLODBCMockEndpointTestBase`

* Reference apacheGH-47117 and Clean up code

* Add driver and DSN to built-in properties to not pass driver/dsn as attributes to server

* Allow `=` in values inside connection strings, fixes connectivity problems

* Address comments from Rob
@alinaliBQ alinaliBQ force-pushed the gh-46574-driver-connectivity branch from b5159a7 to fc95da6 Compare October 29, 2025 18:35
@alinaliBQ alinaliBQ marked this pull request as ready for review October 29, 2025 18:36
@alinaliBQ alinaliBQ requested a review from lidavidm as a code owner October 29, 2025 18:36
@alinaliBQ
Copy link
Contributor Author

alinaliBQ commented Oct 29, 2025

Rebased onto master to get changes from #47763

Edit: getting segfault error, looking into it.

@alinaliBQ alinaliBQ marked this pull request as draft October 29, 2025 20:42
#include "arrow/flight/sql/odbc/odbc_impl/platform.h"

#include "arrow/flight/sql/odbc/odbc_impl/config/configuration.h"
#include "arrow/result.h"
Copy link
Member

Choose a reason for hiding this comment

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

nit: if you wanted arrow::Status, just include status.h

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

namespace arrow::flight::sql::odbc {

/// \brief Case insensitive comparator that takes string_view
struct CaseInsensitiveComparatorStrView {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this defined here? It seems to only be used inside the implementation

Copy link
Contributor

Choose a reason for hiding this comment

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

Moved to the .cc file.


// PropertyMap is case-insensitive for keys.
typedef std::map<std::string_view, std::string, CaseInsensitiveComparator> PropertyMap;
typedef std::map<std::string, std::string, CaseInsensitiveComparator> PropertyMap;
Copy link
Member

Choose a reason for hiding this comment

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

With the right definitions, you should be able to avoid wrapping every lookup in std::string. Can we avoid that? (See the note about 'transparent' comparator in https://en.cppreference.com/w/cpp/container/map/find)

Copy link
Contributor

Choose a reason for hiding this comment

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

I've changed it to a transparent comparator and adjusted all the unnecessary std::string() wrapping.

#include "arrow/flight/sql/odbc/odbc_impl/exceptions.h"
#include "arrow/flight/sql/odbc/odbc_impl/platform.h"

namespace ODBC {
Copy link
Member

Choose a reason for hiding this comment

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

(maybe for a separate issue but) can we fix this namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea we can do it for a separate issue. Are we thinking of replacing ODBC with namespace arrow::flight::sql::odbc?

Copy link
Member

Choose a reason for hiding this comment

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

Yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have created issue #48083, @justing-bq please link this issue in the code, thanks!

GH-48083 TODO: replace `namespace ODBC` with `namespace arrow::flight::sql::odbc`

Copy link
Contributor

Choose a reason for hiding this comment

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

Added a link to the github issue.

// Return the number of bytes required for the conversion.
template <typename CHAR_TYPE>
inline size_t ConvertToSqlWChar(const std::string& str, SQLWCHAR* buffer,
inline size_t ConvertToSqlWChar(const std::string_view& str, SQLWCHAR* buffer,
Copy link
Member

Choose a reason for hiding this comment

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

string_view can (and should) be passed by value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

/// \return wchar_msg in std::string format
inline std::string SqlWcharToString(SQLWCHAR* wchar_msg, SQLINTEGER msg_len = SQL_NTS) {
if (msg_len == 0 || !wchar_msg || wchar_msg[0] == 0) {
if (!wchar_msg || wchar_msg[0] == 0 || msg_len == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't you check length before dereferencing the pointer?

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

static std::string GetPropertiesFromConnString(
/// @return the DSN or an empty string if the DSN is not found or is found after the
/// driver
static std::string GetDsnIfExists(const std::string& conn_str);
Copy link
Member

Choose a reason for hiding this comment

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

Would std::optional<std::string> be better?

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

Comment on lines 78 to 79
/// @return the DSN or an empty string if the DSN is not found or is found after the
/// driver
Copy link
Member

Choose a reason for hiding this comment

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

We use \return not @return.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

#if defined _WIN32
// For displaying DSN Window
# include "arrow/flight/sql/odbc/odbc_impl/system_dsn.h"
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#endif
#endif // defined(_WIN32)

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

@alinaliBQ alinaliBQ left a comment

Choose a reason for hiding this comment

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

Will let my teammate Justin help out with the comments cc @justing-bq

Comment on lines 312 to 314
ARROW_FLIGHT_SQL: ON
ARROW_FLIGHT_SQL_ODBC: ON
ARROW_FLIGHT_SQL_ODBC: OFF
ARROW_GANDIVA: ON
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed in #48019, we will try to enable ODBC on MSVC, so I am removing ODBC build from MinGW here

#include "arrow/flight/sql/odbc/odbc_impl/exceptions.h"
#include "arrow/flight/sql/odbc/odbc_impl/platform.h"

namespace ODBC {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have created issue #48083, @justing-bq please link this issue in the code, thanks!

GH-48083 TODO: replace `namespace ODBC` with `namespace arrow::flight::sql::odbc`

@alinaliBQ alinaliBQ marked this pull request as ready for review November 7, 2025 17:56
@justing-bq
Copy link
Contributor

Please take another look @lidavidm

@github-actions github-actions bot added awaiting merge Awaiting merge and removed awaiting change review Awaiting change review labels Nov 10, 2025
@alinaliBQ alinaliBQ requested a review from lidavidm November 10, 2025 23:42
alinaliBQ and others added 10 commits November 12, 2025 11:07
* SQLDriverConnect requires SQLGetInfo to be implemented for tests to pass, because driver manager requires SQLGetInfo

Co-Authored-By: alinalibq <[email protected]>
Co-authored-by: justing-bq <[email protected]>
Iirc, there is segfault error associated with `SQLGetStmtAttrW`

Attempt to fix segfault error by adding impl for `SQLSetConnectAttr`

Part-fix remove `using` that isn't needed
std::string_view doesn't work well with std::map because once the std::string_view object is out of scope, the key is no longer valid. The map then has undefined behavior.

Enabling transparent comparing only helps with the `find` function, not inserts. For inserts we still need to use a std::string constructor.

Ran ODBC tests on MSVC locally and they passed.
@justing-bq justing-bq force-pushed the gh-46574-driver-connectivity branch from a9eae88 to cfcc956 Compare November 12, 2025 19:33
@alinaliBQ
Copy link
Contributor Author

@lidavidm All comments have been addressed, please let me know if you have other feedback, thank you!

@lidavidm lidavidm merged commit 94b9bb6 into apache:main Nov 14, 2025
42 of 45 checks passed
@lidavidm lidavidm removed the awaiting merge Awaiting merge label Nov 14, 2025
@conbench-apache-arrow
Copy link

After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 94b9bb6.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

jduo pushed a commit that referenced this pull request Dec 8, 2025
### Rationale for this change
Putting the tests for diagnostics in a separate PR from
#47763, because non-diagnostic ODBC
APIs are required to get diagnostics.

### What changes are included in this PR?
- Add tests for ODBC diagnostics 

### Are these changes tested?
PR depends on #47971 for tests to
work.

Tested locally. 
### Are there any user-facing changes?
No
* GitHub Issue: #46575

Co-authored-by: rscales <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants