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

[BUG] Incorrect value of quotted nested fields aggregations in JSON export #2529

Open
smortex opened this issue Feb 24, 2024 · 2 comments
Open
Labels
bug Something isn't working

Comments

@smortex
Copy link

smortex commented Feb 24, 2024

What is the bug?

When quoting the field passed to an aggregation and when this field is a nested field, a SQL query with the JSON format return an incorrect value (0 or null) for the aggregation instead of the actual result.

How can one reproduce the bug?

Given an index with documents with a nested (field_nested.c2) and a non-nested field (field_float), using the following two queries to perform some basic aggregations:

  • SELECT sum(`field_float`) AS `SUM(field_float)`, sum(`field_nested.c2`) AS `SUM(field_nested.c2)` FROM data1 LIMIT 5000;
  • SELECT sum(field_float) AS `SUM(field_float)`, sum(field_nested.c2) AS `SUM(field_nested.c2)` FROM data1 LIMIT 5000;

We expect the same result. But when requesting JSON documents, the first query produce wrong values:

First query result:

{    
    "took": 1,    
    "timed_out": false,    
    "_shards": {    
        "total": 1,    
        "successful": 1,    
        "skipped": 0,    
        "failed": 0    
    },    
    "hits": {    
        "total": {    
            "value": 3,    
            "relation": "eq"    
        },    
        "max_score": null,    
        "hits": []    
    },    
    "aggregations": {    
        "SUM(field_nested.c2)": {    
            "value": 0    
        },    
        "SUM(field_float)": {    
            "value": 0.6000000163912773    
        }    
    }    
} 

Second query result:

{    
    "took": 1,    
    "timed_out": false,    
    "_shards": {    
        "total": 1,    
        "successful": 1,    
        "skipped": 0,    
        "failed": 0    
    },    
    "hits": {    
        "total": {    
            "value": 3,    
            "relation": "eq"    
        },    
        "max_score": null,    
        "hits": []    
    },    
    "aggregations": {    
        "SUM(field_nested.c2)": {    
            "value": 6    
        },    
        "SUM(field_float)": {    
            "value": 0.6000000163912773    
        }    
    }    
} 

Note how aggregations."SUM(field_nested.c2)".value is 0 in the first example and 6 it the second.

What is the expected behavior?

Quoted and non-quoted nested fields in aggregations should return the same (correct) value.

What is your host/environment?

  • OS: Debian
  • Version 11
  • OpenSearch 2.12.0

Do you have any additional context?

  • For the bug to happen, the field must be nested and quoted;
  • Only the JSON format is affected, the output of other formats has the expected value;
  • Some aggregations (e.g. sum as in the example above) always return 0, but other (e.g. avg) always return null instead of the actual value.
@smortex smortex added bug Something isn't working untriaged labels Feb 24, 2024
@smortex
Copy link
Author

smortex commented Feb 24, 2024

In order to ease-up reproducing the issue, here is another example targeting the demo dataset, and that can be reproduced on https://playground.opensearch.org:

  1. Go to https://playground.opensearch.org
  2. Click on "Query Workbench"
  3. Copy & paste one of the queries bellow
  4. Click on "Run"
  5. See the expected values
  6. Click on "Download" / "Download JSON" to access the JSON result
  7. See the wrong values

Test queries:

  • Query producing incorrect results:
    select avg(`products.price`), min(`products.price`), max(`products.price`), avg(`total_quantity`) from opensearch_dashboards_sample_data_ecommerce;
  • Query producing the expected results:
    select avg(products.price), min(products.price), max(products.price), avg(total_quantity) from opensearch_dashboards_sample_data_ecommerce;

@Swiddis Swiddis removed the untriaged label Mar 27, 2024
@Swiddis
Copy link
Collaborator

Swiddis commented Mar 27, 2024

Thanks for the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants