to_string and from_string have different behavior for TableReference
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 344
Description
### Describe the bug
`to_string` simply concat components with `.`:
https://github.com/apache/arrow-datafusion/blob/02a470f6061cce8ee8e57f7af8a6a0e0ddc1571b/datafusion/common/src/table_reference.rs#L107-L121
but `from_string` will transform them to lowercase:
https://github.com/apache/arrow-datafusion/blob/02a470f6061cce8ee8e57f7af8a6a0e0ddc1571b/datafusion/common/src/utils.rs#L248-L257
`TableReference` is the most common table identifier for tables. But I don't think converting cases or considering quotes is necessary when the object name becomes `TableReference`. At this stage (i.e., after the initial plan is constructed from AST), those object names should be fixed.
This implicit conversion makes it difficult when handling complex table identifiers. Thus I propose to make `TableReference` as simple as possible and gather all those `to_lower_cases` and "quotes" before generating the very first `TableReference`.
### To Reproduce
```rust
#[test]
fn to_lower_case() {
let table_ref = TableReference::Full {
catalog: Cow::Owned("catalog".to_string()),
schema: Cow::Owned("schema".to_string()),
table: Cow::Owned("TABLE".to_string()),
};
let concatted = table_ref.to_string();
println!("concatted: {}", concatted);
let parsed = TableReference::parse_str(&concatted);
println!("parsed: {:?}", parsed.to_vec());
}
```
The output is
```
concatted: catalog.schema.TABLE
parsed: ["catalog", "schema", "table"]
```
### Expected behavior
```
concatted: catalog.schema.TABLE
parsed: ["catalog", "schema", "TABLE"]
```
### Additional context
(Not sure if this is "bug"...)
Contributor guide
Research direction
Start with datafusion/common/src/table_reference.rs and the referenced parsing logic in datafusion/common/src/utils.rs, then run the reproducing to_lower_case test using TableReference::parse_str. Compare the current to_string and from_string behavior and define tests covering case preservation and quoted or complex identifiers; done means the expected TABLE value survives the round trip.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100