Skip to content

[BUG] Inconsistent behaviour for date field in nested collection queries #1545

Description

@parked-toes

What is the bug?
When a query contains nested collection (self join) it returns different data and datatype, compared to a "simple" query.

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

  1. Create mapping:
PUT datetype_test
{
  "mappings": {
    "properties": {
      "dateAsDate": {
        "type": "date"
      },
      "longAsDate": {
        "type": "date"
      },      
      "id": {
        "type": "long"
      },
      "projects": {
        "type": "nested", 
        "properties": {
          "name": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword"
              }
            }
          }
        }
      }
    }
  }
}

Note that both date fields are mapped as date, projects is nested

  1. Index data:
POST datetype_test/_bulk?refresh
{"index":{"_id":"1"}}
{"id":3,"dateAsDate":"2023-01-01T00:00:00", "longAsDate": 1672531200000, "projects":[{"name":"SQL Spectrum querying"},{"name":"SQL security"},{"name":"OpenSearch security"}]}
{"index":{"_id":"2"}}
{"id":4,"dateAsDate":"2024-01-01T00:00:00", "longAsDate": 1704067200000, "projects":[]}
{"index":{"_id":"3"}}
{"id":6,"dateAsDate":"2025-01-01T00:00:00","longAsDate": 1735689600000, "projects":[{"name":"SQL security"},{"name":"Hello security"}]}
  1. Query date fields using simple query:
SELECT t.dateAsDate,
       t.longAsDate
FROM datetype_test AS t

Result:

{
  "schema": [
    {
      "name": "dateAsDate",
      "type": "timestamp"
    },
    {
      "name": "longAsDate",
      "type": "timestamp"
    }
  ],
  "datarows": [
    [
      "2023-01-01 00:00:00",
      "2023-01-01 00:00:00"
    ],
    [
      "2024-01-01 00:00:00",
      "2024-01-01 00:00:00"
    ],
    [
      "2025-01-01 00:00:00",
      "2025-01-01 00:00:00"
    ]
  ],
  "total": 3,
  "size": 3,
  "status": 200
}

Query the same date fields using nested collection query:

SELECT t.dateAsDate,
       t.longAsDate
FROM datetype_test AS t,
       t.projects AS p
{
  "schema": [
    {
      "name": "dateAsDate",
      "type": "date"
    },
    {
      "name": "longAsDate",
      "type": "date"
    }
  ],
  "total": 3,
  "datarows": [
    [
      "2023-01-01 00:00:00.000",
      1672531200000
    ],
    [
      "2024-01-01 00:00:00.000",
      1704067200000
    ],
    [
      "2025-01-01 00:00:00.000",
      1735689600000
    ]
  ],
  "size": 3,
  "status": 200
}

Note that there is a type change: timestamp -> date in schema and inconsistent resultset field formats.

Moreover, both require inconsistent date format in WHERE clause:

WHERE t.dateAsDate > "2023-05-01T00:00:00Z"

vs

WHERE t.dateAsDate > "2023-05-01 00:00:00"

What is the expected behavior?
All queries return date type in schema and "2025-01-01 00:00:00.000" like format for both date fields as defined in mapping.

What is your host/environment?
2.6.0

Activity

  1. added
    bug
    on Apr 18, 2023
  2. dai-chen commented on Apr 19, 2023

    @dai-chen
    Collaborator

    Thanks for reporting the issue! I think this is caused by inconsistency between our legacy engine and V2 engine. PartiQL feature in second query is not migrated to V2 yet. We're actively working on this and will update once it's available. Thanks!

  3. changed the title [-][BUG] Inconsistend behaviour for date field in nested collection queries[/-] [+][BUG] Inconsistent behaviour for date field in nested collection queries[/+] on Apr 26, 2023
  4. added
    v2.19.0
    on Nov 15, 2024
  5. andy-k-improving commented on Nov 18, 2024

    @andy-k-improving
    Contributor

    Hi team,
    I'm picking up this.

  6. andy-k-improving commented on Nov 20, 2024

    @andy-k-improving
    Contributor

    Proposed fix submitted under: #3160

  7. reopened this on May 6, 2025
  8. added and removed
    v2.19.0
    on May 6, 2025
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

    SQLbugv3.1.0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions