Is your feature request related to a problem?
In the fix for #5150 (PR #5192), a fieldNameMapping (HashMap<String, String>) was added to AggregateAnalyzer to translate original OpenSearch field names to renamed output names in the top_hits response. This mapping is keyed by the original OS field name.
When two project args trace back to the same original field but have different output names, the second put overwrites the first, causing one field to return null.
Example query:
source=employees | eval pay2 = salary | rename salary as pay | dedup dept_id | fields dept_id, pay, pay2
Both pay (from rename) and pay2 (from eval) resolve to the original field salary. The mapping becomes {salary → pay2}, losing {salary → pay}. The pay column returns null in the result.
What solution would you like?
Change fieldNameMapping in AggregateAnalyzer.createRegularAggregation() from Map<String, String> (one-to-one) to Map<String, List<String>> (one-to-many), and update TopHitsParser.applyFieldNameMapping() to duplicate the value into all mapped output keys.
Additional context
Is your feature request related to a problem?
In the fix for #5150 (PR #5192), a
fieldNameMapping(HashMap<String, String>) was added toAggregateAnalyzerto translate original OpenSearch field names to renamed output names in the top_hits response. This mapping is keyed by the original OS field name.When two project args trace back to the same original field but have different output names, the second
putoverwrites the first, causing one field to returnnull.Example query:
Both
pay(from rename) andpay2(from eval) resolve to the original fieldsalary. The mapping becomes{salary → pay2}, losing{salary → pay}. Thepaycolumn returnsnullin the result.What solution would you like?
Change
fieldNameMappinginAggregateAnalyzer.createRegularAggregation()fromMap<String, String>(one-to-one) toMap<String, List<String>>(one-to-many), and updateTopHitsParser.applyFieldNameMapping()to duplicate the value into all mapped output keys.Additional context
opensearch/src/main/java/org/opensearch/sql/opensearch/request/AggregateAnalyzer.java(line ~612)LOG.warn("Field name mapping collision: ...")