Search in sources :

Example 1 with NullOrder

use of org.teiid.translator.ExecutionFactory.NullOrder in project teiid by teiid.

the class RuleCollapseSource method processOrderBy.

private void processOrderBy(PlanNode node, QueryCommand query, Object modelID, CommandContext context, CapabilitiesFinder capFinder) throws QueryMetadataException, TeiidComponentException {
    boolean userOrdering = NodeEditor.findParent(node, NodeConstants.Types.JOIN | NodeConstants.Types.SOURCE) == null;
    OrderBy orderBy = (OrderBy) node.getProperty(NodeConstants.Info.SORT_ORDER);
    query.setOrderBy(orderBy);
    if (query instanceof Query) {
        List<Expression> cols = query.getProjectedSymbols();
        List<Expression> exprs = new ArrayList<Expression>(cols.size());
        for (Expression expr : cols) {
            exprs.add(SymbolMap.getExpression(expr));
        }
        for (OrderByItem item : orderBy.getOrderByItems()) {
            item.setExpressionPosition(exprs.indexOf(SymbolMap.getExpression(item.getSymbol())));
        }
        try {
            QueryRewriter.rewriteOrderBy(query, orderBy, query.getProjectedSymbols(), context, context.getMetadata());
        } catch (TeiidProcessingException e) {
            throw new TeiidComponentException(e);
        }
    }
    boolean supportsNullOrdering = CapabilitiesUtil.supports(Capability.QUERY_ORDERBY_NULL_ORDERING, modelID, context.getMetadata(), capFinder);
    NullOrder defaultNullOrder = CapabilitiesUtil.getDefaultNullOrder(modelID, context.getMetadata(), capFinder);
    for (OrderByItem item : orderBy.getOrderByItems()) {
        if (item.getNullOrdering() != null) {
            if (!supportsNullOrdering) {
                item.setNullOrdering(null);
            }
        } else if (userOrdering && supportsNullOrdering && defaultNullOrder != context.getOptions().getDefaultNullOrder() && context.getOptions().isPushdownDefaultNullOrder()) {
            // try to match the expected default
            if (item.isAscending()) {
                if (context.getOptions().getDefaultNullOrder() == NullOrder.FIRST || context.getOptions().getDefaultNullOrder() == NullOrder.LOW) {
                    if (defaultNullOrder != NullOrder.FIRST && defaultNullOrder != NullOrder.LOW) {
                        item.setNullOrdering(NullOrdering.FIRST);
                    }
                } else {
                    if (defaultNullOrder != NullOrder.LAST && defaultNullOrder != NullOrder.HIGH) {
                        item.setNullOrdering(NullOrdering.LAST);
                    }
                }
            } else {
                if (context.getOptions().getDefaultNullOrder() == NullOrder.LAST || context.getOptions().getDefaultNullOrder() == NullOrder.LOW) {
                    if (defaultNullOrder != NullOrder.LAST && defaultNullOrder != NullOrder.LOW) {
                        item.setNullOrdering(NullOrdering.LAST);
                    }
                } else {
                    if (defaultNullOrder != NullOrder.FIRST && defaultNullOrder != NullOrder.HIGH) {
                        item.setNullOrdering(NullOrdering.FIRST);
                    }
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) NullOrder(org.teiid.translator.ExecutionFactory.NullOrder) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 2 with NullOrder

use of org.teiid.translator.ExecutionFactory.NullOrder in project teiid by teiid.

the class CapabilitiesUtil method supportsNullOrdering.

static boolean supportsNullOrdering(QueryMetadataInterface metadata, CapabilitiesFinder capFinder, Object modelID, OrderByItem symbol) throws QueryMetadataException, TeiidComponentException {
    boolean supportsNullOrdering = CapabilitiesUtil.supports(Capability.QUERY_ORDERBY_NULL_ORDERING, modelID, metadata, capFinder);
    NullOrder defaultNullOrder = CapabilitiesUtil.getDefaultNullOrder(modelID, metadata, capFinder);
    if (symbol.getNullOrdering() != null && !supportsNullOrdering) {
        if (symbol.getNullOrdering() == NullOrdering.FIRST) {
            if (defaultNullOrder != NullOrder.FIRST && !(symbol.isAscending() && defaultNullOrder == NullOrder.LOW) && !(!symbol.isAscending() && defaultNullOrder == NullOrder.HIGH)) {
                return false;
            }
        } else if (defaultNullOrder != NullOrder.LAST && !(symbol.isAscending() && defaultNullOrder == NullOrder.HIGH) && !(!symbol.isAscending() && defaultNullOrder == NullOrder.LOW)) {
            return false;
        }
    }
    return true;
}
Also used : NullOrder(org.teiid.translator.ExecutionFactory.NullOrder)

Example 3 with NullOrder

use of org.teiid.translator.ExecutionFactory.NullOrder in project teiid by teiid.

the class CapabilitiesUtil method getDefaultNullOrder.

public static NullOrder getDefaultNullOrder(Object modelID, QueryMetadataInterface metadata, CapabilitiesFinder capFinder) throws QueryMetadataException, TeiidComponentException {
    if (metadata.isVirtualModel(modelID)) {
        return NullOrder.UNKNOWN;
    }
    SourceCapabilities caps = getCapabilities(modelID, metadata, capFinder);
    NullOrder order = (NullOrder) caps.getSourceProperty(Capability.QUERY_ORDERBY_DEFAULT_NULL_ORDER);
    if (order == null) {
        return NullOrder.UNKNOWN;
    }
    return order;
}
Also used : NullOrder(org.teiid.translator.ExecutionFactory.NullOrder) SourceCapabilities(org.teiid.query.optimizer.capabilities.SourceCapabilities)

Aggregations

NullOrder (org.teiid.translator.ExecutionFactory.NullOrder)3 ArrayList (java.util.ArrayList)1 TeiidComponentException (org.teiid.core.TeiidComponentException)1 TeiidProcessingException (org.teiid.core.TeiidProcessingException)1 SourceCapabilities (org.teiid.query.optimizer.capabilities.SourceCapabilities)1