Skip to content
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

feat: prevent wildcard aliasing #1096

Closed
wants to merge 3 commits into from
Closed

Conversation

MarinPostma
Copy link
Collaborator

This pr prevents wildcard aliasing. This is done in the ensure_column_name method, by checking if the considered column is a wildcard, in which case, we set its name to "*".

This is pretty hacky, by also works with ctes.

Maybe a better approach would be to change ColumnDef to something like:

enum ColumnDef {
    Wildcard,
    Def {
        id: CId,
        name: Option<String>,
        expr: Expr,
    }
}

By my knowledge of the project is not yet good enough to judge all the implications.

I haven't re-enabled any tests yet, it makes more sense to do that once #1094 is merged.

@MarinPostma MarinPostma changed the base branch from main to semantic October 29, 2022 20:55
@MarinPostma MarinPostma changed the title Prevent wildcard aliasing feat: prevent wildcard aliasing Oct 29, 2022
@MarinPostma MarinPostma marked this pull request as ready for review October 29, 2022 21:52
@max-sixty
Copy link
Member

(I've seen this but I think @aljazerzen by far the better reviewer — IIUC he is traveling but is back quite soon)

@max-sixty
Copy link
Member

Maybe a better approach would be to change ColumnDef to something like:

I agree, this is also similar to the proposal for now name resolution would work; now outlined in the internals in the book. But yes let's see what @aljazerzen thinks

Copy link
Member

@aljazerzen aljazerzen left a comment

Choose a reason for hiding this comment

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

I'll do a refactor and add more info on how to do this.

self.next_col_name_id += 1;
match &def.expr.kind {
ExprKind::ExternRef { variable, .. } if variable == "*" => {
def.name = Some("*".into());
Copy link
Member

Choose a reason for hiding this comment

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

This is clever but a bit hacky. Passing a "*" does indeed prevent alias to be emitted, because it uses rule that SQL assumes alias from ident names only, so we omit explicit alias.

If we don't want to rely on this rule, I have to do a little refactor.

@aljazerzen
Copy link
Member

Hey, my little refactor got out of hand :D I ended up doing exactly what you suggested @MarinPostma . I wanted to give more directions on how to do it, but it ended up being very connected to many different parts of the compiler, which is not ideal for onboarding.

This is the commit that partially does this:
4aae055

And this is the other part:
fd5b5c4

@aljazerzen aljazerzen closed this Nov 8, 2022
@max-sixty
Copy link
Member

@MarinPostma thanks for the effort — we're v happy to have you as a regular contributor, and there's much more to do!

@max-sixty max-sixty deleted the no-alias-wildcard branch January 8, 2023 19:11
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.

3 participants