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

max()/min() not supported for String and Date types #227

Closed
jordanw-bq opened this issue Oct 18, 2019 · 2 comments
Closed

max()/min() not supported for String and Date types #227

jordanw-bq opened this issue Oct 18, 2019 · 2 comments
Labels
BI integration Issues for integration with BI tools enhancement New feature or request SQL

Comments

@jordanw-bq
Copy link
Contributor

Using Docker image amazon/opendistro-for-elasticsearch:1.1.0
Dataset: Flights sample data (loaded through Kibana)
SQL Plugin version: 1.1.0.1

Example Query:
SELECT max(Origin) AS usr_Calculation_462181953493630977_nk FROM kibana_sample_data_flights

Result:
Raw response received: {
"error": {
"reason": "Invalid SQL query",
"details": "Function [MAX] cannot work with [KEYWORD]. Usage: MAX(NUMBER T) -> T",
"type": "SemanticAnalysisException"
},
"status": 400
}

Expectation:
Tableau, using other SQL connectors, allows users to use these functions on these types. Adding support for this in Elasticsearch will allow for full support for these functions when used through Tableau.

@dai-chen dai-chen added the BI integration Issues for integration with BI tools label Oct 18, 2019
@dai-chen
Copy link
Member

This exception is thrown from the type checker in semantic analysis. Will disable it to see if we do have the support for max/min on String and Date. If so, that means the type check is too strict and needs to relax for this case. Otherwise we need to add the support before relaxing the restriction.

@dai-chen
Copy link
Member

Just disabled semantic analysis but found ES max aggregation can only work with numeric value. Need to add support for this and add overloaded function spec to type checker in new parser.

Explain for MAX with string:

{
  "from" : 0,
  "size" : 0,
  "_source" : {
    "includes" : [
      "MAX"
    ],
    "excludes" : [ ]
  },
  "aggregations" : {
    "MAX(firstname.keyword)" : {
      "max" : {
        "field" : "firstname.keyword"
      }
    }
  }
}

Exception thrown from ES engine:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Expected numeric type on field [firstname.keyword], but got [keyword]"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "accounts",
        "node": "jn9G8trERRikgYiF3_eVng",
        "reason": {
          "type": "illegal_argument_exception",
          "reason": "Expected numeric type on field [firstname.keyword], but got [keyword]"
        }
      }
    ],
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "Expected numeric type on field [firstname.keyword], but got [keyword]",
      "caused_by": {
        "type": "illegal_argument_exception",
        "reason": "Expected numeric type on field [firstname.keyword], but got [keyword]"
      }
    }
  },
  "status": 400
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
BI integration Issues for integration with BI tools enhancement New feature or request SQL
Projects
None yet
Development

No branches or pull requests

3 participants