-
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): stringOr ^^ #25638
base: master
Are you sure you want to change the base?
feat(hogql): stringOr ^^ #25638
Conversation
It looks like the code of |
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the |
@@ -1073,6 +1073,7 @@ def compare_types(arg_types: list[ConstantType], sig_arg_types: tuple[ConstantTy | |||
"maxIntersectionsPositionIf": HogQLFunctionMeta("maxIntersectionsPositionIf", 3, 3, aggregate=True), | |||
} | |||
HOGQL_POSTHOG_FUNCTIONS: dict[str, HogQLFunctionMeta] = { | |||
"stringOr": HogQLFunctionMeta("stringOr", 1, None), |
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.
Just commenting here as good as anywhere.
stringOr
sounds really weird to me. Is it truly only for strings? If so then I guess its fine and I assume the naming is coming from logicalOr
? Something like firstNonEmptyString()
is obviously quite verbose but stringOr
didn't mean a whole lot to me at first - could be my lack of common programming terms here.
If it is only for strings then I'm not so sure about adding it as a standard shorthand ^^
(I can't even find that char on my german keyboard 😅 ).
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the |
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the |
This PR was closed due to lack of activity. Feel free to reopen if it's still relevant. |
Problem
We want to easily get the first not empty string in Hog/QL:
In JavaScript:
In Hog:
In HogQL
The only real way to get
banana
is:... but we could do better.
Changes
Introducing
stringOr(null, '', 'banana', 'dingo')
and its shorthand^^
Why
^^
?Looking at my keyboard, I found these underutilised symbols in our language:
! $ % ^ & _ ~
. I excluded symbols that are common bitwise operators or used elsewhere in Hog, and added a bunch of doubles.The question became: which of these is the most natural/obvious?
... and that's how I settled on
^^
How did you test this code?
I didn't yet. This is a WIP in the spirit of "the fastest way to get the right answer is to post the wrong answer on the internet".
To test locally, run
pip install ./hogql_parser
. If you change the^^
inHogQLLexer.g4
and want to play around, runpnpm run grammar:build
followed bypip install ./hogql_parser
.Alternatives
We claim back
||
, however it is a standard SQL concatenation operator. We have advertised it and people are using it in queries, so it'll be a hard fight.