GH-49482: [C++][FlightRPC][ODBC] Fix inconsistent SQLGetInfo values in global connection - #50021
Conversation
lidavidm
left a comment
There was a problem hiding this comment.
Thanks for the PR!
Also CC @alinaliBQ
| bool supported = | ||
| reinterpret_cast<BooleanScalar*>(scalar->child_value().get())->value; |
There was a problem hiding this comment.
Maybe we can use checked_cast from arrow/util/checked_cast.h?
There was a problem hiding this comment.
It seems there's some failing tests - some more test cases need updating?
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Resolves inconsistent return values for several ODBC connection info properties (SQL_CATALOG_LOCATION, SQL_DROP_SCHEMA, SQL_DROP_TABLE) by properly deriving them from Flight SQL boolean info responses, and replaces unchecked reinterpret_cast with checked_cast for scalar conversions.
Changes:
- Use scalar boolean values from
SQL_DDL_SCHEMAandSQL_DDL_TABLEto determineSQL_DROP_SCHEMA,SQL_CREATE_SCHEMA,SQL_DROP_TABLE, andSQL_CREATE_TABLE. - Avoid overwriting
SQL_CATALOG_LOCATIONwhen previously set, by usingSetDefaultIfMissing. - Replace
reinterpret_cast<BooleanScalar*>withchecked_cast<BooleanScalar*>and update affected tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| cpp/src/arrow/flight/sql/odbc/odbc_impl/get_info_cache.cc | Derives DDL-related info values from server-provided booleans, guards SQL_CATALOG_LOCATION against overwrite, and switches to checked_cast. |
| cpp/src/arrow/flight/sql/odbc/tests/connection_info_test.cc | Updates tests to reflect corrected behavior, moving some tests from ConnectionInfoHandleTest to ConnectionInfoTest/ConnectionInfoMockTest. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi @lidavidm, |
There was a problem hiding this comment.
Hi @vanshaj2023 thanks for raising the PR. Please build and test ODBC locally first.
FYI - Once these 2 PRs are merged, ODBC will be tested against a Dremio instance in the Linux CI. This might be helpful.
There was a problem hiding this comment.
@vanshaj2023 To ensure maximum coverage, please build and run the ODBC tests locally against a Dremio docker instance with documentation here:
arrow/cpp/src/arrow/flight/sql/odbc/README.md
Lines 88 to 89 in cd1811b
| transactions_supported = | ||
| reinterpret_cast<BooleanScalar*>(scalar->child_value().get())->value; |
There was a problem hiding this comment.
Please fix the CI build failures from checked_cast in this file:
https://github.com/apache/arrow/actions/runs/26406439067/job/77730895486?pr=50021#step:7:4419
/Users/runner/work/arrow/arrow/cpp/src/arrow/flight/sql/odbc/odbc_impl/get_info_cache.cc:499:19: error: use of undeclared identifier 'checked_cast'; did you mean 'internal::checked_cast'?
499 | checked_cast<BooleanScalar*>(scalar->child_value().get())->value;
| ^~~~~~~~~~~~
| internal::checked_cast
/Users/runner/work/arrow/arrow/cpp/src/arrow/util/checked_cast.h:28:19: note: 'internal::checked_cast' declared here
|
@justing-bq please review future updates. |
|
Thanks @alinaliBQ! Fixed both issues |
|
@lidavidm Folks with maintainer access might need to trigger the C++ Extra CI checks in this PR, could you have a look at the CI? From my end, I can only see: Label when reviewed / Label PRs when reviewed (pull_request_review), not sure why. I see at https://github.com/apache/arrow/actions/workflows/cpp_extra.yml?query=branch%3Afix%2FGH-49482-fix-sqlgetinfo-inconsistent-values, the C++ Extra CI wasn't triggered for the newest commit 8ac407a. @vanshaj2023 Sounds good. How are the local Dremio instance test results? And maybe we could do a new push to get the C++ Extra CIs to run? |
|
Hi, just a quick question — since this PR also seems related to #49500, does it resolve that issue too? Thanks! |
|
@vanshaj2023 can you rebase this PR? |
8ac407a to
7a68a25
Compare
|
There are 2 failures in And could you fix the |
Dremio does not report table or schema DDL support any more than the SQLite mock does, so split TestSQLGetInfoDropTable per backend too.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
cpp/src/arrow/flight/sql/odbc/odbc_impl/get_info_cache.cc:482
SetDefaultIfMissing()usesunordered_map::emplace(), which will never overwrite an existing key. Sinceinfo_already containsSQL_CATALOG_LOCATIONfrom the constructor (and is also defaulted inLoadDefaultsForMissingEntries()), this block will never update the value based onSQL_CATALOG_AT_START, so it doesn't actually serve as a fallback and may not resolve ordering-dependent behavior as intended.
If the goal is “use SQL_CATALOG_AT_START only when ARROW_SQL_CATALOG_TERM didn’t set the location”, consider tracking a local catalog_location_set/saw_catalog_term flag during LoadInfoFromServer() and conditionally assigning info_[SQL_CATALOG_LOCATION] instead of relying on emplace() (or remove the eager initialization of SQL_CATALOG_LOCATION so it can truly be set here).
SetDefaultIfMissing(
info_, SQL_CATALOG_LOCATION,
static_cast<uint16_t>(
checked_cast<BooleanScalar*>(scalar->child_value().get())->value
? SQL_CL_START
alinaliBQ
left a comment
There was a problem hiding this comment.
I have one comment for TestSQLGetInfoDropSchema, other comments are out of scope for this PR but helpful info
| GetInfo(this->conn, SQL_DROP_TABLE, &value); | ||
|
|
||
| // The Dremio backend does not report table DDL support. | ||
| EXPECT_EQ(static_cast<SQLUINTEGER>(0), value); |
There was a problem hiding this comment.
Out of scope of this PR but helpful to mention, there is a gap that 2 tests are missing from the original implementation:
TEST_F(ConnectionInfoRemoteTest, TestSQLGetInfoCreateTable)forSQL_CREATE_TABLETEST_F(ConnectionInfoRemoteTest, TestSQLGetInfoCreateSchema)forSQL_CREATE_SCHEMA
Theoretically these tests should also return0to signal table and schema DDL is not supported in Dremio instance. It also explains why we were only seeing inconsistencies inSQL_DROP_TABLEandSQL_DROP_SCHEMA.
Co-authored-by: Alina (Xi) Li <96995091+alinaliBQ@users.noreply.github.com>
| TEST_F(ConnectionInfoRemoteTest, TestSQLGetInfoDropSchema) { | ||
| SQLUINTEGER value; | ||
| GetInfo(this->conn, SQL_DROP_SCHEMA, &value); | ||
|
|
||
| // The Dremio backend does not report schema DDL support either. | ||
| EXPECT_EQ(static_cast<SQLUINTEGER>(0), value); |
| SQLUINTEGER value; | ||
| GetInfo(this->conn, SQL_DROP_SCHEMA, &value); | ||
|
|
||
| // SQLite (the mock backend) does not support schema DDL. |
There was a problem hiding this comment.
we can change the comment to mention both SQLite and Dremio
Co-authored-by: Alina (Xi) Li <96995091+alinaliBQ@users.noreply.github.com>
|
@alinaliBQ thanks for the suggestions and for catching my typo-fix. Pushed 870e231:
Left Also noted #50828 for the missing remote |
|
The code change looks good, pending ODBC CI workflow re-run: https://github.com/apache/arrow/actions/runs/31123496079?pr=50021 |
|
GitHub had an outage. May want to rebase, I tried restarting the jobs but they did not run. |
Co-authored-by: Alina (Xi) Li <96995091+alinaliBQ@users.noreply.github.com>
alinaliBQ
left a comment
There was a problem hiding this comment.
+1. LGTM, the CI failures look unrelated.
|
Just a heads-up that after this PR, I probably won't have much bandwidth for additional reviews due to some other commitments. Thanks! cc @lidavidm |
|
Thanks @alinaliBQ really appreciate the careful review and your helpful suggestions which helps me to fix the issue... |
|
@vanshaj2023 You're welcome! Glad that I was able to help |
What changed
SQL_DDL_SCHEMAcase now reads the boolean scalar to conditionally setSQL_DROP_SCHEMAandSQL_CREATE_SCHEMAto0when unsupported, instead of always writing non-zero valuesSQL_DDL_TABLEcase applies the same pattern forSQL_DROP_TABLEandSQL_CREATE_TABLESQL_CATALOG_AT_STARTchanged to useSetDefaultIfMissingso it does not overwriteSQL_CATALOG_LOCATIONalready set byARROW_SQL_CATALOG_TERM, eliminating an ordering-dependent conflictConnectionInfoHandleTestback toConnectionInfoTestHow to test
TestSQLGetInfoCatalogLocation,TestSQLGetInfoDropSchema,TestSQLGetInfoDropTablewith both mock server and global connection fixtureCloses #49482