-
Notifications
You must be signed in to change notification settings - Fork 2
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
Preserve columns names when SELECT * and JOIN #268
Conversation
src/sql/relation.rs
Outdated
.field_inputs() | ||
.map(|(f, i)| (i, f.into())) | ||
.collect(); | ||
let composed_columns = all_columns.and_then(join_columns.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are you using this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure to understand, here the only difference from before is that the name of join columns which I change it from new_columns
to join_columns
src/sql/relation.rs
Outdated
.collect(); | ||
composed_columns.and_then(original_not_ambiguous_columns) | ||
} else { | ||
composed_columns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're relying on the previously defined composed column here ? It's a bit hard to read
@@ -251,6 +251,7 @@ impl<'a, T: QueryToRelationTranslator + Copy + Clone> VisitedQueryRelations<'a, | |||
fn try_from_table_with_joins( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is becoming too complex, can you try to split it in independent sub-functions with explicit names ?
src/relation/rewriting.rs
Outdated
.chain(self.field_inputs().filter_map(|(name, id)| { | ||
}).collect::<Vec<_>>(); | ||
|
||
let fields_not_in_vec = self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really obscure, can you separate well between name preservation and collision management?
src/hierarchy.rs
Outdated
/// It creates a new hierarchy with elements for which the tail of their | ||
/// path is not ambiguous. In the new hierarchy, only the tails of the original | ||
/// path are used as a path. | ||
pub fn non_ambiguous_tails(&self) -> Hierarchy<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this from this file
It fixes this issue.
The fix:
When constructing the relation from the ast query, we pass a parameter
preserve_input_names: bool
totry_from_tables_with_joins
and then totry_from_table_with_joins
depending weather the there is a Wildcard in the SelectItem or not.In
try_from_table_with_joins
after the Join (that is created as usual with automatically generated names for fields) a Map is also created where ifpreserve_input_names
is True the original fields names of the Join inputs inserted back but only if they don't create naming collision.Notice that if
SELECT * FROM tableA JOIN tableB USING(id)
theid
column name can be found as a field name along with all the other non ambiguous original column names in the resulting relation whereasSELECT * FROM tableA JOIN tableB ON(tableA.id=tableB.id)
theid
field name is no longer present anymore since it is ambiguous, however. the field will still be present but with a generated field name.