elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.6k stars 8.21k forks source link

[ES|QL] Regexp literal AST node improvements #190359

Open vadimkibana opened 2 months ago

vadimkibana commented 2 months ago

When IN or regex LIKE or RLIKE operators are prefixed by NOT modifier, we should keep the original operator name and add the "not" flag to the AST node, instead for changing the operator name.

Currently LIKE and NOT LIKE operators produce two different operator names:

{type: 'function', name: 'like'} // column LIKE "abc"
{type: 'function', name: 'not_like'} // column NOT LIKE "abc"

Instead we could use the same operator name but attach a not flag:

{type: 'function', name: 'like'} // column LIKE "abc"
{type: 'function', name: 'like', not: true} // column NOT LIKE "abc"

This way, when pretty printing ES|QL query from AST, we could just print the name property:

return `${node.not ? 'NOT ' : ''}${node.name}`

Now we have to loop through all possible cases:

switch (node.name) {
  case 'like': return 'LIKE';
  case 'not_like': return 'NOT LIKE';
  case 'rlike': return 'RLIKE';
  case 'not_rlike': return 'NOT RLIKE';
}

The same holds for the IN and NOT IN binary operators.

elasticmachine commented 2 months ago

Pinging @elastic/kibana-esql (Team:ESQL)