-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat(hogql): handle null properties #15244
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
Conversation
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.
Approved assuming my comment is the case
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.
So I understand - this only fixes it for HogQL?
I tried the filters that weren't working for me and they still don't work so assuming that standard Query stuff is still as is i.e.:
Looks legit. Only thing is my specific issue didn't seem to be solved. Checked it out and ran
// returned results
{
key: '$session_id',
value: '',
operator: 'exact',
type: 'event',
}
// did not return
{
key: '$session_id',
value: 'is_not_set',
operator: 'is_not_set',
type: 'event',
}
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.
Well, it should fix it for just HogQL. However all filters on the "event explorer" page are converted to HogQL. Thus in this case everything should work.
However! This $session_id
is actually stored as a materialized column... and that column is stored without the new nullIf
checks :'(.
A proper fix would require altering the table in an async migration and retroactively changing all these columns as well. However this is above my pay grade right now, so calling in the big guns for support. CC @yakkomajuri
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 |
I think I have the best/worst compromise we can make here.
This will at least unblock us enough to go on with the HogQL public beta launch. |
… hogql-null-handling
Problem
HogQL properties (e.g.
properties.$browser
) are weird:null
, it's returned as the stringnull
This results in an environment where you use
properties.$browser != ''
to check if the field is not set, and can't rely on JSnone
values. Consequently the HogQL-translated "is set" and "is not set" event filters (in use in the event explorer) don't work as those rely onnull
checks.Changes
Both unspecified (
undefined
) andnull
properties are now returned as the SQLnull
.The previous code for property access:
"replaceRegexpAll(JSONExtractRaw(events.properties, '$browser'), '^\"|\"$', '')"
Got replaced with:
"replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$browser'), ''), 'null'), '^\"|\"$', '')"
The new part is
nullIf(nullIf(x, ''), 'null')
. This converts the property to anull
if it's an empty string or the word "null", without quotes.The changes are only in HogQL (including expressions). Nulls are checked differently (
JSONHas
) in non-HogQL filters.How did you test this code?
I added a test case to check the new behaviour.
At first I wanted to just get
undefined
fields to return asnull
, but when adding the testcase I realised also justnull
fields don't work.I validated quickly that I could only read the column once. Even code like
if(properties.x, properties.x, 'null')
slowed down the query significantly. I validated this by running a HogQL query like this on app.posthog.com:Every extra property access resulted in more seconds on average. Only adding
nullIf
-s didn't. My data is however anecdotal and could use double checking.