-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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(hog): remove semicolons, require "as" for column aliases #22868
Conversation
It looks like the code of |
It looks like the code of |
It looks like the code of |
Suspect IssuesThis pull request was deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
Problem
One of the biggest subtle improvements in my programming life has been the elimination of semicolons
We're using them in Hog because it made getting started easier, but I'd like to get rid of them. Every Hog developer so far has had many cases of forgetting a semicolon. I'm confident it'll frustrate our users as well.
Changes
Main change
Unchains theRemoves semicolons from Hog:It might not look like much of a difference, but when writing code... it really adds up.
"Side-effect" - breaking HogQL change
A breaking change needs to be made to HogQL if we want to get rid of semicolons. It might not be as painful as it sounds.
This is currently allowed, but soon won't be:
This is how you'll need to write it:
Note: table aliases are unaffected, so this will keep working:
We need to get rid of this
columnExpr alias
rule (and keepcolumnExpr AS alias
), because the parser ignores whitespace and thealias
part often catches the symbol from the next line.let i := 0 while (){...}
is read aslet i := 0 as "while";;{...};
.I've personally almost always write "select bla as bla", and so do our users: out of ~5k saved HogQL insights on US cloud, only 117 of them contain a column alias without the explicit "as". On EU it was 210.
I have now updated all of them and added
" as "
in front of each alias, so there are zero such saved HogQL insights on cloud.How did I get the data and how did I clean it up?
I copy/pasted bits of code that looked something like this into a CLI in production:
When I was sure everything looked good, I saved the changes into the insights.
For example, this insight for us changed from this:
to this:
Thus this should be safe to merge. Is there anything I've missed?
I should probably do the same quick check and conversion as I did for insights.Done.Are we OK rolling it in?
Other changes
return
probably works again (will test in a later PR)Alternatives
We're currently reusing
columnExpr
between Hog and HogQL. It's a huge set of rules. We could duplicate this set: 1) once for Hog without the alias rule, 2) once for HogQL with it... but this sounds messy. I tried and couldn't figure a clean way to split and share part of the rules, going rather deep. We'd effectively need to split the parser into Hog and HogQL modes (we already have HogQL and String Template modes). However that requires duplicating a lot of code.How did you test this code?
Added tests.
TODO: figure out the impact:
Do tests pass?now they doHow many saved insights use this type of aliasing?117 + EUWhat will break if we enable this?funnelsIs this safe to roll out or do we need to split the grammar? There may also be other reasons to split it.safe if editing old insights manually. Will take just a bit of work.update all HogQL insights on EU & US clouds to have "as " in front of the alias