-
Couldn't load subscription status.
- Fork 3.9k
GH-46098 : [C++][FlightRPC] ODBC Environment Attribute Implementation #47760
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
Conversation
8d6f722 to
5da7b4f
Compare
| namespace arrow::flight::sql::odbc { | ||
|
|
||
| TEST(SQLGetEnvAttr, TestSQLGetEnvAttrODBCVersion) { | ||
| // ODBC Environment |
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, but I don't think these comments add anything
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.
removed
| if (!value_ptr && !str_len_ptr) { | ||
| throw DriverException("Invalid null pointer for attribute.", "HY000"); | ||
| } |
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.
Test this case as well?
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 test DISABLED_TestSQLGetEnvAttrNullValuePointer for this case. The test case is disabled because call to SQLGetEnvAttr is handled by the driver manager on Windows. And the Windows driver manager doesn't error out when null pointer is passed, even though it should.
Potentially this can be tested on mac/linux depending on the driver manager on these systems
| #ifdef _WIN32 | ||
| # include <windows.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.
Should we use cpp/src/arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/platform.h instead?
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.
fixed
| // Allocate an environment handle | ||
| SQLRETURN return_env = SQLAllocEnv(&env); | ||
|
|
||
| EXPECT_EQ(SQL_SUCCESS, return_env); |
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.
Should we use ASSERT_EQ() not EXPECT_EQ()?
Do we need to proceed this test even when this assertion is failed?
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.
fixed to use ASSERT_EQ
| SQLRETURN return_set = | ||
| SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, reinterpret_cast<void*>(SQL_OV_ODBC2), 0); | ||
|
|
||
| EXPECT_EQ(SQL_SUCCESS, return_set); |
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.
Is SQL_SUCCESS expected?
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.
Should we assert set value by SQLGetEnvAttr()?
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 SQL_SUCCESS is expected since the version is supposed to be supported.
Added check for SQLGetEnvAttr
|
|
||
| EXPECT_EQ(SQL_SUCCESS, return_env); | ||
|
|
||
| // Attempt to set to unsupported version |
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.
Is this comment correct?
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.
fixed the comment, thanks good catch
| ARROW_LOG(DEBUG) << "SQLGetEnvAttr called with env: " << env << ", attr: " << attr | ||
| << ", value_ptr: " << value_ptr << ", buffer_length: " << buffer_length | ||
| << ", str_len_ptr: " << static_cast<const void*>(str_len_ptr); |
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.
Can we remove this debug print now?
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 generally log the ODBC API calls for debugging so we know which ODBC APIs got passed to the driver, is it ok to keep these logs?
| if (!value_ptr && !str_len_ptr) { | ||
| throw DriverException("Invalid null pointer for attribute.", "HY000"); | ||
| } |
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.
Should we check this out of this switch?
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.
Probably not in this case. I think attribute needs to be checked first before the pointers, and ODBC needs to error out on attribute value first.
In a case where attribute, value_ptr and str_len_ptr are all invalid, HYC00 (error code for invalid attribute) should be returned first. So we put value_ptr and str_len_ptr check under the switch statement
5da7b4f to
65391da
Compare
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.
Addressed code review comments
| ARROW_LOG(DEBUG) << "SQLGetEnvAttr called with env: " << env << ", attr: " << attr | ||
| << ", value_ptr: " << value_ptr << ", buffer_length: " << buffer_length | ||
| << ", str_len_ptr: " << static_cast<const void*>(str_len_ptr); |
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 generally log the ODBC API calls for debugging so we know which ODBC APIs got passed to the driver, is it ok to keep these logs?
| if (!value_ptr && !str_len_ptr) { | ||
| throw DriverException("Invalid null pointer for attribute.", "HY000"); | ||
| } |
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 test DISABLED_TestSQLGetEnvAttrNullValuePointer for this case. The test case is disabled because call to SQLGetEnvAttr is handled by the driver manager on Windows. And the Windows driver manager doesn't error out when null pointer is passed, even though it should.
Potentially this can be tested on mac/linux depending on the driver manager on these systems
| if (!value_ptr && !str_len_ptr) { | ||
| throw DriverException("Invalid null pointer for attribute.", "HY000"); | ||
| } |
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.
Probably not in this case. I think attribute needs to be checked first before the pointers, and ODBC needs to error out on attribute value first.
In a case where attribute, value_ptr and str_len_ptr are all invalid, HYC00 (error code for invalid attribute) should be returned first. So we put value_ptr and str_len_ptr check under the switch statement
| #ifdef _WIN32 | ||
| # include <windows.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.
fixed
| namespace arrow::flight::sql::odbc { | ||
|
|
||
| TEST(SQLGetEnvAttr, TestSQLGetEnvAttrODBCVersion) { | ||
| // ODBC Environment |
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.
removed
| // Allocate an environment handle | ||
| SQLRETURN return_env = SQLAllocEnv(&env); | ||
|
|
||
| EXPECT_EQ(SQL_SUCCESS, return_env); |
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.
fixed to use ASSERT_EQ
|
|
||
| EXPECT_EQ(SQL_SUCCESS, return_env); | ||
|
|
||
| // Attempt to set to unsupported version |
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.
fixed the comment, thanks good catch
| SQLRETURN return_set = | ||
| SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, reinterpret_cast<void*>(SQL_OV_ODBC2), 0); | ||
|
|
||
| EXPECT_EQ(SQL_SUCCESS, return_set); |
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 SQL_SUCCESS is expected since the version is supposed to be supported.
Added check for SQLGetEnvAttr
65391da to
1395cff
Compare
Co-authored-by: rscales <[email protected]> Add tests for setting and getting environment attributes Address code review comments Co-Authored-By: justing-bq <[email protected]>
1395cff to
c4de836
Compare
|
Rebased on top of |
|
After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 56e3836. There were no benchmark performance regressions. 🎉 The full Conbench report has more details. It also includes information about 11 possible false positives for unstable benchmarks that are known to sometimes produce them. |
Rationale for this change
ODBC driver needs to set and get environment attributes, such as ODBC driver version.
What changes are included in this PR?
Are these changes tested?
Tested locally on Windows MSVC.
Will be tested in CI after #47689 is merged
Are there any user-facing changes?
No