Search in sources :

Example 6 with ItemField

use of com.actiontech.dble.plan.common.item.ItemField 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 7 with ItemField

use of com.actiontech.dble.plan.common.item.ItemField 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)

Example 8 with ItemField

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

the class ERJoinChooser method nodeHasSelectable.

private Item nodeHasSelectable(PlanNode child, Item sel) {
    if (sel instanceof ItemField) {
        return nodeHasColumn(child, (ItemField) sel);
    } else if (sel.canValued()) {
        return sel;
    } else if (sel.type().equals(Item.ItemType.SUM_FUNC_ITEM)) {
        return null;
    } else {
        ItemFunc fcopy = (ItemFunc) sel.cloneStruct();
        for (int index = 0; index < fcopy.getArgCount(); index++) {
            Item arg = fcopy.arguments().get(index);
            Item argSel = nodeHasSelectable(child, arg);
            if (argSel == null)
                return null;
            else
                fcopy.arguments().set(index, argSel);
        }
        PlanUtil.refreshReferTables(fcopy);
        fcopy.setPushDownName(null);
        return fcopy;
    }
}
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 9 with ItemField

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

the class FilterJoinColumnPusher method isPossibleERJoinColumnFilter.

/**
 * is ER Filter: 1.Filter must be equal(=) 2.Filter must be Column = Column
 * 3.Filter's key and value must be belong different table ex:a.id=b.id true a.id=b.id+1 false
 */
private static boolean isPossibleERJoinColumnFilter(PlanNode node, Item ifilter) {
    if (!(ifilter instanceof ItemFuncEqual))
        return false;
    ItemFuncEqual filter = (ItemFuncEqual) ifilter;
    Item column = filter.arguments().get(0);
    Item value = filter.arguments().get(1);
    if (column != null && column instanceof ItemField && value != null && value instanceof ItemField) {
        Pair<TableNode, ItemField> foundColumn = PlanUtil.findColumnInTableLeaf((ItemField) column, node);
        Pair<TableNode, ItemField> foundValue = PlanUtil.findColumnInTableLeaf((ItemField) value, node);
        if (foundColumn != null && foundValue != null) {
            String columnTable = foundColumn.getValue().getTableName();
            String valueTable = foundValue.getValue().getTableName();
            // the table must be different
            return !StringUtils.equals(columnTable, valueTable);
        } else {
            return false;
        }
    } else {
        return false;
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemFuncEqual(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual) TableNode(com.actiontech.dble.plan.node.TableNode) ItemField(com.actiontech.dble.plan.common.item.ItemField)

Example 10 with ItemField

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

the class MySQLPlanNodeVisitor method addJoinOnColumns.

private void addJoinOnColumns(Item ifilter, JoinNode joinNode) {
    if (ifilter instanceof ItemFuncEqual) {
        ItemFuncEqual filter = (ItemFuncEqual) ifilter;
        Item column = filter.arguments().get(0);
        Item value = filter.arguments().get(1);
        if (column != null && column instanceof ItemField && value != null && value instanceof ItemField) {
            joinNode.addJoinFilter(filter);
        } else {
            joinNode.setOtherJoinOnFilter(filter);
        }
    } else if (ifilter instanceof ItemCondAnd) {
        ItemCondAnd ilfand = (ItemCondAnd) ifilter;
        List<Item> subFilter = ilfand.arguments();
        if (subFilter != null) {
            for (Item arg : subFilter) {
                Item orgOtherJoin = joinNode.getOtherJoinOnFilter();
                addJoinOnColumns(arg, joinNode);
                joinNode.setOtherJoinOnFilter(FilterUtils.and(orgOtherJoin, joinNode.getOtherJoinOnFilter()));
            }
        } else {
            throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "and has no other columns , " + ifilter);
        }
    } else {
        joinNode.setOtherJoinOnFilter(ifilter);
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) ItemCondAnd(com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd) ItemFuncEqual(com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual) ItemField(com.actiontech.dble.plan.common.item.ItemField) ArrayList(java.util.ArrayList) List(java.util.List) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Aggregations

ItemField (com.actiontech.dble.plan.common.item.ItemField)20 Item (com.actiontech.dble.plan.common.item.Item)10 NamedField (com.actiontech.dble.plan.NamedField)6 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)6 ItemFuncEqual (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)4 ArrayList (java.util.ArrayList)4 ItemFunc (com.actiontech.dble.plan.common.item.function.ItemFunc)3 JoinNode (com.actiontech.dble.plan.node.JoinNode)3 TableNode (com.actiontech.dble.plan.node.TableNode)3 ERTable (com.actiontech.dble.config.model.ERTable)2 Order (com.actiontech.dble.plan.Order)2 Field (com.actiontech.dble.plan.common.field.Field)2 RowDataComparator (com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator)1 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)1 ItemCondAnd (com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd)1 ItemSum (com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum)1 PlanNode (com.actiontech.dble.plan.node.PlanNode)1 QueryNode (com.actiontech.dble.plan.node.QueryNode)1 List (java.util.List)1