Search in sources :

Example 26 with Order

use of com.actiontech.dble.plan.Order in project dble by actiontech.

the class OrderedGroupByHandler method prepareSumAggregators.

/**
 * see Sql_executor.cc
 *
 * @return
 */
protected void prepareSumAggregators(List<ItemSum> functions, List<ItemSum> sumFunctions, List<FieldPacket> packets, boolean isAllPushDown, boolean needDistinct, MySQLConnection conn) {
    LOGGER.info("prepare_sum_aggregators");
    for (int i = 0; i < functions.size(); i++) {
        ItemSum func = functions.get(i);
        ResultStore store = null;
        if (func.hasWithDistinct()) {
            ItemSum selFunc = sumFunctions.get(i);
            List<Order> orders = HandlerTool.makeOrder(selFunc.arguments());
            RowDataComparator distinctCmp = new RowDataComparator(packets, orders, isAllPushDown, this.type());
            store = new DistinctLocalResult(pool, packets.size(), distinctCmp, this.charset).setMemSizeController(session.getOtherBufferMC());
            distinctStores.add(store);
        }
        func.setAggregator(needDistinct && func.hasWithDistinct() ? AggregatorType.DISTINCT_AGGREGATOR : AggregatorType.SIMPLE_AGGREGATOR, store);
    }
}
Also used : Order(com.actiontech.dble.plan.Order) DistinctLocalResult(com.actiontech.dble.backend.mysql.store.DistinctLocalResult) ItemSum(com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum) ResultStore(com.actiontech.dble.plan.common.external.ResultStore) RowDataComparator(com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator)

Example 27 with Order

use of com.actiontech.dble.plan.Order in project dble by actiontech.

the class PushDownVisitor method buildGroupBy.

protected void buildGroupBy(PlanNode query) {
    if (nodeHasGroupBy(query)) {
        // push down group by
        if (!existUnPushDownGroup) {
            if (!query.getGroupBys().isEmpty()) {
                sqlBuilder.append(" GROUP BY ");
                for (Order group : query.getGroupBys()) {
                    // store the order by's order
                    pushDownOrderBy.add(group.copy());
                    Item groupCol = group.getItem();
                    String pdName = "";
                    if (groupCol.basicConstItem())
                        pdName = "'" + groupCol.toString() + "'";
                    if (pdName.isEmpty())
                        pdName = visitUnSelPushDownName(groupCol, true);
                    sqlBuilder.append(pdName).append(" ").append(group.getSortOrder()).append(",");
                }
                sqlBuilder.deleteCharAt(sqlBuilder.length() - 1);
            }
        } else {
            // change to push down order by
            pushDownOrderBy.addAll(query.getGroupBys());
            if (pushDownOrderBy.size() > 0) {
                sqlBuilder.append(" ORDER BY ");
                for (Order order : pushDownOrderBy) {
                    Item orderSel = order.getItem();
                    String pdName = "";
                    if (orderSel.basicConstItem())
                        pdName = "'" + orderSel.toString() + "'";
                    if (pdName.isEmpty())
                        pdName = visitUnSelPushDownName(orderSel, true);
                    sqlBuilder.append(pdName).append(" ").append(order.getSortOrder()).append(",");
                }
                sqlBuilder.deleteCharAt(sqlBuilder.length() - 1);
            }
        }
    }
}
Also used : Order(com.actiontech.dble.plan.Order) Item(com.actiontech.dble.plan.common.item.Item)

Aggregations

Order (com.actiontech.dble.plan.Order)27 Item (com.actiontech.dble.plan.common.item.Item)16 RowDataComparator (com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator)4 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)4 ArrayList (java.util.ArrayList)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 DistinctLocalResult (com.actiontech.dble.backend.mysql.store.DistinctLocalResult)2 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)2 ItemField (com.actiontech.dble.plan.common.item.ItemField)2 ItemFuncEqual (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)2 ItemSum (com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum)2 PlanNode (com.actiontech.dble.plan.node.PlanNode)2 SQLSelectOrderByItem (com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)2 DirectGroupByHandler (com.actiontech.dble.backend.mysql.nio.handler.query.impl.groupby.DirectGroupByHandler)1 OrderedGroupByHandler (com.actiontech.dble.backend.mysql.nio.handler.query.impl.groupby.OrderedGroupByHandler)1 ResultStore (com.actiontech.dble.plan.common.external.ResultStore)1 Field (com.actiontech.dble.plan.common.field.Field)1 JoinNode (com.actiontech.dble.plan.node.JoinNode)1 QueryNode (com.actiontech.dble.plan.node.QueryNode)1 SQLOrderBy (com.alibaba.druid.sql.ast.SQLOrderBy)1