Skip to content

[BUG] Get "mismatched input 'BETWEEN' expecting {<EOF>, ';'}" warning when running a SQL query with BETWEEN function #1115

Closed

Description

@samhamme

Describe the bug
If we run a SQL query that contains the BETWEEN function having the response format set to jdbc then, in the opensearch log, appears a warning message, although the execution was successful:

POST /_plugins/_sql?format=jdbc
{
  "query" : "SELECT `kubernetes.pod.name` as Name, 100 - AVG(kubernetes.volume.fs.used.pct) as Backup_free_space FROM *metricbeat*ccad* WHERE kubernetes.namespace = 'ccad-gch-cadm-analytics-os' AND event.module = 'kubernetes' AND metricset.name = 'volume' AND kubernetes.pod.name LIKE '%-opensearch-data-%' AND kubernetes.volume.name = 'backup-volume' AND @timestamp BETWEEN '2022-11-29T07:00:00Z' AND '2022-11-29T07:15:00Z' GROUP BY 1"
}

{
  "schema": [
    {
      "name": "Name",
      "alias": "Name",
      "type": "double"
    },
    {
      "name": "Backup_free_space",
      "alias": "Backup_free_space",
      "type": "double"
    }
  ],
  "total": 2,
  "datarows": [
    [
      "gch-cadm-os-opensearch-data-0",
      99.986
    ],
    [
      "gch-cadm-os-opensearch-data-1",
      99.986
    ]
  ],
  "size": 2,
  "status": 200
}


[2022-11-29T10:00:02,311][INFO ][o.o.s.l.p.RestSqlAction  ] [gch-cadm-os-opensearch-masters-0] [3bbb13c6-af65-407e-8bf4-b8f3c9f12718] Incoming request /_plugins/_sql?format=jdbc&pretty=true: ( SELECT identifier AS Name, number - AVG(identifier) AS Backup_free_space FROM * metricbeat*ccad* WHERE identifier = 'string_literal' AND identifier = 'string_literal' AND identifier = 'string_literal' AND identifier LIKE 'string_literal' AND identifier = 'string_literal' AND @timestamp BETWEEN 'string_literal' AND 'string_literal' GROUP BY number )
[2022-11-29T10:00:02,353][WARN ][stderr                   ] [gch-cadm-os-opensearch-masters-0] line 1:354 mismatched input 'BETWEEN' expecting {<EOF>, ';'}

Note: The warning message does not appear in case the SQL query is executed using json format.

To Reproduce
Prerequisites:

  1. Have an index with a field for which the BETWEEN function can be used. For example:
PUT /car?pretty
{
    "mappings":{
        "properties": {
            "model" : { "type" : "text" },
            "year": {"type" : "integer"}
        }
    }
}
  1. Add several documents to that index with different values for the field for which the BETWEEN function is applied. For example:
POST car/_doc/1
{
    "model": "Porshe",
    "year": 1972
}

POST car/_doc/2
{
    "model": "Porshe",
    "year": 1973
}

POST car/_doc/3
{
    "model": "Porshe",
    "year": 1974
}

POST car/_doc/4
{
    "model": "Porshe",
    "year": 1975
}

POST car/_doc/5
{
    "model": "Porshe",
    "year": 1976
}

Steps to reproduce the behavior:

  1. Go to Opensearch Dashboards Dev Tools
  2. Execute the following SQL query:
POST /_plugins/_sql?format=jdbc
{
  "query" : "SELECT `year` AS CarYear FROM car WHERE `year` BETWEEN 1972 AND 1975"
}
  1. The response is correctly returned:
{
  "schema": [{
    "name": "year",
    "alias": "CarYear",
    "type": "integer"
  }],
  "total": 4,
  "datarows": [
    [1972],
    [1973],
    [1974],
    [1975]
  ],
  "size": 4,
  "status": 200
}
  1. Go to opensearch log and see the warning message:
[2022-11-29T12:54:51,997][INFO ][o.o.s.l.p.RestSqlAction  ] [gch-cadm-os-opensearch-masters-1] [d33d5d6c-897f-43ab-ada3-b630634b93fb] Incoming request /_plugins/_sql?format=jdbc&pretty=true: ( SELECT identifier AS CarYear FROM table WHERE identifier BETWEEN number AND number )
[2022-11-29T12:54:52,024][WARN ][stderr                   ] [gch-cadm-os-opensearch-masters-1] line 1:47 mismatched input 'BETWEEN' expecting {<EOF>, ';'}

Expected behavior
The warning message should not occur as the execution was successful.
What can be done to not have this warning present in the opensearch log?

OpenSearch Version
2.4.0

Activity

  1. added
    bug
    on Nov 29, 2022
  2. Yury-Fridlyand commented on Nov 29, 2022

    @Yury-Fridlyand
    Collaborator

    Hi,
    Thank you for reporting this. The error goes for the query anonymizer for SQL.
    The plugin has two SQL parsing engines: V2 (the new one) and V1 (legacy). Query anonymizer uses V1 engine, which could fail on some features implemented in V2, but missing in V1.
    Please ignore this error. We have plans to update anonymizer.

  3. dai-chen commented on Dec 12, 2022

    @dai-chen
    Collaborator

    Meanwhile BETWEEN is missing in V2 engine: #172

  4. self-assigned this
    on Dec 14, 2022
  5. added
    v2.5.0
    on Dec 14, 2022
  6. dai-chen commented on Dec 14, 2022

    @dai-chen
    Collaborator

    Published PR for BETWEEN support. Will send separate PR for query anonymizer fix which is reported in other issues too, such as #821.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugv2.5.0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions