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

LEFT JOIN with WHERE doesn't filter the result as expected #124

@penghuo

Description

@penghuo

Issue
The WHERE clause doesn't filter out the null value from right table after LEFT JOIN.

LEFT JOIN query

GET /_opendistro/_sql/?
{
  "query": "SELECT * FROM dog D LEFT JOIN account A ON D.holdersName = A.firstname WHERE A.firstname = 'Hattie'"
}

Sample Data

// dog index
{"index":{"_type": "dog", "_id":"1"}}
{"dog_name":"rex","holdersName":"Daenerys","age":2}
{"index":{"_type": "dog", "_id":"6"}}
{"dog_name":"snoopy","holdersName":"Hattie","age":4}

// account index
{"index":{"_type": "account", "_id":"6"}}
{"account_number":6,"balance":5686,"firstname":"Hattie","lastname":"Bond","age":36}

Actual Result

    "hits": [
      {
        "_type": "dog|account",
        "_id": "6|6",
        "_score": "-Infinity",
        "_source": {
          "D.age": 4,
          "D.holdersName": "Hattie",
          "A.lastname": "Bond",
          "D.dog_name": "snoopy",
          "A.balance": 5686,
          "A.firstname": "Hattie",
          "A.age": 36,
        }
      },
      {
        "_type": "dog|null",
        "_id": "1|0",
        "_score": "-Infinity",
        "_source": {
          "D.dog_name": "rex",
          "D.age": 2,
          "D.holdersName": "Daenerys"
        }
      }
    ]

Expected Result

    "hits": [
      {
        "_type": "dog|account",
        "_id": "6|6",
        "_score": "-Infinity",
        "_source": {
          "D.age": 4,
          "D.holdersName": "Hattie",
          "A.lastname": "Bond",
          "D.dog_name": "snoopy",
          "A.balance": 5686,
          "A.firstname": "Hattie",
          "A.age": 36,
        }
      }
    ]

Metadata

Metadata

Assignees

Labels

SQLbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions