Search in sources :

Example 6 with NamedField

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

use of com.actiontech.dble.plan.NamedField 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 8 with NamedField

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

the class PlanNode method setUpInnerFields.

protected void setUpInnerFields() {
    innerFields.clear();
    String tmpFieldTable;
    String tmpFieldName;
    for (PlanNode child : children) {
        child.setUpFields();
        for (NamedField coutField : child.outerFields.keySet()) {
            tmpFieldTable = child.getAlias() == null ? coutField.getTable() : child.getAlias();
            tmpFieldName = coutField.getName();
            NamedField tmpField = new NamedField(tmpFieldTable, tmpFieldName, coutField.planNode);
            if (innerFields.containsKey(tmpField) && getParent() != null)
                throw new MySQLOutPutException(ErrorCode.ER_DUP_FIELDNAME, "42S21", "Duplicate column name '" + tmpFieldName + "'");
            innerFields.put(tmpField, coutField);
        }
    }
}
Also used : NamedField(com.actiontech.dble.plan.NamedField) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 9 with NamedField

use of com.actiontech.dble.plan.NamedField 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 10 with NamedField

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

the class PlanUtil method findColumnInTableLeaf.

/**
 * check obj is the column of an real tablenode ,if obj is not Column Type return null
 * <the column to be found must be  table's parent's column>
 *
 * @param column column
 * @param node node
 * @return the target table node and the column
 */
public static Pair<TableNode, ItemField> findColumnInTableLeaf(ItemField column, PlanNode node) {
    // union return
    if (node.type() == PlanNodeType.MERGE)
        return null;
    NamedField tmpField = new NamedField(column.getTableName(), column.getItemName(), null);
    NamedField coutField = node.getInnerFields().get(tmpField);
    if (coutField == null)
        return null;
    else if (node.type() == PlanNodeType.TABLE) {
        return new Pair<>((TableNode) node, column);
    } else {
        PlanNode referNode = column.getReferTables().iterator().next();
        Item cSel = referNode.getOuterFields().get(coutField);
        if (cSel instanceof ItemField) {
            return findColumnInTableLeaf((ItemField) cSel, referNode);
        } else {
            return null;
        }
    }
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) NamedField(com.actiontech.dble.plan.NamedField) TableNode(com.actiontech.dble.plan.node.TableNode)

Aggregations

NamedField (com.actiontech.dble.plan.NamedField)15 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)9 ItemField (com.actiontech.dble.plan.common.item.ItemField)6 Item (com.actiontech.dble.plan.common.item.Item)3 PlanNode (com.actiontech.dble.plan.node.PlanNode)3 StructureMeta (com.actiontech.dble.meta.protocol.StructureMeta)1 JoinNode (com.actiontech.dble.plan.node.JoinNode)1 TableNode (com.actiontech.dble.plan.node.TableNode)1 ArrayList (java.util.ArrayList)1