Search in sources :

Example 71 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class FilterPusher method replaceFunctionArg.

/**
 * replaceFunctionArg
 *
 * @param f
 * @param sels1
 * @param sels2
 * @return if f also contains selectable which is not sels1 ,return null
 */
public static ItemFunc replaceFunctionArg(ItemFunc f, List<Item> sels1, List<Item> sels2) {
    ItemFunc ret = (ItemFunc) f.cloneStruct();
    for (int index = 0; index < ret.getArgCount(); index++) {
        Item arg = ret.arguments().get(index);
        if (arg instanceof ItemFunc) {
            ItemFunc newfArg = replaceFunctionArg((ItemFunc) arg, sels1, sels2);
            if (newfArg == null)
                return null;
            else
                ret.arguments().set(index, newfArg);
        } else if (arg instanceof ItemField) {
            int tmpIndex = sels1.indexOf(arg);
            if (tmpIndex < 0) {
                return null;
            } else {
                Item newArg = sels2.get(tmpIndex);
                ret.arguments().set(index, newArg.cloneStruct());
            }
        } else {
        // do nothing;
        }
    }
    ret.setPushDownName(null);
    PlanUtil.refreshReferTables(ret);
    return ret;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemFunc(com.actiontech.dble.plan.common.item.function.ItemFunc) ItemField(com.actiontech.dble.plan.common.item.ItemField)

Example 72 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class MergeHavingFilter method optimize.

/**
 * merge having to where if it can be merged
 *
 * @param qtn
 */
public static void optimize(PlanNode qtn) {
    if (qtn.getHavingFilter() != null) {
        List<Item> subFilters = FilterUtils.splitFilter(qtn.getHavingFilter());
        List<Item> canMergeSubs = new ArrayList<>();
        for (Item subFilter : subFilters) {
            if (!subFilter.isWithSumFunc()) {
                canMergeSubs.add(subFilter);
            }
        }
        subFilters.removeAll(canMergeSubs);
        qtn.having(FilterUtils.and(subFilters));
        qtn.setWhereFilter(FilterUtils.and(qtn.getWhereFilter(), FilterUtils.and(canMergeSubs)));
    }
    for (PlanNode child : qtn.getChildren()) optimize(child);
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) PlanNode(com.actiontech.dble.plan.node.PlanNode) ArrayList(java.util.ArrayList)

Example 73 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class JoinNode method copy.

@Override
public JoinNode copy() {
    JoinNode newJoinNode = new JoinNode();
    this.copySelfTo(newJoinNode);
    newJoinNode.setJoinFilter(new ArrayList<ItemFuncEqual>());
    for (Item bf : joinFilter) {
        newJoinNode.addJoinFilter((ItemFuncEqual) bf.cloneStruct());
    }
    newJoinNode.setLeftNode(this.getLeftNode().copy());
    newJoinNode.setRightNode(this.getRightNode().copy());
    newJoinNode.setNeedOptimizeJoinOrder(this.isNeedOptimizeJoinOrder());
    newJoinNode.leftOuter = this.leftOuter;
    newJoinNode.rightOuter = this.rightOuter;
    newJoinNode.isNotIn = this.isNotIn;
    newJoinNode.otherJoinOnFilter = this.otherJoinOnFilter == null ? null : this.otherJoinOnFilter.cloneItem();
    return newJoinNode;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemFuncEqual(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)

Example 74 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class PlanNode method setUpGroupBy.

private void setUpGroupBy() {
    nameContext.setFindInSelect(true);
    nameContext.setSelectFirst(false);
    for (Order order : groups) {
        Item item = order.getItem();
        if (item.type() == Item.ItemType.INT_ITEM) {
            int index = item.valInt().intValue();
            if (index >= 1 && index <= getColumnsSelected().size())
                order.setItem(getColumnsSelected().get(index - 1));
            else
                throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "Unknown column '" + index + "' in group statement");
        } else {
            order.setItem(setUpItem(item));
        }
    }
}
Also used : Order(com.actiontech.dble.plan.Order) Item(com.actiontech.dble.plan.common.item.Item) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 75 with Item

use of com.actiontech.dble.plan.common.item.Item in project dble by actiontech.

the class PlanNode method setUpOrderBy.

private void setUpOrderBy() {
    nameContext.setFindInSelect(true);
    nameContext.setSelectFirst(true);
    for (Order order : orderBys) {
        Item item = order.getItem();
        if (item.type() == Item.ItemType.INT_ITEM) {
            int index = item.valInt().intValue();
            if (index >= 1 && index <= getColumnsSelected().size())
                order.setItem(getColumnsSelected().get(index - 1));
            else
                throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "Unknown column '" + index + "' in order statement");
        } else {
            order.setItem(setUpItem(item));
        }
    }
}
Also used : Order(com.actiontech.dble.plan.Order) Item(com.actiontech.dble.plan.common.item.Item) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Aggregations

Item (com.actiontech.dble.plan.common.item.Item)122 ArrayList (java.util.ArrayList)26 Order (com.actiontech.dble.plan.Order)16 PlanNode (com.actiontech.dble.plan.node.PlanNode)14 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)10 ItemField (com.actiontech.dble.plan.common.item.ItemField)10 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)7 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)7 Test (org.junit.Test)7 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)6 ItemFuncEqual (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)6 ItemSum (com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum)6 JoinNode (com.actiontech.dble.plan.node.JoinNode)6 SQLAggregateExpr (com.alibaba.druid.sql.ast.expr.SQLAggregateExpr)6 ItemFunc (com.actiontech.dble.plan.common.item.function.ItemFunc)5 ItemInt (com.actiontech.dble.plan.common.item.ItemInt)4 ItemString (com.actiontech.dble.plan.common.item.ItemString)4 BigDecimal (java.math.BigDecimal)4 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)3 NamedField (com.actiontech.dble.plan.NamedField)3