Search in sources :

Example 1 with PlanNode

use of com.actiontech.dble.plan.node.PlanNode in project dble by actiontech.

the class QueryNodeHandlerBuilder method buildPre.

@Override
public List<DMLResponseHandler> buildPre() {
    List<DMLResponseHandler> pres = new ArrayList<>();
    PlanNode subNode = node.getChild();
    BaseHandlerBuilder builder = hBuilder.getBuilder(session, subNode, isExplain);
    if (builder.getSubQueryBuilderList().size() > 0) {
        this.getSubQueryBuilderList().addAll(builder.getSubQueryBuilderList());
    }
    DMLResponseHandler subHandler = builder.getEndHandler();
    pres.add(subHandler);
    return pres;
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) DMLResponseHandler(com.actiontech.dble.backend.mysql.nio.handler.query.DMLResponseHandler) ArrayList(java.util.ArrayList)

Example 2 with PlanNode

use of com.actiontech.dble.plan.node.PlanNode in project dble by actiontech.

the class ItemField method getMergeNodeColumn.

private Item getMergeNodeColumn(String tmpFieldTable, String tmpFieldName, PlanNode planNode) {
    // select union only found in outerfields
    Item column;
    if (StringUtils.isEmpty(getTableName())) {
        PlanNode firstNode = planNode.getChild();
        boolean found = false;
        for (NamedField coutField : firstNode.getOuterFields().keySet()) {
            if (tmpFieldName.equalsIgnoreCase(coutField.getName())) {
                if (!found) {
                    tmpFieldTable = coutField.getTable();
                    found = true;
                } else {
                    throw new MySQLOutPutException(ErrorCode.ER_BAD_FIELD_ERROR, "(42S22", "Unknown column '" + tmpFieldName + "' in 'order clause'");
                }
            }
        }
        column = planNode.getOuterFields().get(new NamedField(tmpFieldTable, tmpFieldName, null));
    } else {
        throw new MySQLOutPutException(ErrorCode.ER_TABLENAME_NOT_ALLOWED_HERE, "42000", "Table '" + getTableName() + "' from one of the SELECTs cannot be used in global ORDER clause");
    }
    return column;
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) NamedField(com.actiontech.dble.plan.NamedField) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 3 with PlanNode

use of com.actiontech.dble.plan.node.PlanNode in project dble by actiontech.

the class ItemField method fixFields.

@Override
public Item fixFields(NameResolutionContext context) {
    if (this.isWild())
        return this;
    String tmpFieldTable = null;
    String tmpFieldName = getItemName();
    PlanNode planNode = context.getPlanNode();
    if (context.getPlanNode().type() == PlanNodeType.MERGE) {
        return getMergeNodeColumn(tmpFieldTable, tmpFieldName, planNode);
    }
    Item column = null;
    if (context.isFindInSelect()) {
        // try to find in selectlist
        if (StringUtils.isEmpty(getTableName())) {
            for (NamedField namedField : planNode.getOuterFields().keySet()) {
                if (StringUtils.equalsIgnoreCase(tmpFieldName, namedField.getName())) {
                    if (column == null) {
                        column = planNode.getOuterFields().get(namedField);
                    } else
                        throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "42S22", "duplicate column:" + this);
                }
            }
        } else {
            tmpFieldTable = getTableName();
            column = planNode.getOuterFields().get(new NamedField(tmpFieldTable, tmpFieldName, null));
        }
    }
    if (column != null && context.isSelectFirst()) {
        return column;
    }
    // find from inner fields
    Item columnFromMeta = null;
    if (StringUtils.isEmpty(getTableName())) {
        for (NamedField namedField : planNode.getInnerFields().keySet()) {
            if (StringUtils.equalsIgnoreCase(tmpFieldName, namedField.getName())) {
                if (columnFromMeta == null) {
                    tmpFieldTable = namedField.getTable();
                    NamedField coutField = planNode.getInnerFields().get(new NamedField(tmpFieldTable, tmpFieldName, null));
                    this.tableName = namedField.getTable();
                    getReferTables().clear();
                    this.getReferTables().add(coutField.planNode);
                    columnFromMeta = this;
                } else {
                    if (planNode.type() == PlanNodeType.JOIN) {
                        JoinNode jn = (JoinNode) planNode;
                        if (jn.getUsingFields() != null && jn.getUsingFields().contains(columnFromMeta.getItemName().toLowerCase())) {
                            continue;
                        }
                    }
                    throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "42S22", "duplicate column:" + this);
                }
            }
        }
    } else {
        tmpFieldTable = getTableName();
        NamedField tmpField = new NamedField(tmpFieldTable, tmpFieldName, null);
        if (planNode.getInnerFields().containsKey(tmpField)) {
            NamedField coutField = planNode.getInnerFields().get(tmpField);
            getReferTables().clear();
            getReferTables().add(coutField.planNode);
            this.tableName = tmpField.getTable();
            columnFromMeta = this;
        }
    }
    if (columnFromMeta != null) {
        return columnFromMeta;
    } else if (column == null)
        throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "42S22", "column " + this + " not found");
    else {
        return column;
    }
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) NamedField(com.actiontech.dble.plan.NamedField) JoinNode(com.actiontech.dble.plan.node.JoinNode) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 4 with PlanNode

use of com.actiontech.dble.plan.node.PlanNode in project dble by actiontech.

the class ItemField method fixRefer.

@Override
public void fixRefer(ReferContext context) {
    if (isWild())
        return;
    PlanNode node = context.getPlanNode();
    PlanNode tn = getReferTables().iterator().next();
    node.addSelToReferedMap(tn, this);
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode)

Example 5 with PlanNode

use of com.actiontech.dble.plan.node.PlanNode in project dble by actiontech.

the class FilterPusher method getQueryNode.

private static PlanNode getQueryNode(PlanNode qtn, List<Item> dnfNodeToPush) {
    if (qtn.getSubQueries().size() > 0) {
        Item node = FilterUtils.and(dnfNodeToPush);
        if (node != null) {
            qtn.query(FilterUtils.and(qtn.getWhereFilter(), node));
        }
        return qtn;
    }
    refreshPdFilters(qtn, dnfNodeToPush);
    PlanNode child = pushFilter(qtn.getChild(), dnfNodeToPush);
    ((QueryNode) qtn).setChild(child);
    return qtn;
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) PlanNode(com.actiontech.dble.plan.node.PlanNode) QueryNode(com.actiontech.dble.plan.node.QueryNode)

Aggregations

PlanNode (com.actiontech.dble.plan.node.PlanNode)50 JoinNode (com.actiontech.dble.plan.node.JoinNode)16 Item (com.actiontech.dble.plan.common.item.Item)14 ArrayList (java.util.ArrayList)10 QueryNode (com.actiontech.dble.plan.node.QueryNode)8 ItemFuncEqual (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)6 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)5 MySQLPlanNodeVisitor (com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor)5 ItemSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemSubQuery)4 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)4 DMLResponseHandler (com.actiontech.dble.backend.mysql.nio.handler.query.DMLResponseHandler)3 NamedField (com.actiontech.dble.plan.NamedField)3 ErrorPacket (com.actiontech.dble.net.mysql.ErrorPacket)2 Order (com.actiontech.dble.plan.Order)2 TableNode (com.actiontech.dble.plan.node.TableNode)2 HashSet (java.util.HashSet)2 BaseHandlerBuilder (com.actiontech.dble.backend.mysql.nio.handler.builder.BaseHandlerBuilder)1 HandlerBuilder (com.actiontech.dble.backend.mysql.nio.handler.builder.HandlerBuilder)1 TempTableHandler (com.actiontech.dble.backend.mysql.nio.handler.query.impl.TempTableHandler)1 CallBackHandler (com.actiontech.dble.backend.mysql.nio.handler.util.CallBackHandler)1