[ https://issues.apache.org/jira/browse/METAMODEL-128?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14387004#comment-14387004 ]
ASF GitHub Bot commented on METAMODEL-128: ------------------------------------------ Github user kaspersorensen commented on a diff in the pull request: https://github.com/apache/metamodel/pull/13#discussion_r27410445 --- Diff: core/src/main/java/org/apache/metamodel/query/parser/SelectItemParser.java --- @@ -160,6 +164,14 @@ public SelectItem findSelectItem(String expression) throws MultipleSelectItemsPa return new SelectItem(subQuerySelectItem, fromItem); } } + + //if the expression is alias of some select item defined return clone of that select item + List<SelectItem> allSelectItems = MetaModelHelper.getAllSelectItems(_query); + for(SelectItem selectItem : allSelectItems) { + if(selectItem.getAlias() != null && selectItem.getAlias().equals(expressionCopy)) { + return selectItem.clone(); --- End diff -- Do we need to return the clone? Why not return the same select item? If it is referred to by alias (like a kind of pass by reference) then I think it makes sense to keep the same reference item and not a copy. > Ordering on aggregation value not working > ----------------------------------------- > > Key: METAMODEL-128 > URL: https://issues.apache.org/jira/browse/METAMODEL-128 > Project: Apache MetaModel > Issue Type: Bug > Affects Versions: 4.3.2 > Reporter: Ashish Mukherjee > > I am using a CSV Data Context example with multiple fields - occurrences, > first_name, last_name. > The query - > SELECT SUM(persons.csv.occurrences) AS X, persons.csv.first_name FROM > ashish.persons.csv GROUP BY persons.csv.first_name ORDER BY X > This query always orders the results by first_name and not the aggregation > value. -- This message was sent by Atlassian JIRA (v6.3.4#6332)