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

SQL: using a normalized field in a GROUP BY throws an unexpected error #35200

Closed
astefan opened this issue Nov 2, 2018 · 5 comments
Closed
Labels
:Analytics/SQL SQL querying >bug Team:QL (Deprecated) Meta label for query languages team v6.4.4

Comments

@astefan
Copy link
Contributor

astefan commented Nov 2, 2018

This is valid for ES 6.4.2.

ES 6.5 and 7.x don't have this behavior, but there were changes in the way indices mappings are picked up and combined together as part of #34718.

Normalized fields shouldn't be allowed for groupings (aggregations), sorting and comparisons and a proper error message should be issued when this happens. But, a different error message is posted:

{
  "error": {
    "root_cause": [
      {
        "type": "query_shard_exception",
        "reason": "failed to find field [user.user] and [missing_bucket] is not set",
        "index_uuid": "6Wr_vO16TGahy3WhBQW_xg",
        "index": "test"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "test",
        "node": "qLp6GtalRIWMGkm2608rng",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to find field [user.user] and [missing_bucket] is not set",
          "index_uuid": "6Wr_vO16TGahy3WhBQW_xg",
          "index": "test"
        }
      }
    ]
  },
  "status": 400
}

Test data:

DELETE /test
PUT /test
{
  "settings": {
    "analysis": {
      "normalizer": {
        "my_normalizer": {
          "type": "custom",
          "filter": [
            "lowercase",
            "asciifolding"
          ]
        }
      }
    }
  },
  "mappings": {
    "test": {
      "properties": {
        "user": {
          "type": "keyword",
          "normalizer": "my_normalizer"
        }
      }
    }
  }
}

POST /_xpack/sql
{
  "query": "select user from test group by user"
}
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

@jimczi
Copy link
Contributor

jimczi commented Nov 6, 2018

Normalized fields shouldn't be allowed for groupings (aggregations), sorting and comparisons and a proper error message should be issued when this happens.

Why ? It's a keyword field so it should work even if a normalizer is set. The only difference is that the values in the doc_values are normalized.

The error message failed to find field [user.user] and [missing_bucket] is not set means that user.user does not exist in the mapping of the targeted index. I wonder why missing_bucket is not set though, null should be a valid group in SQL, right ?

@astefan
Copy link
Contributor Author

astefan commented Nov 6, 2018

@jimczi A normalized field has its value potentially changed (simplest example - lowercasing) and doing groupings (aggregations) will create buckets for the terms themselves and return those. SQL, on the other hand, is about exact values (the ones user used to index the document with) and getting back normalized values will break this rule.

@matriv
Copy link
Contributor

matriv commented Mar 30, 2020

@elastic/es-ql

@astefan astefan self-assigned this Apr 6, 2020
@astefan astefan removed their assignment Apr 16, 2020
@rjernst rjernst added the Team:QL (Deprecated) Meta label for query languages team label May 4, 2020
@matriv
Copy link
Contributor

matriv commented Jun 15, 2021

Closing as for 7.x is not an issue:

Inserted 3 docs:

PUT test/_doc/1
{
  "user": "BÀR"
}

PUT test/_doc/2
{
  "user": "bar"
}

PUT test/_doc/3
{
  "user": "baz"
}

and the query returns:

      user   
---------------
bar            
baz            

@matriv matriv closed this as completed Jun 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/SQL SQL querying >bug Team:QL (Deprecated) Meta label for query languages team v6.4.4
Projects
None yet
Development

No branches or pull requests

5 participants