elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
69.61k stars 24.64k forks source link

SQL: `id` on `Alias`es should be same if the `Alias`es are semantically equal #64652

Open palesz opened 3 years ago

palesz commented 3 years ago

This problem was discovered during the investigation of the #56013 bug. Namely the following problems were discovered:

(1) SELECT 100, 100 -> success
(2) SELECT ?, ? (with params: 100, 100) -> success
(3) SELECT 100, 100 FROM test -> Unknown output attribute exception for the second 100
(4) SELECT ?, ? FROM test (params: 100, 100) -> Unknown output attribute exception for the second ?
(5) SELECT field1 as "x", field1 as "x" FROM test -> Unknown output attribute exception for the second "x"

There are two separate issues at play here:

  1. Construction of AttributeMaps keeps only one of the Attributes with the same name even if the ids are different (see the AttributeMapTests in this PR). This should be fixed no matter what, we should not overwrite attributes with one another during the construction of the AttributeMap.
  2. The id on the Aliases is not the same in case the Aliases have the same name and same child (meaning they are semantically equal).

For the full explanation and ways we cannot use to fix the second issue, please see: https://github.com/elastic/elasticsearch/pull/63710#issuecomment-721236168

The first issue was fixed as part of #63710 . This issue is to not forget to fix the second one (id reuse).

Take the example (3) above. The Aliases in the projections:

Today How it should look like
100 AS 100#id_1 100 AS 100#id_1
100 AS 100#id_2 100 AS 100#id_1
elasticmachine commented 3 years ago

Pinging @elastic/es-ql (:Query Languages/SQL)

elasticsearchmachine commented 8 months ago

Pinging @elastic/es-analytical-engine (Team:Analytics)