8000 Fix #380, bug in code that reads Enums by fotonick · Pull Request #454 · duckdb/duckdb-rs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix #380, bug in code that reads Enums #454

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

Closed
wants to merge 2 commits into from
Closed

Conversation

fotonick
Copy link
Contributor
@fotonick fotonick commented Mar 4, 2025

In turning a ValueRef::Enum to a Value, the code was inappropriately indexing with the row index directly into the dictionary's string array, so iterating any query's results was effectively just listing the Enum variants in order until row index > number of variants and it panicked. Fix by getting the row/col value (the dictionary key) and using that to index into the dictionary's string array.

You can see it in all three branches of the match statement at value_ref.rs#L245. These call DictionaryArray.values(), whose docstring says clearly that it returns the dictionary values.

Note that this code was covered by a test, but the expected value was hardcoded incorrectly to make the previous implementation pass. Proof that the old expected value was incorrect and the new one is correct:

D SELECT medium_enum FROM test_all_types();
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                                 medium_enum                                                                  │
│ enum('enum_0', 'enum_1', 'enum_2', 'enum_3', 'enum_4', 'enum_5', 'enum_6', 'enum_7', 'enum_8', 'enum_9', 'enum_10', 'enum_11', 'enum_12', …  │
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ enum_0                                                                                                                                       │
│ enum_299                                                                                                                                     │
│ NULL                                                                                                                                         │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

fotonick added 2 commits March 4, 2025 00:51
In turning a ValueRef to a Value, the code was indexing with the row index directly into the dictionary's string array, so iterating any query's results was effectively just listing the Enum variants in order until row index > number of variants and it panicked. Fix by getting the row value (key) and using that to index into the dictionary's string array.
The test tests for correct value extraction, based on built-in examples in DuckDB. The old expected value was flatly incorrect, as can be seen in duckdb directly with `SELECT medium_enum FROM test_all_types();`.
@fotonick
Copy link
Contributor Author
fotonick commented Mar 4, 2025

I should mention that cargo test --features bundled passes, as does ASAN_OPTIONS=detect_leaks=1 ASAN_SYMBOLIZER_PATH=/opt/homebrew/Cellar/llvm/19.1.7/bin/llvm-symbolizer cargo test --features bundled -- --nocapture.

@Maxxen
Copy link
Member
Maxxen commented Mar 12, 2025

Hello! Thanks a lot for the PR! I've included these changes as part of #462, so I'm going to go ahead and close this.

@Maxxen Maxxen closed this Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0