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: Improve handling of geo_shapes in search context #41791

Closed
imotov opened this issue May 3, 2019 · 3 comments
Closed

SQL: Improve handling of geo_shapes in search context #41791

imotov opened this issue May 3, 2019 · 3 comments
Assignees
Labels
:Analytics/Geo Indexing, search aggregations of geo points and shapes :Analytics/SQL SQL querying >bug >docs General docs changes

Comments

@imotov
Copy link
Contributor

imotov commented May 3, 2019

Until #37206 is done we cannot handle any ST_* functions on geo_shapes in the search context, which means that any call to an ST_* function in the WHERE clause or GROUP BY context are going to fail with a confusing runtime the error message that will look like similar to this

{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "runtime error",
        "script_stack": [
          "org.elasticsearch.index.mapper.MappedFieldType.fielddataBuilder(MappedFieldType.java:110)",
          "org.elasticsearch.index.fielddata.IndexFieldDataService.getForField(IndexFieldDataService.java:116)",
          "org.elasticsearch.index.query.QueryShardContext.lambda$lookup$0(QueryShardContext.java:276)",
          "org.elasticsearch.search.lookup.LeafDocLookup$1.run(LeafDocLookup.java:101)",
          "org.elasticsearch.search.lookup.LeafDocLookup$1.run(LeafDocLookup.java:98)",
          "java.base/java.security.AccessController.doPrivileged(Native Method)",
          "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:98)",
          "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:41)",
          "org.elasticsearch.xpack.sql.expression.function.scalar.whitelist.InternalSqlScriptUtils.docValue(InternalSqlScriptUtils.java:74)",
          "org.elasticsearch.xpack.sql.expression.function.scalar.whitelist.InternalSqlScriptUtils.geoDocValue(InternalSqlScriptUtils.java:535)",
          "InternalSqlScriptUtils.nullSafeFilter(InternalSqlScriptUtils.gt(InternalSqlScriptUtils.stX(InternalSqlScriptUtils.geoDocValue(doc,params.v0)),params.v1))",
          "                                                                                                                                        ^---- HERE"
        ],
        "script": "InternalSqlScriptUtils.nullSafeFilter(InternalSqlScriptUtils.gt(InternalSqlScriptUtils.stX(InternalSqlScriptUtils.geoDocValue(doc,params.v0)),params.v1))",
        "lang": "painless"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "geo",
        "node": "h3PSzwPFRT2Cf0KzLUnx5w",
        "reason": {
          "type": "script_exception",
          "reason": "runtime error",
          "script_stack": [
            "org.elasticsearch.index.mapper.MappedFieldType.fielddataBuilder(MappedFieldType.java:110)",
            "org.elasticsearch.index.fielddata.IndexFieldDataService.getForField(IndexFieldDataService.java:116)",
            "org.elasticsearch.index.query.QueryShardContext.lambda$lookup$0(QueryShardContext.java:276)",
            "org.elasticsearch.search.lookup.LeafDocLookup$1.run(LeafDocLookup.java:101)",
            "org.elasticsearch.search.lookup.LeafDocLookup$1.run(LeafDocLookup.java:98)",
            "java.base/java.security.AccessController.doPrivileged(Native Method)",
            "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:98)",
            "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:41)",
            "org.elasticsearch.xpack.sql.expression.function.scalar.whitelist.InternalSqlScriptUtils.docValue(InternalSqlScriptUtils.java:74)",
            "org.elasticsearch.xpack.sql.expression.function.scalar.whitelist.InternalSqlScriptUtils.geoDocValue(InternalSqlScriptUtils.java:535)",
            "InternalSqlScriptUtils.nullSafeFilter(InternalSqlScriptUtils.gt(InternalSqlScriptUtils.stX(InternalSqlScriptUtils.geoDocValue(doc,params.v0)),params.v1))",
            "                                                                                                                                        ^---- HERE"
          ],
          "script": "InternalSqlScriptUtils.nullSafeFilter(InternalSqlScriptUtils.gt(InternalSqlScriptUtils.stX(InternalSqlScriptUtils.geoDocValue(doc,params.v0)),params.v1))",
          "lang": "painless",
          "caused_by": {
            "type": "illegal_argument_exception",
            "reason": "Fielddata is not supported on field [shape] of type [geo_shape]"
          }
        }
      }
    ]
  },
  "status": 400
}

It would be great to improve the error message by failing earlier during the query generation, or at least document this limitation.

@imotov imotov added >bug >docs General docs changes :Analytics/Geo Indexing, search aggregations of geo points and shapes :Analytics/SQL SQL querying labels May 3, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

@imotov imotov self-assigned this May 3, 2019
imotov added a commit to imotov/elasticsearch that referenced this issue May 7, 2019
Improves error messages when geo_shapes are used in unsupported manner
and adds description of current geo function limitations.

Fixes elastic#41791
imotov added a commit that referenced this issue May 9, 2019
Improves error messages when geo_shapes are used in unsupported manner
and adds description of current geo function limitations.

Fixes #41791
@imotov
Copy link
Contributor Author

imotov commented May 9, 2019

Fixed by #41923

@imotov imotov closed this as completed May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/Geo Indexing, search aggregations of geo points and shapes :Analytics/SQL SQL querying >bug >docs General docs changes
Projects
None yet
Development

No branches or pull requests

2 participants