Skip to content

GH-49482: [C++][FlightRPC][ODBC] Fix inconsistent SQLGetInfo values in global connection - #50021

Open
vanshaj2023 wants to merge 9 commits into
apache:mainfrom
vanshaj2023:fix/GH-49482-fix-sqlgetinfo-inconsistent-values
Open

GH-49482: [C++][FlightRPC][ODBC] Fix inconsistent SQLGetInfo values in global connection#50021
vanshaj2023 wants to merge 9 commits into
apache:mainfrom
vanshaj2023:fix/GH-49482-fix-sqlgetinfo-inconsistent-values

Conversation

@vanshaj2023

@vanshaj2023 vanshaj2023 commented May 22, 2026

Copy link
Copy Markdown
Contributor

What changed

  • SQL_DDL_SCHEMA case now reads the boolean scalar to conditionally set SQL_DROP_SCHEMA and SQL_CREATE_SCHEMA to 0 when unsupported, instead of always writing non-zero values
  • SQL_DDL_TABLE case applies the same pattern for SQL_DROP_TABLE and SQL_CREATE_TABLE
  • SQL_CATALOG_AT_START changed to use SetDefaultIfMissing so it does not overwrite SQL_CATALOG_LOCATION already set by ARROW_SQL_CATALOG_TERM, eliminating an ordering-dependent conflict
  • Removed per-test connect/disconnect workarounds and converted three tests from ConnectionInfoHandleTest back to ConnectionInfoTest

How to test

  • Build ODBC tests and run TestSQLGetInfoCatalogLocation, TestSQLGetInfoDropSchema, TestSQLGetInfoDropTable with both mock server and global connection fixture
  • All three tests should pass consistently regardless of connection reuse

Closes #49482

@lidavidm lidavidm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR!

Also CC @alinaliBQ

Comment on lines +398 to +399
bool supported =
reinterpret_cast<BooleanScalar*>(scalar->child_value().get())->value;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we can use checked_cast from arrow/util/checked_cast.h?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems there's some failing tests - some more test cases need updating?

@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels May 25, 2026
Copilot AI lite review requested due to automatic review settings May 25, 2026 14:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_SCHEMA and SQL_DDL_TABLE to determine SQL_DROP_SCHEMA, SQL_CREATE_SCHEMA, SQL_DROP_TABLE, and SQL_CREATE_TABLE.
  • Avoid overwriting SQL_CATALOG_LOCATION when previously set, by using SetDefaultIfMissing.
  • Replace reinterpret_cast<BooleanScalar*> with checked_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.

@github-actions github-actions Bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels May 25, 2026
@vanshaj2023

vanshaj2023 commented May 25, 2026

Copy link
Copy Markdown
Contributor Author

Hi @lidavidm,
Thanks for the review! I've addressed both comments switched to checked_cast and updated the DropSchema/DropTable test expectations to SQL_DS_DROP_SCHEMA/SQL_DT_DROP_TABLE since the mock sends true for both DDL flags. CI failures are a pre-existing flake unrelated to this change.

@vanshaj2023
vanshaj2023 requested review from Copilot and lidavidm May 25, 2026 14:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@alinaliBQ alinaliBQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@vanshaj2023 To ensure maximum coverage, please build and run the ODBC tests locally against a Dremio docker instance with documentation here:

## Steps to Run the ODBC tests
After ODBC has been registered, you can run the ODBC tests. It is recommended to run the ODBC tests locally first.

Comment on lines 496 to -497
transactions_supported =
reinterpret_cast<BooleanScalar*>(scalar->child_value().get())->value;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

@alinaliBQ

Copy link
Copy Markdown
Collaborator

@justing-bq please review future updates.

@vanshaj2023

Copy link
Copy Markdown
Contributor Author

Thanks @alinaliBQ! Fixed both issues
qualified checked_cast with using arrow::internal::checked_cast; to match the convention used elsewhere in flight/sql, and switched the DropSchema/DropTable tests back to TYPED_TEST(ConnectionInfoTest, ...). I'll run the tests against a Dremio Docker instance and report back.

@vanshaj2023
vanshaj2023 requested a review from Copilot May 26, 2026 12:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@vanshaj2023
vanshaj2023 requested a review from alinaliBQ May 27, 2026 20:58
@alinaliBQ

alinaliBQ commented May 27, 2026

Copy link
Copy Markdown
Collaborator

@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?

@manyiResearch

Copy link
Copy Markdown

Hi, just a quick question — since this PR also seems related to #49500, does it resolve that issue too? Thanks!

@lidavidm

lidavidm commented Jul 1, 2026

Copy link
Copy Markdown
Member

@vanshaj2023 can you rebase this PR?

@vanshaj2023
vanshaj2023 force-pushed the fix/GH-49482-fix-sqlgetinfo-inconsistent-values branch from 8ac407a to 7a68a25 Compare August 2, 2026 22:20
Copilot AI review requested due to automatic review settings August 2, 2026 22:20
@alinaliBQ

Copy link
Copy Markdown
Collaborator

There are 2 failures in C++ Extra / ODBC Linux against the dremio instance:

[  FAILED  ] 2 tests, listed below:
[  FAILED  ] ConnectionInfoTest/1.TestSQLGetInfoDropTable, where TypeParam = arrow::flight::sql::odbc::FlightSQLODBCRemoteTestBase
[  FAILED  ] ConnectionInfoRemoteTest.TestSQLGetInfoDropSchema

 2 FAILED TESTS

And could you fix the Dev / Lint C++ failure as well?

Dremio does not report table or schema DDL support any more than the
SQLite mock does, so split TestSQLGetInfoDropTable per backend too.
Copilot AI review requested due to automatic review settings August 6, 2026 06:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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() uses unordered_map::emplace(), which will never overwrite an existing key. Since info_ already contains SQL_CATALOG_LOCATION from the constructor (and is also defaulted in LoadDefaultsForMissingEntries()), this block will never update the value based on SQL_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 alinaliBQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I have one comment for TestSQLGetInfoDropSchema, other comments are out of scope for this PR but helpful info

Comment thread cpp/src/arrow/flight/sql/odbc/tests/connection_info_test.cc Outdated
GetInfo(this->conn, SQL_DROP_TABLE, &value);

// The Dremio backend does not report table DDL support.
EXPECT_EQ(static_cast<SQLUINTEGER>(0), value);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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) for SQL_CREATE_TABLE
  • TEST_F(ConnectionInfoRemoteTest, TestSQLGetInfoCreateSchema) for SQL_CREATE_SCHEMA
    Theoretically these tests should also return 0 to signal table and schema DDL is not supported in Dremio instance. It also explains why we were only seeing inconsistencies in SQL_DROP_TABLE and SQL_DROP_SCHEMA.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I raised #50828 for this

Co-authored-by: Alina (Xi) Li <96995091+alinaliBQ@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 6, 2026 17:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vanshaj2023
vanshaj2023 requested a review from alinaliBQ August 6, 2026 17:24
Comment thread cpp/src/arrow/flight/sql/odbc/tests/connection_info_test.cc Outdated
Comment on lines +764 to +769
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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can be removed

SQLUINTEGER value;
GetInfo(this->conn, SQL_DROP_SCHEMA, &value);

// SQLite (the mock backend) does not support schema DDL.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we can change the comment to mention both SQLite and Dremio

Co-authored-by: Alina (Xi) Li <96995091+alinaliBQ@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 6, 2026 17:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings August 6, 2026 17:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vanshaj2023

Copy link
Copy Markdown
Contributor Author

@alinaliBQ thanks for the suggestions and for catching my typo-fix. Pushed 870e231:

  • Removed the now-duplicate ConnectionInfoRemoteTest.TestSQLGetInfoDropSchema since TYPED_TEST(ConnectionInfoHandleTest, TestSQLGetInfoDropSchema) already covers both backends.
  • Updated the comment to mention both SQLite and Dremio.

Left TestSQLGetInfoDropTable as separate mock/remote TEST_Fs since those two backends genuinely disagree on the value (mock expects SQL_DT_DROP_TABLE, remote expects 0), so it can't be consolidated the same way.

Also noted #50828 for the missing remote CreateTable/CreateSchema coverage, thanks for filing that separately.

@vanshaj2023
vanshaj2023 requested a review from alinaliBQ August 6, 2026 17:33
@alinaliBQ

Copy link
Copy Markdown
Collaborator

The code change looks good, pending ODBC CI workflow re-run: https://github.com/apache/arrow/actions/runs/31123496079?pr=50021
Looks like the CI failed due to connection issue.

@lidavidm

lidavidm commented Aug 6, 2026

Copy link
Copy Markdown
Member

GitHub had an outage. May want to rebase, I tried restarting the jobs but they did not run.

Comment thread cpp/src/arrow/flight/sql/odbc/tests/connection_info_test.cc Outdated
Co-authored-by: Alina (Xi) Li <96995091+alinaliBQ@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 7, 2026 16:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@alinaliBQ alinaliBQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+1. LGTM, the CI failures look unrelated.

@alinaliBQ

Copy link
Copy Markdown
Collaborator

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

@vanshaj2023

Copy link
Copy Markdown
Contributor Author

Thanks @alinaliBQ really appreciate the careful review and your helpful suggestions which helps me to fix the issue...

@alinaliBQ

Copy link
Copy Markdown
Collaborator

@vanshaj2023 You're welcome! Glad that I was able to help

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.

[C++][FlightRPC][ODBC] Fix inconsistent values in SQLGetInfo in global connection

5 participants