Skip to content

[BUG] SQL query doesn't support different date formats without date casting #2700

Closed

Description

@rupal-bq

What is the bug?
Getting below error for user defined date format

"{\n  \"error\": {\n    \"reason\": \"Invalid SQL query\",\n    \"details\": \"date:03-Jan-24 in unsupported format, please use 'yyyy-MM-dd'\",\n    \"type\": \"SemanticCheckException\"\n  },\n  \"status\": 400\n}"

How can one reproduce the bug?
Steps to reproduce the behavior:

PUT testindex
{
  "mappings" : {
    "properties" :  {
      "release_date" : {
        "type" : "date",
        "format" : "dd-MMM-yy"
      }
    }
  }
}
PUT testindex/_doc/21 
{
  "release_date" : "03-Jan-24"
}
POST _plugins/_sql
{
"query":"select release_date from testindex where release_date='03-Jan-24'"
}

What is the expected behavior?
Query should work without date casting

What is your host/environment?

  • OS: [e.g. iOS]
  • Version [e.g. 22]
  • Plugins

Do you have any screenshots?
If applicable, add screenshots to help explain your problem.

Do you have any additional context?
Add any other context about the problem.

Activity

  1. added
    bug
    on May 30, 2024
  2. changed the title [-][BUG] SQL query doesn't allow different date formats without date casting[/-] [+][BUG] SQL query doesn't support different date formats without date casting[/+] on May 30, 2024
  3. manasvinibs commented on Jun 20, 2024

    @manasvinibs
    Member

    We have one more similar issue reported from users when date in timestamp format in the SQL query is erroring out due to mismatch in the timestamp format between field mapping and the request query -

    Sample query:

    select count(*) from ami where State = 'available' and  Public = 'true' and CallerVersion = "2016-11-15 00:00:00";
    
    select count(*) from ami where State = 'available' and  Public = 'true' and CallerVersion < "2016-11-15 00:00:00";
    

    Error -

    [INFO] 10f0cef3-4159-4c39-84e1-f4ba8b88be97 (Bobcat-29) com.amazonaws.fleetinsightsopensearchcommons.helper.ResponseConvertor: Original SQL response : {
      "error": {
        "reason": "Error occurred in OpenSearch engine: all shards failed",
        "details": "Shard[0]: OpenSearchParseException[failed to parse date field [2016-11-15 00:00:00] with format [strict_date_optional_time||epoch_millis]: [failed to parse date field [2016-11-15 00:00:00] with format [strict_date_optional_time||epoch_millis]]]; nested: IllegalArgumentException[failed to parse date field [2016-11-15 00:00:00] with format [strict_date_optional_time||epoch_millis]]; nested: NotSerializableExceptionWrapper[date_time_parse_exception: Failed to parse with all enclosed parsers];\nShard[1]: OpenSearchParseException[failed to parse date field [2016-11-15 00:00:00] with format [strict_date_optional_time||epoch_millis]: [failed to parse date field [2016-11-15 00:00:00] with format [strict_date_optional_time||epoch_millis]]]; nested: IllegalArgumentException[failed to parse date field [2016-11-15 00:00:00] with format [strict_date_optional_time||epoch_millis]]; nested: NotSerializableExceptionWrapper[date_time_parse_exception: Failed to parse with all enclosed parsers];\nShard[2]: OpenSearchParseException[failed to parse date field [2016-11-15 00:00:00] with format [strict_date_optional_time||epoch_millis]: [failed to parse date field [2016-11-15 00:00:00] with format [strict_date_optional_time||epoch_millis]]]; nested: IllegalArgumentException[failed to parse date field [2016-11-15 00:00:00] with format [strict_date_optional_time||epoch_millis]]; nested: NotSerializableExceptionWrapper[date_time_parse_exception: Failed to parse with all enclosed parsers];\nShard[3]: OpenSearchParseException[failed to parse date field [2016-11-15 00:00:00] with format [strict_date_optional_time||epoch_millis]: [failed to parse date field [2016-11-15 00:00:00] with format [strict_date_optional_time||epoch_millis]]]; nested: IllegalArgumentException[failed to parse date field [2016-11-15 00:00:00] with format [strict_date_optional_time||epoch_millis]]; nested: NotSerializableExceptionWrapper[date_time_parse_exception: Failed to parse with all enclosed parsers];\nShard[4]: OpenSearchParseException[failed to parse date field [2016-11-15 00:00:00] with format [strict_date_optional_time||epoch_millis]: [failed to parse date field [2016-11-15 00:00:00] with format [strict_date_optional_time||epoch_millis]]]; nested: IllegalArgumentException[failed to parse date field [2016-11-15 00:00:00] with format [strict_date_optional_time||epoch_millis]]; nested: NotSerializableExceptionWrapper[date_time_parse_exception: Failed to parse with all enclosed parsers];\n\nFor more details, please send request for Json format to see the raw response from OpenSearch engine.",
        "type": "SearchPhaseExecutionException"
      },
      "status": 400
    }
    

    Root cause -
    Currently for response JDBC format, when term/range query has timestamp field in the sql query, by default we are converting timestamps to epoch time in milliseconds when building query for Opensearch DSL which is causing the above exceptions. Instead for timestamp query string in epoch, we should send parsed formatted timestamp string as it is as part of the query similar to Date format.

    Fixing this issue as part of this PR #2765

  4. added
    v2.16.0
    and removed on Jun 20, 2024
  5. 10 remaining items

  6. aalva500-prog commented on Sep 12, 2025

    @aalva500-prog
    Contributor

    Was this issue fixed here: #2762? Is it okay to close it?

  7. songkant-aws commented on Apr 10, 2026

    @songkant-aws
    Collaborator

    Verified the issue is already fixed by #2762 locally, closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugv2.16.0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions