-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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(hogql): hidden aliases for special fields #18725
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This breaks some tests, so will convert to draft and finish Monday. 👋 |
Size Change: 0 B Total Size: 2.01 MB ℹ️ View Unchanged
|
mariusandra
force-pushed
the
hogql-hidden-aliases
branch
from
November 21, 2023 21:19
0572b98
to
8577afc
Compare
mariusandra
force-pushed
the
hogql-hidden-aliases
branch
from
November 21, 2023 21:49
7093fc7
to
bd73de7
Compare
mariusandra
force-pushed
the
resolver-snapshots
branch
from
November 21, 2023 22:15
36b8ffc
to
b16e351
Compare
mariusandra
force-pushed
the
hogql-hidden-aliases
branch
from
November 21, 2023 22:17
2c76907
to
7e8af1a
Compare
…o hogql-hidden-aliases
This is ready for a look! It's blocking a) custom SQL columns, b) PoEv2 with the overrides table, c) Lifecycle insights 😅 |
Gilbert09
approved these changes
Nov 24, 2023
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.
Great test coverage
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The following doesn't work:
because we don't add
AS timestamp
in the generated ClickHouse SQL here when wrapping with a function:This also caused issues with the custom SQL columns I was trying to implement.
Changes
Now this works.
I wrapped each field with a "hidden alias" node, which will be ignored during printing... except if it's the first child of a
select
column.Alternatives
This is not the first implementation of this, nor the only way to do it. An earlier proposal (from @Twixes) was effectively to use dedicated named
columnExpr
nodes for select fields, and only for select fields.I thought about it hard, but in the end decided against it. A columnExpr is effectively just an alias that can be used in one place. It brings clarity in some places, but makes other things messier. I imagine we'd have to rework many places that build select queries from AST nodes. Then it'll also make copying nodes between trees harder, as you'll have to deal with
remove_column_expr
style functions everywhere.All of this would have been doable, but we got most of it for free by reusing aliases... including correct printing, ignoring and type extraction (the
ast.FieldAliasType
was already there and integrated into a lot of places).I hope this is the least evil best of both world approach, but time will tell. I'd personally be happy to merge it in and get the custom SQL column expressions live already :).
How did you test this code?
Wrote tests, adapted old ones, made sure it's all green.