Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Table/Index name alias is breaking where clause #99

Closed
Nitinrajyadav opened this issue Jun 27, 2019 · 5 comments
Closed

Table/Index name alias is breaking where clause #99

Nitinrajyadav opened this issue Jun 27, 2019 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@Nitinrajyadav
Copy link

localhost:9200/_opendistro/_sql/_explain

Query
{ "query": "select slatwallpr0_.activeFlag, slatwallpr0_.calculatedQATS, slatwallpr0_.calculatedTitle, slatwallpr0_.deferredRevenueFlag, slatwallpr0_.productCode, slatwallpr0_.productID from testingagainn slatwallpr0_ where slatwallpr0_.calculatedQATS >500 or slatwallpr0_.calculatedTitle like '%pix%' or slatwallpr0_.productCode like '%pix%' or slatwallpr0_.productID like '%pix%'" }

Response
{"from":0,"size":200,"query":{"bool":{"filter":[{"bool":{"must":[{"bool":{"should":[{"range":{"slatwallpr0_.calculatedQATS":{"from":500,"to":null,"include_lower":false,"include_upper":true,"boost":1.0}}},{"wildcard":{"slatwallpr0_.calculatedTitle":{"wildcard":"*pix*","boost":1.0}}},{"wildcard":{"slatwallpr0_.productCode":{"wildcard":"*pix*","boost":1.0}}},{"wildcard":{"slatwallpr0_.productID":{"wildcard":"*pix*","boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}},"_source":{"includes":["activeFlag","calculatedQATS","calculatedTitle","deferredRevenueFlag","productCode","productID"],"excludes":[]}}

see slatwallpr0_.calculatedTitle, slatwallpr0_.productCode

@Nitinrajyadav Nitinrajyadav changed the title Table name alias is breaking where clause Table/Index name alias is breaking where clause Jun 27, 2019
@abbashus
Copy link
Contributor

Thanks @Nitinrajyadav , can you briefly describe the issue.
What version of plugin are you using?
Can you also share the mappings of testingagainn index?

@Nitinrajyadav
Copy link
Author

Nitinrajyadav commented Jun 28, 2019

@abbashus I'm using open distro 0.9.0
Mappings

 "testingagainn": {
        "aliases": {},
        "mappings": {
            "_doc": {
                "properties": {
                    "activeFlag": {
                        "type": "boolean",
                        "fields": {
                            "raw": {
                                "type": "keyword"
                            }
                        }
                    },
                    "calculatedQATS": {
                        "type": "integer",
                        "fields": {
                            "raw": {
                                "type": "keyword"
                            }
                        }
                    },
                    "calculatedTitle": {
                        "type": "text",
                        "term_vector": "with_positions",
                        "fields": {
                            "raw": {
                                "type": "keyword"
                            }
                        }
                    },
                    "deferredRevenueFlag": {
                        "type": "boolean",
                        "fields": {
                            "raw": {
                                "type": "keyword"
                            }
                        }
                    },
                    "productCode": {
                        "type": "text",
                        "term_vector": "with_positions",
                        "fields": {
                            "raw": {
                                "type": "keyword"
                            }
                        }
                    },
                    "productID": {
                        "type": "text",
                        "term_vector": "with_positions",
                        "fields": {
                            "raw": {
                                "type": "keyword"
                            }
                        }
                    }
                }
            }
        },
        "settings": {
            "index": {
                "creation_date": "1561661937266",
                "number_of_shards": "5",
                "number_of_replicas": "1",
                "uuid": "aa5RGC6WSC2o5_eWOPn7Mg",
                "version": {
                    "created": "6070199"
                },
                "provided_name": "testingagainn"
            }
        }
    }
}

@Nitinrajyadav
Copy link
Author

@abbashus Having the same problem in OpenDistro V-1.0.0.

To explain the problem "When I'm using Index-name alias, the plugin understands the alias.columnName for the SELECT statement it's removing alias and only including columnName (have a look at the response from /_explain API), but for WHERE clause it's treating the alias.columnName as columnName (again have a look at response from /_explain API).

It works, if I change the WHERE clause from WHERE alias.columnName condition to WHERE colunmName condition(notice the missing alias) and leave the select statement as is(Using table-name alias).
I'm getting the expected results for this query.
"select slatwallpr0_.activeFlag, slatwallpr0_.calculatedQATS, slatwallpr0_.calculatedTitle, slatwallpr0_.deferredRevenueFlag, slatwallpr0_.productCode, slatwallpr0_.productID from testingagainn slatwallpr0_ where calculatedQATS >500 or calculatedTitle like '%pix%' or productCode like '%pix%' or productID like '%pix%'".

And to my understanding, the issue looks like it's related to distinguishing b/w
nested-field-name (columnName.nestedPropertyName)
and alias.columnName for WHERE clause.

@abbashus
Copy link
Contributor

abbashus commented Jul 1, 2019

Thanks @Nitinrajyadav for providing details, we will investigate this issue and update the thread.

@abbashus abbashus self-assigned this Jul 23, 2019
@abbashus abbashus added the bug Something isn't working label Jul 24, 2019
@dai-chen
Copy link
Member

This seems a critical issue. Query as simple as below returns incorrect empty response.

POST _opendistro/_sql
{
  "query": "SELECT a.age FROM accounts a WHERE a.age > 0"
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants