Examples of OrderByExpression


Examples of com.foundationdb.sql.optimizer.plan.Sort.OrderByExpression

            newSetNode.setResults(results);
            List<OrderByExpression> sorts = new ArrayList<>();
            if (orderByList != null) {
                for (OrderByColumn orderByColumn : orderByList) {
                    ExpressionNode expression = toOrderGroupBy(orderByColumn.getExpression(), projects, "ORDER");
                    sorts.add(new OrderByExpression(expression,
                            orderByColumn.isAscending()));
                }
            }
            Project project = new Project (newSetNode, projects);
            PlanNode query = project;
View Full Code Here

Examples of com.foundationdb.sql.optimizer.plan.Sort.OrderByExpression

            List<OrderByExpression> sorts = new ArrayList<>();
            if (orderByList != null) {
                for (OrderByColumn orderByColumn : orderByList) {
                    ExpressionNode expression = toOrderGroupBy(orderByColumn.getExpression(), projects, "ORDER");
                    sorts.add(new OrderByExpression(expression,
                                                    orderByColumn.isAscending()));
                }
            }

            // Stupid but legal:
View Full Code Here

Examples of com.foundationdb.sql.optimizer.plan.Sort.OrderByExpression

            List<ExpressionNode> exprs = project.getFields();
            BitSet used = new BitSet(exprs.size());
            int nSorts = sorts.size();
            ExpressionNode[] adjustedOrderBys = new ExpressionNode[nSorts];
            for (int i = 0; i < nSorts; i++) {
                OrderByExpression orderBy = sorts.get(i);
                ExpressionNode expr = orderBy.getExpression();
                int idx = exprs.indexOf(expr);
                if (idx < 0) {
                    if (isDistinctSortNotSelectGroupBy())
                        return false;
                    throw new UnsupportedSQLException("SELECT DISTINCT requires that ORDER BY expressions be in the select list",
                                                      expr.getSQLsource());
                }
                adjustedOrderBys[i] = new ColumnExpression(project, idx,
                                                           expr.getSQLtype(),
                                                           expr.getSQLsource(),
                                                           expr.getType());
                used.set(idx);
            }
            // If we got here, it means each orderBy's expression is in the exprs list. As such, nSorts <= exprs.size
            for (int i = 0; i < exprs.size(); i++) {
                if (i < nSorts)
                    sorts.get(i).setExpression(adjustedOrderBys[i]);
                if (!used.get(i)) {
                    ExpressionNode expr = exprs.get(i);
                    ExpressionNode cexpr = new ColumnExpression(project, i,
                                                                expr.getSQLtype(),
                                                                expr.getSQLsource(),
                                                                expr.getType());
                    OrderByExpression orderBy = new OrderByExpression(cexpr,
                                                                      sorts.get(0).isAscending());
                    sorts.add(orderBy);
                }
            }
            return true;
View Full Code Here

Examples of com.foundationdb.sql.optimizer.plan.Sort.OrderByExpression

                    {
                        sorts = new ArrayList<>();
                        for (OrderByColumn orderByColumn : orderByList)
                        {
                            ExpressionNode expression = toOrderGroupBy(orderByColumn.getExpression(), projects, "ORDER");
                            sorts.add(new OrderByExpression(expression,
                                                            orderByColumn.isAscending()));
                        }
                    }
                   
                    return new AggregateFunctionExpression(function,
View Full Code Here

Examples of com.foundationdb.sql.optimizer.plan.Sort.OrderByExpression

                                ExpressionNode expr = exprs.get(i);
                                ExpressionNode cexpr = new ColumnExpression(project, i,
                                                                            expr.getSQLtype(),
                                                                            expr.getSQLsource(),
                                                                            expr.getType());
                                OrderByExpression orderBy = new OrderByExpression(cexpr,
                                                                                  sorts.get(0).isAscending());
                                sorts.add(orderBy);
                            }
                        }
                        n = moveBeneath(sort, distinct);
View Full Code Here

Examples of com.foundationdb.sql.optimizer.plan.Sort.OrderByExpression

                IndexColumn indexColumn = indexColumns.get(i++);
                indexExpression = getIndexExpression(index, indexColumn);
                ascending = indexColumn.isAscending();
            }
            indexExpressions.add(indexExpression);
            orderBy.add(new OrderByExpression(indexExpression, ascending));
        }
        index.setColumns(indexExpressions);
        index.setOrdering(orderBy);
    }
View Full Code Here

