Open YANG-DB opened 2 months ago
@LantaoJin I'll be happy to get your feedback here
The CASE
function is very useful whatever in SQL or PPL. I think we need it in PPL.
Simple is one of important design concepts of PPL, it would be redundant to completely copy the SQL syntax in PPL. Instead of adding the WHEN
, THEN
, ELSE
and END
keywords, I prefer to replace the branches with list of predicate-value
pairs. My proposal of CASE
function is:
CASE(<predicate1>, <value1>, [<predicate2>, <value2>, ...] [ELSE] <default>)
ELSE
could be optional, removing it will save an additional keyword in PPL. It is also more like a function than a clause.
The example in description could be change to
source = my_index
| eval status_category =
case(status_code >= 200 AND status_code < 300, 'Success',
status_code >= 300 AND status_code < 400, 'Redirection'
status_code >= 400 AND status_code < 500, 'Client Error'
status_code >= 500, 'Server Error',
'Unknown')
| stats count() by status_category
@LantaoJin thanks for your comments - I agree this is more pipeline oriented
and looks in corespondent to other PPL commands
@penghuo @dai-chen - LMK what you think ...
Is your feature request related to a problem? Current
CASE
functionality syntax is only available in SQL query, this functionality is important for actual use cases for Observability and in addition more general cases where evalCASE
add helpful functionality to the query.Examples:
The next example shows the case function evaluates the HTTP error codes stored in the error field:
The next example shows the case function evaluates the
sort_field
wd
field type stored in the field:Existing SQL syntax support has the following definition:
We need the same support for PPL as shown in the above example.
Here is an example based on the existing SQL
case
syntax:What solution would you like?
We need support for PPL
eval CASE
functionality for both:- OpenSearch based PPL engine
https://github.com/opensearch-project/sql/issues/3009
- Spark based PPL engine
Do you have any additional context?