You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] MAX/MIN functions does not work properly with array values #3138
For MAX, the expectd result is [3, 4] and for MIN, the expected result is [1, 2]. The comparison should be performed element by element and preserve the entire array value.
How can one reproduce the bug?
Steps to reproduce the behavior:
Create a new index and load the data above
Run the query above
What is the expected behavior?
Use array comparisons to compare the array values and return the MAX or MIN array.
What is your host/environment?
OS: Mac OS X
Version: 3.0 code base
Plugins: SQL plugin
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.
Thanks for rasing issue. OpenSearch/Lucene does not support ARRAY data type. Lucene allows adding multiple values for the same field name. for example. when calcualte min/max of field y, OpenSeach read all the value of y, and calcuate metrics, the result is min(y)=1, max(y)=5.
@penghuo I'm not sure the SQL plugin can easily know that the field is an array field. By default, the mapping will only contain information about the element types.
IMO we can utilize mapping._meta#field.name.type:array location for the user to explicitly hint the specific mapping field is expected to be treated and an array.
indexing: ingestion a mismatched value will not cause an error (if this field only contains a single value) but the query engine (PPL/SQL) should treat this value as a single list.
IMO in the first iteration we can have the plugin be aware of the mapping._meta#field.name.type:array and actually do the aggregation in the client's scope (not pushing down).
Activity
normanj-bitquill commentedon Oct 30, 2024
This appears to be due to how the OpenSearch engine calculates the min and max for arrays values.
normanj-bitquill commentedon Oct 30, 2024
For reference, this is how PostgreSQL behaves:
penghuo commentedon Oct 30, 2024
Thanks for rasing issue. OpenSearch/Lucene does not support ARRAY data type. Lucene allows adding multiple values for the same field name. for example. when calcualte min/max of field y, OpenSeach read all the value of y, and calcuate metrics, the result is min(y)=1, max(y)=5.
penghuo commentedon Oct 30, 2024
Related issue in opensearch-core. opensearch-project/OpenSearch#16420
penghuo commentedon Oct 30, 2024
One solution is if array_field is used in aggregation, we should do post-processing, instead of rewrite as DSL aggregation query.
normanj-bitquill commentedon Oct 30, 2024
@penghuo I'm not sure the SQL plugin can easily know that the field is an array field. By default, the mapping will only contain information about the element types.
If the user adds something to the mapping, we could know that it is an array.
https://trino.io/docs/current/connector/elasticsearch.html#array-types
Is there anything similar currently in OpenSearch?
penghuo commentedon Oct 31, 2024
@normanj-bitquill agree, opensearch-project/OpenSearch#16420 discuss similar approach.
andrross commentedon Nov 18, 2024
[Catch All Triage - 1, 2, 3, 4, 5]
YANG-DB commentedon Dec 16, 2024
@normanj-bitquill @acarbonetto I've seen the approach suggested here.
IMO we can utilize
mapping._meta#field.name.type:arraylocation for the user to explicitly hint the specific mapping field is expected to be treated and an array.indexing: ingestion a mismatched value will not cause an error (if this field only contains a single value) but the query engine (PPL/SQL) should treat this value as a single list.
IMO in the first iteration we can have the plugin be aware of the
mapping._meta#field.name.type:arrayand actually do the aggregation in the client's scope (not pushing down).Fix array comparison to use lexicographic ordering instead of size-only
qianheng-aws commentedon Apr 10, 2026
Closing as duplicate of #5333 — consolidated umbrella issue for array values not treated as atomic values.