opensearch-project / sql

Query your data using familiar SQL or intuitive Piped Processing Language (PPL)
https://opensearch.org/docs/latest/search-plugins/sql/index/
Apache License 2.0
121 stars 140 forks source link

[BUG] COUNT function counts number of elements in array values #3137

Open normanj-bitquill opened 3 weeks ago

normanj-bitquill commented 3 weeks ago

What is the bug? The COUNT function counts the number of elements in all array values rather than counting the number of array values.

Consider an index with the following data:

{"x": 1, "y": [1, 2]}
{"x": 2, "y": [3, 4]}
{"x": 3, "y": [1, 5]}
{"x": 4, "y": [1, 2]}
{"x": 5, "y": [2, 3]}

and this query:

SELECT COUNT(y) FROM test3;
10

Expected Result:

5

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

  1. Create a new index and load the data above
  2. Run the query above

What is the expected behavior? The COUNT function only counts the number of array values.

What is your host/environment?

Do you have any screenshots? N/A

Do you have any additional context? Issue #1300 had a change recently merged in that allows array values to be used in query evaluation and in the result set.

andrross commented 3 days ago

[Catch All Triage - 1, 2, 3, 4, 5]