Search in sources :

Example 46 with Item

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

the class JoinNode method buildJoinFilters.

private void buildJoinFilters() {
    nameContext.setFindInSelect(false);
    nameContext.setSelectFirst(false);
    if (usingFields != null) {
        for (String using : usingFields) {
            using = StringUtil.removeBackQuote(using);
            String lName = findTbNameByUsing(this.getLeftNode(), using);
            String rName = findTbNameByUsing(this.getRightNode(), using);
            if (lName.equals(rName)) {
                throw new MySQLOutPutException(ErrorCode.ER_NONUNIQ_TABLE, "42000", "Not unique table/alias: '" + lName + "'");
            }
            Item filter = setUpItem(genJoinFilter(using, lName, rName));
            joinFilter.add((ItemFuncEqual) filter);
        }
    } else {
        for (int index = 0; index < joinFilter.size(); index++) {
            Item bf = joinFilter.get(index);
            bf = setUpItem(bf);
            if (bf.getReferTables().size() == 1) {
                throw new MySQLOutPutException(ErrorCode.ER_NONUNIQ_TABLE, "42000", "Not unique table/alias: '" + this.getLeftNode().getPureName() + "'");
            }
            joinFilter.set(index, (ItemFuncEqual) bf);
        }
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 47 with Item

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

the class PlanNode method setUpRefers.

// column refered start
public void setUpRefers(boolean isPushDownNode) {
    sumFuncs.clear();
    referContext.setPushDownNode(isPushDownNode);
    // select
    for (Item sel : columnsSelected) {
        setUpItemRefer(sel);
    }
    if (type() == PlanNodeType.JOIN) {
        JoinNode jn = (JoinNode) this;
        if (!isPushDownNode) {
            for (Item bf : jn.getJoinFilter()) setUpItemRefer(bf);
            setUpItemRefer(jn.getOtherJoinOnFilter());
        }
    }
    // where, pushdown node does 't need where
    if (!isPushDownNode) {
        setUpItemRefer(whereFilter);
    }
    // group by
    for (Order groupBy : groups) {
        setUpItemRefer(groupBy.getItem());
    }
    // having
    setUpItemRefer(havingFilter);
    // order by
    for (Order orderBy : orderBys) {
        setUpItemRefer(orderBy.getItem());
    }
    // make list
    for (List<Item> selSet : columnsReferredCache.asMap().values()) {
        columnsReferList.addAll(selSet);
    }
}
Also used : Order(com.actiontech.dble.plan.Order) Item(com.actiontech.dble.plan.common.item.Item)

Example 48 with Item

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

the class PlanNode method setUpSelects.

protected void setUpSelects() {
    if (columnsSelected.isEmpty()) {
        columnsSelected.add(new ItemField(null, null, "*"));
    }
    boolean withWild = false;
    for (Item sel : columnsSelected) {
        if (sel.isWild())
            withWild = true;
    }
    if (withWild)
        dealStarColumn();
    outerFields.clear();
    nameContext.setFindInSelect(false);
    nameContext.setSelectFirst(false);
    for (Item sel : columnsSelected) {
        setUpItem(sel);
        NamedField field = makeOutNamedField(sel);
        if (outerFields.containsKey(field) && getParent() != null)
            throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "duplicate field");
        outerFields.put(field, sel);
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) NamedField(com.actiontech.dble.plan.NamedField) ItemField(com.actiontech.dble.plan.common.item.ItemField) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 49 with Item

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

the class PlanNode method dealStarColumn.

protected void dealStarColumn() {
    List<Item> newSels = new ArrayList<>();
    for (Item selItem : columnsSelected) {
        if (selItem.isWild()) {
            ItemField wildField = (ItemField) selItem;
            if (wildField.getTableName() == null || wildField.getTableName().length() == 0) {
                dealSingleStarColumn(newSels);
            } else {
                String selTable = wildField.getTableName();
                boolean found = false;
                for (NamedField field : innerFields.keySet()) {
                    if (selTable.equals(field.getTable())) {
                        ItemField col = new ItemField(null, field.getTable(), field.getName());
                        newSels.add(col);
                        found = true;
                    } else if (found) {
                        // a.* ->a.id,a.id1,b.id ,break when find b.id
                        break;
                    }
                }
                if (!found) {
                    throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "child table " + selTable + " not exist!");
                }
            }
        } else {
            newSels.add(selItem);
        }
    }
    columnsSelected = newSels;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) NamedField(com.actiontech.dble.plan.NamedField) ItemField(com.actiontech.dble.plan.common.item.ItemField) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 50 with Item

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

the class TableNode method dealStarColumn.

@Override
protected void dealStarColumn() {
    List<Item> newSelects = new ArrayList<>();
    for (Item sel : columnsSelected) {
        if (!sel.isWild())
            newSelects.add(sel);
        else {
            for (NamedField innerField : innerFields.keySet()) {
                ItemField col = new ItemField(null, sel.getTableName(), innerField.getName());
                newSelects.add(col);
            }
        }
    }
    columnsSelected = newSelects;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) NamedField(com.actiontech.dble.plan.NamedField) ArrayList(java.util.ArrayList) ItemField(com.actiontech.dble.plan.common.item.ItemField)

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