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

[FEATURE] Support conditional count in PPL #1075

Open
penghuo opened this issue Feb 26, 2025 · 2 comments
Open

[FEATURE] Support conditional count in PPL #1075

penghuo opened this issue Feb 26, 2025 · 2 comments
Labels
enhancement New feature or request Lang:PPL Pipe Processing Language support

Comments

@penghuo
Copy link
Collaborator

penghuo commented Feb 26, 2025

Is your feature request related to a problem?
currently, PPL does not support conditional count. for instance, source=tbl | stats count_if(age > 18)

What solution would you like?

  • PostgreSQL support, FILTER clause, for instance, select count(*) FILTER (WHERE age > 18) FROM tbl. This is a SQL-specific implementation that doesn't fit into the PPL design.
  • Kusto support countif aggregation, for instance, tbl | summarize countIf(age>18). It is preferred solution.
  • Splunk support eval in aggregation, for instance, source=tbl | stats count(eval(age>18)). Semantically, this approach is not ideal—eval(age > 18) returns a boolean value, and counting the boolean results would yield the same count as if no filter were applied.

What alternatives have you considered?
Using condition function, NULLIF / IF / CASE with count, and NULL value should ignored by count, for instance, source=tbl | stats count(NULLIF(age < 18))

@LantaoJin
Copy link
Member

Seems no difference between source=tbl | stats count_if(age > 18) and source=tbl | where age > 18 | stats count()

@penghuo
Copy link
Collaborator Author

penghuo commented Feb 27, 2025

Seems no difference between source=tbl | stats count_if(age > 18) and source=tbl | where age > 18 | stats count()

count_if can help query include multiple aggregation functions, for instance, source=tbl | stats avg(age), count_if(age > 18)`

@seankao-az seankao-az added Lang:PPL Pipe Processing Language support and removed untriaged labels Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Lang:PPL Pipe Processing Language support
Projects
None yet
Development

No branches or pull requests

3 participants