Skip to content
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): nullish coalescing #16276

Merged
merged 1 commit into from
Jun 28, 2023
Merged

feat(hogql): nullish coalescing #16276

merged 1 commit into from
Jun 28, 2023

Conversation

mariusandra
Copy link
Collaborator

@mariusandra mariusandra commented Jun 27, 2023

Problem

Typing ifNull(bla, 0) everywhere is cumbersome. I'm used to so much better from TypeScript.

Changes

Adds ??, so instead of

select length(JSONExtractArrayRaw(ifNull(properties.$active_feature_flags, '[]'))) from events limit 1

you can do

select length(JSONExtractArrayRaw(properties.$active_feature_flags ?? '[]')) from events limit 1

How did you test this code?

I took care to have the operator precedence match what JS does. So 1 + null ?? 2 + 3 translates to (1 + null) ?? (2 + 3), and not 1 + (null ?? 2) + 3.

Copy link
Collaborator

@Twixes Twixes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants