// Cached state, if needed
String[] knownShortNames = new String[knownElements.size()];
List<Expression> expressions = new ArrayList<Expression>(knownElements.size());
for(int i=0; i<knownElements.size(); i++) {
SingleElementSymbol knownSymbol = knownElements.get(i);
expressions.add(SymbolMap.getExpression(knownSymbol));
if (knownSymbol instanceof ExpressionSymbol) {
continue;
}
String name = knownSymbol.getShortName();
knownShortNames[i] = name;
}
for (int i = 0; i < orderBy.getVariableCount(); i++) {
SingleElementSymbol sortKey = orderBy.getVariable(i);
if (sortKey instanceof ElementSymbol) {
ElementSymbol symbol = (ElementSymbol)sortKey;
String groupPart = null;
if (symbol.getGroupSymbol() != null) {
groupPart = symbol.getGroupSymbol().getName();
}
String symbolName = symbol.getName();
String shortName = symbol.getShortName();
if (groupPart == null) {
int position = -1;
SingleElementSymbol matchedSymbol = null;
// walk the SELECT col short names, looking for a match on the current ORDER BY 'short name'
for(int j=0; j<knownShortNames.length; j++) {
if( !shortName.equalsIgnoreCase( knownShortNames[j] )) {
continue;
}
// if we already have a matched symbol, matching again here means it is duplicate/ambiguous
if(matchedSymbol != null) {
if (!matchedSymbol.equals(knownElements.get(j))) {
throw new QueryResolverException("ERR.015.008.0042", QueryPlugin.Util.getString("ERR.015.008.0042", symbolName)); //$NON-NLS-1$ //$NON-NLS-2$
}
continue;
}
matchedSymbol = knownElements.get(j);
position = j;
}
if (matchedSymbol != null) {
TempMetadataID tempMetadataID = new TempMetadataID(symbol.getName(), matchedSymbol.getType());
symbol.setMetadataID(tempMetadataID);
symbol.setType(matchedSymbol.getType());
}
if (position != -1) {
orderBy.setExpressionPosition(i, position);
continue;
}