Search in sources :

Example 21 with Order

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

the class PlanNode method groupBy.

public PlanNode groupBy(Item c, SQLOrderingSpecification sortOrder) {
    Order order = new Order(c, sortOrder);
    this.groups.add(order);
    return this;
}
Also used : Order(com.actiontech.dble.plan.Order)

Example 22 with Order

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

the class PlanNode method copySelfTo.

protected final void copySelfTo(PlanNode to) {
    to.setAlias(this.alias);
    to.setDistinct(this.isDistinct);
    for (Item selected : this.getColumnsSelected()) {
        Item copySel = selected.cloneItem();
        copySel.setItemName(selected.getItemName());
        to.columnsSelected.add(copySel);
    }
    for (Order groupBy : this.getGroupBys()) {
        to.groups.add(groupBy.copy());
    }
    for (Order orderBy : this.getOrderBys()) {
        to.orderBys.add(orderBy.copy());
    }
    to.whereFilter = this.whereFilter == null ? null : this.whereFilter.cloneItem();
    to.havingFilter = this.havingFilter == null ? null : havingFilter.cloneItem();
    to.setLimitFrom(this.limitFrom);
    to.setLimitTo(this.limitTo);
    to.setSql(this.getSql());
    to.setSubQuery(subQuery);
    to.setCorrelatedSubQuery(correlatedSubQuery);
    to.setUnGlobalTableCount(unGlobalTableCount);
    to.setNoshardNode(noshardNode);
}
Also used : Order(com.actiontech.dble.plan.Order) Item(com.actiontech.dble.plan.common.item.Item)

Example 23 with Order

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

the class BaseHandlerBuilder method mergeOrderBy.

/**
 * try to merger the order of 'order by' syntax to columnsSelected
 *
 * @param columnsSelected
 * @param orderBys
 * @return
 */
private List<Order> mergeOrderBy(List<Item> columnsSelected, List<Order> orderBys) {
    List<Integer> orderIndexes = new ArrayList<>();
    List<Order> newOrderByList = new ArrayList<>();
    for (Order orderBy : orderBys) {
        Item column = orderBy.getItem();
        int index = columnsSelected.indexOf(column);
        if (index < 0)
            return null;
        else
            orderIndexes.add(index);
        Order newOrderBy = new Order(columnsSelected.get(index), orderBy.getSortOrder());
        newOrderByList.add(newOrderBy);
    }
    for (int index = 0; index < columnsSelected.size(); index++) {
        if (!orderIndexes.contains(index)) {
            Order newOrderBy = new Order(columnsSelected.get(index), SQLOrderingSpecification.ASC);
            newOrderByList.add(newOrderBy);
        }
    }
    return newOrderByList;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Order(com.actiontech.dble.plan.Order) Item(com.actiontech.dble.plan.common.item.Item) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 24 with Order

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

the class GlobalVisitor method buildGroupBy.

protected void buildGroupBy(PlanNode query) {
    boolean first = true;
    if (query.getGroupBys() != null && query.getGroupBys().size() > 0) {
        sqlBuilder.append(" GROUP BY ");
        for (Order group : query.getGroupBys()) {
            if (first)
                first = false;
            else
                sqlBuilder.append(",");
            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());
        }
    }
}
Also used : Order(com.actiontech.dble.plan.Order) Item(com.actiontech.dble.plan.common.item.Item)

Example 25 with Order

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

the class MultiNodeSelectHandler method mergeFieldEof.

private void mergeFieldEof(List<byte[]> fields, BackendConnection conn) throws IOException {
    fieldCount = fields.size();
    List<FieldPacket> fieldPackets = new ArrayList<>();
    for (byte[] field : fields) {
        this.netOutBytes += field.length;
        FieldPacket fieldPacket = new FieldPacket();
        fieldPacket.read(field);
        if (rrs.getSchema() != null) {
            fieldPacket.setDb(rrs.getSchema().getBytes());
        }
        if (rrs.getTableAlias() != null) {
            fieldPacket.setTable(rrs.getTableAlias().getBytes());
        }
        if (rrs.getTable() != null) {
            fieldPacket.setOrgTable(rrs.getTable().getBytes());
        }
        fieldPackets.add(fieldPacket);
    }
    List<Order> orderBys = new ArrayList<>();
    for (String groupBy : rrs.getGroupByCols()) {
        ItemField itemField = new ItemField(rrs.getSchema(), rrs.getTableAlias(), groupBy);
        orderBys.add(new Order(itemField));
    }
    rowComparator = new RowDataComparator(fieldPackets, orderBys);
    outputHandler.fieldEofResponse(null, null, fieldPackets, null, false, conn);
}
Also used : Order(com.actiontech.dble.plan.Order) ItemField(com.actiontech.dble.plan.common.item.ItemField) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket) RowDataComparator(com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator)

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