-
Notifications
You must be signed in to change notification settings - Fork 228
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
Join should not include columns twice #1138
Comments
I'm going to start tagging issues that we're relying on the If anyone needs a fix urgently to unblock them, please post and I can try and rush something. Some will be possible, some less so... (CC @aljazerzen, hope that's OK your end) |
(I'm ok with tagging semantic) Unfortunately, this is not possible in general, at least not without knowledge of table DDL. A counter example is this: from first_table
select [some_index, foo]
join second_table [some_index]
join third_table [some_index] which would, in your proposal, probably translate to: SELECT
*
FROM
first_table
JOIN second_table USING(some_index)
JOIN third_table USING(some_index) But this includes all columns from first_table too, even though we wanted only I know that current behavior is not ergonomic at all, because results contains basically three copies of Fortunately, upcomming language changes on |
The changeI added "self equality" operator from first_table
join second_table [~some_index] which translates to: SELECT
first_table.*
second_table.*
FROM first_table
JOIN second_table ON first_table.some_index = second_table.some_index It does not translate to USING, but to The reasonWe currently have custom behavior on I may be able to get around this limitation by extending rules on functions, but I'm not sure if this is possible. It's a small language change, but I want your opinions on it anyway, @max-sixty @snth . I think it's unfortunate consequence that reduces ergonomics of the language a little, but is tolerable compared to upsides that it brings. |
I will need to ponder this a bit as I don't know enough about the resolving behaviour to understand what you mean by
In the example from first_table
select [some_index, foo]
join second_table [some_index]
join third_table [some_index] , can it not turn the first two rows into a CTE and then use the What if in from first_table
derive [some_index=first_index, foo]
join second_table [some_index]
join third_table [some_index] The current playground version translates this to: SELECT
first_table.*,
first_table.foo,
second_table.*,
third_table.*,
some_index
FROM
first_table
JOIN second_table USING(some_index)
JOIN third_table USING(some_index) which seems wrong to me since in my hypothetical example I'd also like to highlight that for a I don't know if this is much help but that's all that I could think of for now. |
With "normal functions" I mean that we resolve their arguments the same way as we resolve arguments to any other function. Which allows you to define things like: func left_join_by_name right_tbl filter left_tbl -> (
join side:left right_tbl [left_tbl.name == right_tbl.name] left_tbl
)
from a
left_join_by_name b More about that is written here.
Like so? WITH _table_0 AS (
SELECT *
FROM first_table
JOIN second_table USING(some_index)
)
SELECT *
FROM _table_0
JOIN third_table USING(some_index) This still has the problem in (and disregard current implementation, it has many problem like this)
Good point. That's another reason to include both columns in the table after join. (which does not happen if we compile to |
Regarding the CTE example, what I envisioned was from first_table
select [some_index, foo]
join second_table [some_index]
join third_table [some_index] turning into WITH _table_0 AS (
SELECT
some_index,
foo
FROM first_table
)
SELECT *
FROM _table_0
JOIN second_table USING(some_index)
JOIN third_table USING(some_index) and from first_table
derive [some_index=first_index, foo]
join second_table [some_index]
join third_table [some_index] turning into WITH _table_0 AS (
SELECT
first_index AS some_index,
foo
FROM first_table
)
SELECT *
FROM _table_0
JOIN second_table USING(some_index)
JOIN third_table USING(some_index) I tend to write the joins out manually and haven't used |
Ah, yeah that does make sense and would work! It's not the easiest to implement, though. In any case, it's not needed if we stop compiling to USING. I too haven't used |
Update: original issue has been circumvented with semantic branch, which now compiles: from first_table
join side:left second_table [~some_index] ... to ... SELECT
first_table.*,
second_table.*
FROM
first_table
LEFT JOIN second_table ON first_table.some_index = second_table.some_index We have discussed new behavior of join and self equality operator on the call and we will be adopting this new behavior in 0.3 release and possibly amend it in patch releases. |
Self equality is now discussed in #1168 |
Consider
which currently outputs
but probably should output
The text was updated successfully, but these errors were encountered: