Skip to content

Commit

Permalink
Updated to not compare column alias
Browse files Browse the repository at this point in the history
  • Loading branch information
Jugen committed Feb 8, 2024
1 parent d5bbd52 commit 3ec74e0
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.apache.cayenne.access.sqlbuilder.NodeBuilder;
import org.apache.cayenne.access.sqlbuilder.OrderingNodeBuilder;
import org.apache.cayenne.access.sqlbuilder.StringBuilderAppendable;
import org.apache.cayenne.access.sqlbuilder.sqltree.Node;
import org.apache.cayenne.exp.Expression;
import org.apache.cayenne.exp.parser.ASTAggregateFunctionCall;
Expand Down Expand Up @@ -57,10 +58,11 @@ private void processOrdering(QualifierTranslator qualifierTranslator, Translator
// If query is DISTINCT then we need to add all ORDER BY clauses as result columns
if(!context.isDistinctSuppression()) {
// Duplicate column check
String nodeStr = translatedNode.toString();
String orderStr = translatedNode.append(new StringBuilderAppendable()).append(' ').toString();
boolean isNotPresent = context.getResultNodeList().stream()
.map( result -> result.getNode().toString() )
.noneMatch( node -> node.equals( nodeStr ) );
.map( result -> result.getNode().append(new StringBuilderAppendable()).append(' ') )
// the column may have an alias so just check that the orderStr part matches
.noneMatch( column -> column.toString().startsWith( orderStr ) );

if ( isNotPresent ) {
// deepCopy as some DB expect exactly the same expression in select and in ordering
Expand Down

0 comments on commit 3ec74e0

Please sign in to comment.