@Override public void visit(SortSpecification obj) { if (this.orderBy.length() > 0) { this.orderBy.append(Tokens.COMMA); } ColumnReference column = (ColumnReference)obj.getExpression(); this.orderBy.append(column.getMetadataObject().getName()); // default is ascending if (obj.getOrdering() == Ordering.DESC) { this.orderBy.append(Tokens.SPACE).append(DESC.toLowerCase()); } }
public SortSpecification createOrderByItem(ColumnReference element, Ordering direction) { return new SortSpecification(direction, element); }
public void visit(SortSpecification obj) { append(obj.getExpression()); if (obj.getOrdering() == Ordering.DESC) { buffer.append(Tokens.SPACE) .append(DESC); } // Don't print default "ASC" if (obj.getNullOrdering() != null) { buffer.append(Tokens.SPACE) .append(NonReserved.NULLS) .append(Tokens.SPACE) .append(obj.getNullOrdering().name()); } }
public static void correctNullOrdering(org.teiid.language.OrderBy orderBy, boolean supportsNullOrdering, NullOrder sourceNullOrder, NullOrder teiidNullOrder) { for (SortSpecification item : orderBy.getSortSpecifications()) { if (item.getNullOrdering() != null) { if (!supportsNullOrdering) { item.setNullOrdering(null); if (item.getOrdering() == Ordering.ASC) { if (teiidNullOrder == NullOrder.FIRST || teiidNullOrder == NullOrder.LOW) { if (sourceNullOrder != NullOrder.FIRST && sourceNullOrder != NullOrder.LOW) { item.setNullOrdering(NullOrdering.FIRST); item.setNullOrdering(NullOrdering.LAST); if (teiidNullOrder == NullOrder.LAST || teiidNullOrder == NullOrder.LOW) { if (sourceNullOrder != NullOrder.LAST && sourceNullOrder != NullOrder.LOW) { item.setNullOrdering(NullOrdering.LAST); item.setNullOrdering(NullOrdering.FIRST);
public org.teiid.language.OrderBy translate(OrderBy orderBy, boolean set) { if(orderBy == null){ return null; } List<OrderByItem> items = orderBy.getOrderByItems(); List<SortSpecification> translatedItems = new ArrayList<SortSpecification>(); for (int i = 0; i < items.size(); i++) { Expression symbol = items.get(i).getSymbol(); Ordering direction = items.get(i).isAscending() ? Ordering.ASC: Ordering.DESC; SortSpecification orderByItem = null; if(!set && (items.get(i).isUnrelated() || symbol instanceof ElementSymbol)){ orderByItem = new SortSpecification(direction, translate(symbol)); } else { orderByItem = new SortSpecification(direction, new ColumnReference(null, Symbol.getShortName(((Symbol)symbol).getOutputName()), null, symbol.getType())); } orderByItem.setNullOrdering(items.get(i).getNullOrdering()); translatedItems.add(orderByItem); } return new org.teiid.language.OrderBy(translatedItems); }
@Override public void visit(SortSpecification obj) { visitNode(obj.getExpression()); }
Expression ex = ss.getExpression(); if (!(ex instanceof ColumnReference)) { continue; Integer position = positions.get(cr.toString()); if (position != null) { ss.setExpression(new Literal(position, TypeFacility.RUNTIME_TYPES.INTEGER));
public static void correctNullOrdering(org.teiid.language.OrderBy orderBy, boolean supportsNullOrdering, NullOrder sourceNullOrder, NullOrder teiidNullOrder) { for (SortSpecification item : orderBy.getSortSpecifications()) { if (item.getNullOrdering() != null) { if (!supportsNullOrdering) { item.setNullOrdering(null); if (item.getOrdering() == Ordering.ASC) { if (teiidNullOrder == NullOrder.FIRST || teiidNullOrder == NullOrder.LOW) { if (sourceNullOrder != NullOrder.FIRST && sourceNullOrder != NullOrder.LOW) { item.setNullOrdering(NullOrdering.FIRST); item.setNullOrdering(NullOrdering.LAST); if (teiidNullOrder == NullOrder.LAST || teiidNullOrder == NullOrder.LOW) { if (sourceNullOrder != NullOrder.LAST && sourceNullOrder != NullOrder.LOW) { item.setNullOrdering(NullOrdering.LAST); item.setNullOrdering(NullOrdering.FIRST);
orderByItem = new SortSpecification(direction, translate(symbol)); } else { orderByItem = new SortSpecification(direction, new ColumnReference(null, Symbol.getShortName(((Symbol)symbol).getOutputName()), null, symbol.getType())); orderByItem.setNullOrdering(items.get(i).getNullOrdering()); translatedItems.add(orderByItem);
private void validateOrderBy(Select obj) { Collection<ColumnReference> whereColumns = CollectorVisitor.collectElements(obj.getWhere()); for (SortSpecification sort:obj.getOrderBy().getSortSpecifications()) { boolean matched = false; for (ColumnReference where:whereColumns) { ColumnReference col = (ColumnReference)sort.getExpression(); if (col.getName().equals(where.getName())) { matched = true; } } if (!matched) { this.exceptions.add(new TranslatorException(SimpleDBPlugin.Event.TEIID24005, SimpleDBPlugin.Util.gs(SimpleDBPlugin.Event.TEIID24005))); break; } } }
@Override public void visit(SortSpecification obj) { append(obj.getExpression()); Object expr = this.onGoingExpression.pop(); ColumnDetail alias = this.expressionMap.get(expr); if (this.sort == null) { this.sort = new BasicDBObject(alias.getProjectedName(), (obj.getOrdering() == Ordering.ASC)?1:-1); } else { this.sort.put(alias.getProjectedName(), (obj.getOrdering() == Ordering.ASC)?1:-1); } }
orderByItem = new SortSpecification(direction, translate(symbol)); } else { orderByItem = new SortSpecification(direction, new ColumnReference(null, Symbol.getShortName(((Symbol)symbol).getOutputName()), null, symbol.getType())); orderByItem.setNullOrdering(items.get(i).getNullOrdering()); translatedItems.add(orderByItem);
public static SetQuery example3() throws Exception { SetQuery union = example2(); List<SortSpecification> items = new ArrayList<SortSpecification>(); items.add(new SortSpecification(Ordering.ASC, new ColumnReference(null, "nugent", null, DataTypeManager.DefaultDataClasses.STRING))); //$NON-NLS-1$ OrderBy orderBy = new OrderBy(items); union.setOrderBy(orderBy); return union; }
@Override public void visit(SortSpecification obj) { if (this.orderBy.length() > 0) { this.orderBy.append(Tokens.COMMA); } ColumnReference column = (ColumnReference)obj.getExpression(); try { Column c = ODataMetadataProcessor.normalizePseudoColumn(this.metadata, column.getMetadataObject()); this.orderBy.append(c.getName()); } catch (TranslatorException e) { this.exceptions.add(e); } // default is ascending if (obj.getOrdering() == Ordering.DESC) { this.orderBy.append(Tokens.SPACE).append(DESC.toLowerCase()); } }
while(orderItr.hasNext()) { SortSpecification item = orderItr.next(); String itemName = getExpressionQueryString(item.getExpression()); LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Adding sort key for item:", itemName); //$NON-NLS-1$ if(item.getOrdering() == Ordering.ASC) { LogManager.logTrace(LogConstants.CTX_CONNECTOR, "with ASC ordering."); //$NON-NLS-1$ sortKey = new SortKey(itemName, true, null); } else if(item.getOrdering() == Ordering.DESC){ LogManager.logTrace(LogConstants.CTX_CONNECTOR, "with DESC ordering."); //$NON-NLS-1$ sortKey = new SortKey(itemName, false, null);