[Console] Fix nested sql lexer rules (#217571)

Fixes https://github.com/elastic/kibana/issues/204963

## Summary

This PR fixes the SQL lexer rules which, previously, recognized a single
`/` as a start of comment, which is not a valid SQL syntax. According to
the [SQL
docs](https://docs.oracle.com/cd/B14117_01/server.101/b10759/sql_elements006.htm),
there are only two types of comments - the single-line one that starts
with `--` and the multi-line one that starts with `/*` and ends with
`*/`.

**What this fixes:**
Nested SQL script in Console that contains the `/` character was
incorrectly highlighted as a comment and was messing up the highlighting
of the rest of the request.

Test with the following request. Make sure that the SQL script in the
`"query"` object is highlighted correctly as well as the rest of the
request.

```
PUT _watcher/watch/ec_alerts_dependency_check
{
  "trigger": {
    "schedule": {
      "interval": "1m"
    }
  },
  "input": {
    "chain": {
      "inputs": [
        {
          "initial_search": {
            "search": {
              "request": {
                "indices": ["ec_alerts"],
                "body": {
                  "query": {
                    "bool": {
                      "must_not": [
                        {
                          "exists": {
                            "field": "case_id"
                          }
                        }
                      ]
                    }
                  },
                  "size": 1,
                  "_source": ["dependent.service.name"]
                }
              }
            }
          }
        },
        {
          "dependent_search": {
            "search": {
              "request": {
              "indices": ["ec_alerts"],
              
              "body": {
                //"_source": ["alert","service.name","dependend.service.name"],
                "size": 999,
                "query": {
                  "query_string": {
                       "query": """
                       {{#ctx.payload.initial_search.hits.hits.0._source.dependent}}
                       {{#service.name}}({{.}}) OR {{/service.name}}{{/ctx.payload.initial_search.hits.hits.0._source.dependent}} ({{ctx.payload.initial_search.hits.hits.0._source.dependent.0.service.name.0}})""",
                    "default_field": "service.name"

                    }
                }
                }
              }
            }
          }
        }
      ]
    }
  },
  "condition": {
    "compare": {
      "ctx.payload.initial_search.hits.total": {
        "gt": 0
      }
    }
  },
  "actions": {
    "log_results": {
      "logging": {
        "text": "Found related alerts: {{ctx.payload.dependent_search.hits.total}}"
      }
    }
  }
}
```
This commit is contained in:
Elena Stoeva 2025-04-15 11:59:27 +01:00 committed by GitHub
parent 7ffe810fc4
commit 401b76e5eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 3 deletions

View file

@ -186,6 +186,7 @@ export const builtinFunctions = [
'WEIGHTED_AVG',
];
// These ESQL lexer rules are only used for highlighting nested ESQL in Console requests
export const lexerRules = {
defaultToken: 'invalid',
ignoreCase: true,
@ -206,9 +207,8 @@ export const lexerRules = {
},
],
[/[()]/, '@brackets'],
[/--.*$/, 'comment'],
[/\/\/.*$/, 'comment'],
[/\/\*/, 'comment', '@comment'],
[/\/.*$/, 'comment'],
[/".*?"/, 'string'],

View file

@ -221,7 +221,6 @@ export const lexerRules = {
[/[()]/, '@brackets'],
[/--.*$/, 'comment'],
[/\/\*/, 'comment', '@comment'],
[/\/.*$/, 'comment'],
[/".*?"/, 'string'],