-
Notifications
You must be signed in to change notification settings - Fork 218
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
Approach for expressions in from
#919
Comments
Unfortunately, I don't think this is possible. From requires an ident, because it is later used as prefix for all column names. I.e.
When age is encountered, it is resolved as
Even though Just a peek behind the scenes: From is actually an identity function. It's only function is that it resolves its argument in "table namespace" - so it cannot resolve into a column or a function. |
Right, very good point. One approach that is a) awkward and b) only covers some cases — is to make a CTE out of the s-string: from s"SELECT * FROM employees WHERE foo > 5" would compile to: with _31 as (
SELECT * FROM employees WHERE foo > 5
)
SELECT * FROM _31 ...and then the columns are on But it only covers some cases — it doesn't cover the dbt case: from s'"foo"."employees"' ...which needs to be treated like the literal
We could make a guess (i.e. does it have a I still think it's worth doing this for |
Yes, sort and group are a differnet story. Similar, but possible to implement. from employees
group age % 10 (aggregate count) ... would resolve to: from employees
derive _tmp = age % 10
group _tmp (aggregate count) ... which would translate to: with _table_0 = (select age % 10 as tmp, * from employees)
select _tmp, count(*)
from _table_0
group by _tmp |
Oh wait, SQL does support expressions in GROUP BY! It's even easier. |
Ah great! Though |
This was closed by #1197 Both: from employees
group age % 10 (aggregate count) ... and ... from s"SELECT * FROM employees WHERE foo > 5" ... now compile correctly. |
That's so awesome, again, @aljazerzen ! Maybe I add some examples to the book? |
Currently
from s"<s-string>"
is not allowed. We'd like to make this possible, both for #918, and because it's a general & orthogonal language feature.As part of that we can also allow broader expressions, such as
from (from y)
. While I don't see this being that useful, it would be useful to generally extend expressions to everywhere; e.g. insort
&group
; sosort (foo * 2)
works.There's some tradeoff between this and Semantic — if we have an s-string there, then we can't really understand where columns come from.
Any thoughts on this tradeoff? Do we have a mode in Semantic that basically shrugs and says "I dunno"?
The text was updated successfully, but these errors were encountered: