Skip to content

[ES|QL] Return correct correct message when a union type field is provided to to_dateperiod or to_timeduration #112668

@fang-xing-esql

Description

@fang-xing-esql

To_DatePeriod and To_TimeDuration only take constants as input, when a union type field is provided to them, the correct error message doesn't return.

Here are the steps to reproduce it:

curl -u elastic:password -H "Content-Type: application/json" "127.0.0.1:9200/test1" -XPUT -d '{
  "mappings": {                                                                                                         
        "properties": {
            "x": {       
                "type": "keyword"
            }
        }
  }
}'
curl -u elastic:password -H "Content-Type: application/json" "127.0.0.1:9200/test2" -XPUT -d '{
  "mappings": {
        "properties": {
            "x": {
                "type": "text"   
            }
        }
  }
}'
curl -u elastic:password -H "Content-Type: application/json" "127.0.0.1:9200/_query?format=txt" -d '{
    "query": "from test* | eval y = now() + to_dateperiod(x)"}
'

"verification_exception","reason":"Found 1 problem\nline 1:45: Cannot use field [x] due to ambiguities being mapped as [2] incompatible types: [keyword] in [test1], [text] in [test2]"}]

To_DatePeriod has an unresolved child, Analyzer's Verifier errors out. However, the real/expected error that the function only takes foldable inputs are not returned, because the check to foldable is deferred to LogicalPlanOptimizer, which is after Analyzer. The correct error message is returned for the other field/data types, this is found for union type field only.

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions