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

[BUG] LIKE escape special characters with '\' not working #779

Open
chloe-zh opened this issue Aug 18, 2022 · 5 comments
Open

[BUG] LIKE escape special characters with '\' not working #779

chloe-zh opened this issue Aug 18, 2022 · 5 comments
Labels
bug Something isn't working good first issue Good for newcomers SQL

Comments

@chloe-zh
Copy link
Contributor

chloe-zh commented Aug 18, 2022

What is the bug?
We followed MySQL syntax and tried to escape special character like '%' and '_' with the escape char ‘\', because MySQL uses '\' as the escape character, but seems it does not work.
Our observation only applies to some queries that are pushed down to the DSL.

How can one reproduce the bug?
Example A:

SELECT column1 FROM test_identitifer_2 WHERE column1 LIKE 'testEscape\%'

Explain:

{
  "error": {
    "reason": "Invalid SQL query",
    "details": "Failed to parse request payload",
    "type": "IllegalArgumentException"
  },
  "status": 400
}

Example B:

SELECT column1 FROM test_identitifer_2 WHERE column1 LIKE 'testEscape\\%'

Explain:

{
  "root": {
    "name": "ProjectOperator",
    "description": {
      "fields": "[column1]"
    },
    "children": [
      {
        "name": "ElasticsearchIndexScan",
        "description": {
          "request": """ElasticsearchQueryRequest(indexName=test_identifier_2, sourceBuilder={"from":0,"size":200,"timeout":"1m","query":{"wildcard":{"column1.keyword":{"wildcard":"testEscape\\*","boost":1.0}}},"_source":{"includes":["column1"],"excludes":[]},"sort":[{"_doc":{"order":"asc"}}]}, searchDone=false)"""
        },
        "children": []
      }
    ]
  }
}

What is the expected behavior?
The default escape is expected to work. It would be better if users are able to use alternative escape character e.g.

SELECT column1 FROM test_identitifer_2 WHERE column1 LIKE 'testEscape/%'  ESCAPE '/'

What is your host/environment?

  • OS: Linux
  • Version: AES7.10
  • Plugins: All plugins are enabled by default

Do you have any screenshots?
NA

Do you have any additional context?
NA

Proposal to fix
Add instructions for escape cases to build wildcard query from LIKE: https://github.com/opensearch-project/sql/blob/main/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilder.java#L59

@chloe-zh chloe-zh added bug Something isn't working untriaged labels Aug 18, 2022
@dai-chen
Copy link
Collaborator

@chloe-zh Thanks for reporting the issue with very detailed info. Will check if this can be fixed soon.

@dai-chen dai-chen added good first issue Good for newcomers SQL and removed untriaged labels Aug 22, 2022
@jingyali-apr
Copy link

@chloe-zh Thanks for reporting the issue with very detailed info. Will check if this can be fixed soon.

Hey @dai-chen,
Do we have update for this issue?

Thank you

@dai-chen
Copy link
Collaborator

dai-chen commented Sep 1, 2022

@chloe-zh Thanks for reporting the issue with very detailed info. Will check if this can be fixed soon.

Hey @dai-chen, Do we have update for this issue?

Thank you

@jingyali-apr We haven't worked on this yet. Will evaluate the solution first. Thanks!

@MaxKsyunz
Copy link
Collaborator

MaxKsyunz commented Oct 14, 2022

What version is AES7.10? The sample query is working in most recent SQL plugin.

result from current engine
PS /Users/maxk/inst/act> http :9201/_plugins/_sql format==jdbc query="SELECT Tags FROM sa3dprinting WHERE Tags LIKE 'testEscape\\%'"
HTTP/1.1 200 OK
content-encoding: gzip
content-length: 122
content-type: application/json; charset=UTF-8

{
    "datarows": [],
    "schema": [
        {
            "name": "Tags",
            "type": "text"
        }
    ],
    "size": 0,
    "status": 200,
    "total": 0
}

when legacy engine is forced
PS /Users/maxk/inst/act> http :9201/_plugins/_sql format==json  query="SELECT Tags FROM sa3dprinting WHERE Tags LIKE 'testEscape\\%'"
HTTP/1.1 200 OK
content-encoding: gzip
content-length: 140
content-type: application/json; charset=UTF-8

{
    "_shards": {
        "failed": 0,
        "skipped": 0,
        "successful": 1,
        "total": 1
    },
    "hits": {
        "hits": [],
        "max_score": null,
        "total": {
            "relation": "eq",
            "value": 0
        }
    },
    "timed_out": false,
    "took": 2
}
node details
PS /Users/maxk/inst/act> http :9201
HTTP/1.1 200 OK
content-encoding: gzip
content-length: 346
content-type: application/json; charset=UTF-8

{
    "cluster_name": "docker-cluster",
    "cluster_uuid": "qP59y9QBTHGfysGkijDm-w",
    "name": "opensearch-node-230",
    "tagline": "The OpenSearch Project: https://opensearch.org/",
    "version": {
        "build_date": "2022-09-09T00:07:12.137133581Z",
        "build_hash": "6f6e84ebc54af31a976f53af36a5c69d474a5140",
        "build_snapshot": false,
        "build_type": "tar",
        "distribution": "opensearch",
        "lucene_version": "9.3.0",
        "minimum_index_compatibility_version": "7.0.0",
        "minimum_wire_compatibility_version": "7.10.0",
        "number": "2.3.0"
    }
}
explain from current engine
PS /Users/maxk/inst/act> http :9201/_plugins/_sql/_explain format==jdbc query="SELECT Tags FROM sa3dprinting WHERE Tags LIKE 'testEscape\\%'"
HTTP/1.1 200 OK
content-encoding: gzip
content-length: 335
content-type: application/json; charset=UTF-8

{
    "root": {
        "children": [
            {
                "children": [],
                "description": {
                    "request": "OpenSearchQueryRequest(indexName=sa3dprinting, sourceBuilder={\"from\":0,\"size\":200,\"timeout\":\"1m\",\"query\":{\"wildcard\":{\"Tags\":{\"wildcard\":\"testEscape\\\\\\\\*\",\"boost\":1.0}}},\"_source\":{\"includes\":[\"Tags\"],\"excludes\":[]},\"sort\":[{\"_doc\":{\"order\":\"asc\"}}]}, searchDone=false)"
                },
                "name": "OpenSearchIndexScan"
            }
        ],
        "description": {
            "fields": "[Tags]"
        },
        "name": "ProjectOperator"
    }
}

@Yury-Fridlyand
Copy link
Collaborator

Maybe it was fixed by #696

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers SQL
Projects
None yet
Development

No branches or pull requests

5 participants