Repository navigation
GH-47721: [C++][FlightRPC] Return ODBC Column Attribute from result set - #48050
Conversation
|
|
44deffe to
f3e267e
Compare
|
@lidavidm Draft PR is ready for review 🙂 |
|
@alinaliBQ sorry but do you mind just undrafting PRs when they are ready? That way it pings me automatically and if I approve, I can merge directly |
| return true; | ||
| default: | ||
| return false; | ||
| return true; |
There was a problem hiding this comment.
Won't this give a bad result on non-numeric types? (Maybe the right answer is to throw?)
There was a problem hiding this comment.
In any case, there's is_unsigned_integer in type_traits.h...I don't see why listing out the signed types explicitly here makes any difference if you aren't going to throw for non-numeric types
There was a problem hiding this comment.
Now using arrow::is_unsigned_integer() instead.
We don't want to throw an exception for non-numeric types because we expect all the columns of a result set to hit this logic regardless of type. Returning false for non-numerics is the desired behavior.
| } | ||
|
|
||
| std::string FlightSqlResultSetMetadata::GetTypeName(int column_position) { | ||
| std::string FlightSqlResultSetMetadata::GetTypeName(int column_position, int data_type) { |
There was a problem hiding this comment.
Is there a more precise type we can use than int?
| void CheckSQLColAttributes(SQLHSTMT stmt, SQLUSMALLINT idx, | ||
| const std::wstring& expected_column_name, | ||
| SQLLEN expected_data_type, SQLLEN expected_display_size, | ||
| SQLLEN expected_prec_scale, SQLLEN expected_length, | ||
| SQLLEN expected_column_size, SQLLEN expected_column_scale, | ||
| SQLLEN expected_column_nullability, SQLLEN expected_searchable, | ||
| SQLLEN expected_unsigned_column) { |
There was a problem hiding this comment.
Is the difference just which attributes are checked? Is there any better way to name this? Otherwise I think they should just be overloads of the same function
There was a problem hiding this comment.
No this is testing a different ODBC API. The earlier function was testing SQLColAttribute (singular attribute) while this one is testing SQLColAttributes (plural attributes). Understandably this difference is very easy to miss.
Hi @lidavidm I was out of office yesterday, will reply to your comment on #46099 (comment). Please see my reply in #46099 (comment) |
4395e8a to
d46ee0c
Compare
|
@lidavidm Please take another look. |
d46ee0c to
e2a3362
Compare
|
Turning PR back to draft state since there is a dependency on SQLExecDirect API implementation. PR can still be reviewed |
e2a3362 to
630a544
Compare
630a544 to
02ac357
Compare
02ac357 to
d92a1a8
Compare
d92a1a8 to
93b300d
Compare
Use nullptr explicitly instead of 0 Co-Authored-By: alinalibq <alina.li@improving.com> Co-Authored-By: justing-bq <justin.gossett@improving.com>
`metadata_map_` would be nullptr if `metadata_map` is null. Downstream might assume `metadata_map_` is always non-null, so it is safer to create an empty map if `metadata_map` is null.
93b300d to
05e08e6
Compare
| ColumnMetadata::ColumnMetadata( | ||
| std::shared_ptr<const arrow::KeyValueMetadata> metadata_map) | ||
| : metadata_map_(std::move(metadata_map)) {} | ||
| std::shared_ptr<const arrow::KeyValueMetadata> metadata_map) { | ||
| metadata_map_ = std::move(metadata_map ? metadata_map | ||
| : std::make_shared<arrow::KeyValueMetadata>()); | ||
| } |
There was a problem hiding this comment.
In the original implementation, metadata_map_ would be nullptr if metadata_map is null. Downstream might assume metadata_map_ is always non-null, so it is safer to create an empty map if metadata_map is null.
|
Hi! seems like the build is broken from this change https://github.com/apache/arrow/actions/runs/20586860759/job/59124745454?pr=48683. |
| std::shared_ptr<const arrow::KeyValueMetadata> metadata_map) | ||
| : metadata_map_(std::move(metadata_map)) {} | ||
| std::shared_ptr<const arrow::KeyValueMetadata> metadata_map) { | ||
| metadata_map_ = std::move(metadata_map ? metadata_map |
There was a problem hiding this comment.
Seem like this line is the issue (https://github.com/apache/arrow/actions/runs/20586321192/job/59123338759).
There was a problem hiding this comment.
ack, I was questioning that line and should've checked the CI...let's revert for now
There was a problem hiding this comment.
oh actually I was creating a followup. do you mind holding on a sec?
This reverts commit 16de220.
|
After merging your PR, Conbench analyzed the 3 benchmarking runs that have been run so far on merge-commit 16de220. There weren't enough matching historic benchmark results to make a call on whether there were regressions. The full Conbench report has more details. |
…sult set (apache#48050) ### Rationale for this change Implement ODBC to return column attribute values from the result set ### What changes are included in this PR? - SQLColAttribute & Tests ### Are these changes tested? Tested on local MSVC ### Are there any user-facing changes? N/A * GitHub Issue: apache#47721 Authored-by: Alina (Xi) Li <alina.li@improving.com> Signed-off-by: David Li <li.davidm96@gmail.com>
…ring attributes with the wide decoder (#50853) ### Rationale for this change Two string attributes in the ODBC driver are decoded with the byte-wise decoder even when the value arrives through a wide (Unicode / `*W`) entry point, so the wide buffer is misread and corrupted. `ODBCConnection::SetConnectAttr(SQL_ATTR_CURRENT_CATALOG)` had its two decode branches swapped: ```cpp if (is_unicode) { SetAttributeUTF8(value, string_length, catalog); // byte-wise } else { SetAttributeSQLWCHAR(value, string_length, catalog); // wide } ``` `is_unicode` selects the buffer **width**: a unicode (`*W`) call passes a wide `SQLWCHAR` buffer that must be decoded with `SetAttributeSQLWCHAR`; a non-unicode call passes a byte string decoded with `SetAttributeUTF8`. With the branches swapped, a wide catalog name (e.g. UTF-16 `"my_catalog"`) is reinterpreted byte-wise and stored with the wide encoding's embedded NULs (`"m\0y\0_\0c\0a\0t\0a\0l\0o\0g\0"`), so catalog scoping operates on a corrupt name. This is the inverse of the mapping the getter already uses: `GetStringAttribute` maps `is_unicode -> GetAttributeSQLWCHAR`. `ODBCDescriptor::SetField(SQL_DESC_NAME)` is the same class of bug: it unconditionally used the byte-wise `SetAttributeUTF8`, even though the matching getter (`GetField` / `SQL_DESC_NAME`) reads the field back with `GetAttributeSQLWCHAR`. **How this happened (history):** - The `SQL_ATTR_CURRENT_CATALOG` branches were swapped from the start, in the original driver import (GH-46522, #40939). Note the getter side was written against the shared `GetStringAttribute` helper (which decides width in one place and got it right), while the setter open-coded the branch inline and inverted the polarity — there is no matching `SetStringAttribute` helper. - The descriptor `SQL_DESC_NAME` case was originally *consistent* (getter and setter both byte-wise). GH-47721 (#48050) later migrated the descriptor string getters to the wide `GetAttributeSQLWCHAR` for correct Unicode column attributes, but left the `SQL_DESC_NAME` setter on the byte-wise decoder, creating the asymmetry. ### What changes are included in this PR? - `odbc_connection.cc`: swap the `SQL_ATTR_CURRENT_CATALOG` decode branches so a unicode call uses `SetAttributeSQLWCHAR` and a non-unicode call uses `SetAttributeUTF8`, matching `GetStringAttribute`. - `odbc_descriptor.cc`: decode `SQL_DESC_NAME` with `SetAttributeSQLWCHAR` to match its getter. - `connection_attr_test.cc`: add `TestSQLSetGetConnectAttrCurrentCatalogWide`, a `TYPED_TEST` (mock + remote fixtures) that sets a multi-character catalog through the wide entry point and asserts the full name round-trips back. - `odbc_descriptor_test.cc` (new): add `ODBCDescriptorTest.SetGetNameWideRoundTrips`, a `SetField`/`GetField` round-trip on `SQL_DESC_NAME` with a multi-character wide name. There is no `SQLSetDescField` entry point in this tree, so this covers the descriptor change with a direct unit test on `ODBCDescriptor`. ### Are these changes tested? Yes. Each change has a round-trip test that distinguishes the fixed and unfixed code: | check | result | |---|---| | catalog test, **with** fix (mock fixture) | PASS — `out_catalog == "my_catalog"` | | catalog test, **without** fix (mock fixture) | FAIL — `out_catalog == "m\0y\0_\0c\0a\0t\0a\0l\0o\0g\0"` | | descriptor test, **with** fix | PASS — name reads back as `"my_column"` | | descriptor test, **without** fix | FAIL — byte-wise decode corrupts the stored UTF-16 | | `arrow-odbc-spi-impl-test` (unit suite) | 85/85 pass | | `ConnectionAttributeTest/0.*` (mock suite) | 25/25 pass | | clang-format | clean on all changed files | The connection catalog test uses the mock fixture (`FlightSQLODBCMockTestBase`, an in-process SQLite Flight SQL server); its remote variant runs when `ARROW_FLIGHT_SQL_ODBC_CONN` is set. The descriptor test is a standalone unit test. Verified locally against the mock fixture and the unit suite. ### Are there any user-facing changes? Yes. A catalog name (and descriptor `SQL_DESC_NAME`) set through the wide entry point is now decoded correctly instead of being corrupted. Applications that set a multi-character catalog through `SQLSetConnectAttrW` now scope to the intended catalog. ### AI usage Per the [AI-generated code guidance](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code): the diagnosis, the fix, and the test were produced with the assistance of an AI coding agent and reviewed and verified by me. Correctness was checked by (1) confirming the getter path (`GetStringAttribute`) maps `is_unicode` to the wide decoder, establishing the intended mapping the setters violated, and (2) running the new round-trip test against both the fixed and unfixed driver to confirm it distinguishes them (clean name vs. embedded-NUL corruption). --- _🤖 Drafted by Claude Code (an AI agent) and reviewed & verified by vikrantpuppala._ * GitHub Issue: #50852 Lead-authored-by: Vikrant Puppala <vikrant.puppala@databricks.com> Co-authored-by: Isaac Signed-off-by: David Li <li.davidm96@gmail.com>
Rationale for this change
Implement ODBC to return column attribute values from the result set
What changes are included in this PR?
Are these changes tested?
Tested on local MSVC
Are there any user-facing changes?
N/A