-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-46574: [C++][FlightRPC] ODBC Driver Connectivity support #47971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-46574: [C++][FlightRPC] ODBC Driver Connectivity support #47971
Conversation
|
|
f28ed1f to
8ad5b6a
Compare
* 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
b5159a7 to
fc95da6
Compare
|
Rebased onto Edit: getting segfault error, looking into it. |
| #include "arrow/flight/sql/odbc/odbc_impl/platform.h" | ||
|
|
||
| #include "arrow/flight/sql/odbc/odbc_impl/config/configuration.h" | ||
| #include "arrow/result.h" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
There was a problem hiding this comment.
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`
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| /// @return the DSN or an empty string if the DSN is not found or is found after the | ||
| /// driver |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #endif | |
| #endif // defined(_WIN32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
f8f48a3 to
1c34565
Compare
alinaliBQ
left a comment
There was a problem hiding this 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
| ARROW_FLIGHT_SQL: ON | ||
| ARROW_FLIGHT_SQL_ODBC: ON | ||
| ARROW_FLIGHT_SQL_ODBC: OFF | ||
| ARROW_GANDIVA: ON |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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`
|
Please take another look @lidavidm |
* 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]>
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.
a9eae88 to
cfcc956
Compare
|
@lidavidm All comments have been addressed, please let me know if you have other feedback, thank you! |
|
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. |
### 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]>
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:
Are these changes tested?
Tested locally on MSVC Windows.
Are there any user-facing changes?
N/A