Examples of com.foundationdb.sql.optimizer.plan.Sort.OrderByExpression

                            targetExpression = project.getFields()
                                .get(column.getPosition());
                        }
                    }
                }
                OrderByExpression indexColumn = getIndexColumn(indexOrdering, idx);
                if (indexColumn == null && idx < nequals) {
                    throw new CorruptedPlanException("No index column expression for union comparison");
                }
                if (indexColumn != null) {
                    boolean matchingColumn = orderingExpressionMatches(indexColumn, targetExpression);
                    if (!matchingColumn && idx < nequals) {
                        // if we we're trying the union column, but that failed, try just treating it as equals
                        idx++;
                        indexColumn = getIndexColumn(indexOrdering, idx);
                        if (indexColumn != null) {
                            matchingColumn = orderingExpressionMatches(indexColumn, targetExpression);
                            if (matchingColumn) {
                                index.setIncludeUnionAsEquality(true);
                            }
                        }
                    }
                    if (matchingColumn) {
                        if (idx < nequals) {
                            index.setIncludeUnionAsEquality(false);
                        }
                        if (indexColumn.isAscending() != targetColumn.isAscending()) {
                            // To avoid mixed mode as much as possible,
                            // defer changing the index order until
                            // certain it will be effective.
                            reverse.set(idx, true);
                            if (idx == nequals)
                                // Likewise reverse the initial equals segment.
                                reverse.set(0, nequals, true);
                        }
                        if (idx >= index.getNKeyColumns())
                            index.setUsesAllColumns(true);
                        idx++;
                        continue;
                    }
                }
                if (equalityColumns != null) {
                    // Another possibility is that target ordering is
                    // in fact unchanged due to equality condition.
                    // TODO: Should this have been noticed earlier on
                    // so that it can be taken out of the sort?
                    if (equalityColumns.contains(targetExpression))
                        continue;
                }
                break try_sorted;
            }
            if ((idx > 0) && (idx < indexOrdering.size()) && reverse.get(idx-1))
                // Reverse after ORDER BY if reversed last one.
                reverse.set(idx, indexOrdering.size(), true);
            for (int i = 0; i < reverse.size(); i++) {
                if (reverse.get(i)) {
                    OrderByExpression indexColumn = indexOrdering.get(i);
                    indexColumn.setAscending(!indexColumn.isAscending());
                }
            }
            result = IndexScan.OrderEffectiveness.SORTED;
        }
        if (queryGoal.getGrouping() != null) {
View Full Code Here

Examples of com.foundationdb.sql.optimizer.plan.Sort.OrderByExpression

        }
        return result;
    }

    private OrderByExpression getIndexColumn(List<OrderByExpression> indexOrdering, int idx) {
        OrderByExpression indexColumn = null;
        if (idx < indexOrdering.size()) {
            indexColumn = indexOrdering.get(idx);
            if (indexColumn.getExpression() == null)
                indexColumn = null; // Index sorts by unknown column.
        }
        return indexColumn;
    }
View Full Code Here

Examples of com.salesforce.phoenix.expression.OrderByExpression

                    .setMessage(expression.toString()).build().buildException();
                }
                if (expression.getColumnModifier() == ColumnModifier.SORT_DESC) {
                    isAscending = !isAscending;
                }
                OrderByExpression orderByExpression = new OrderByExpression(expression, node.isNullsLast(), isAscending);
                orderByExpressions.add(orderByExpression);
            }
            visitor.reset();
        }
      
View Full Code Here

Examples of com.salesforce.phoenix.expression.OrderByExpression

    }

    @Override
    protected int compare(Tuple t1, Tuple t2) {
        for (int i = 0; i < orderByColumns.size(); i++) {
            OrderByExpression order = orderByColumns.get(i);
            Expression orderExpr = order.getExpression();
            boolean isNull1 = !orderExpr.evaluate(t1, ptr1) || ptr1.getLength() == 0;
            boolean isNull2 = !orderExpr.evaluate(t2, ptr2) || ptr2.getLength() == 0;
            if (isNull1 && isNull2) {
                continue;
            } else if (isNull1) {
                return order.isNullsLast() ? 1 : -1;
            } else if (isNull2) {
                return order.isNullsLast() ? -1 : 1;
            }
            int cmp = ptr1.compareTo(ptr2);
            if (cmp == 0) {
                continue;
            }
            return order.isAscending() ? cmp : -cmp;
        }
        return 0;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.