Search in sources :

Example 16 with MySQLOutPutException

use of com.actiontech.dble.plan.common.exception.MySQLOutPutException in project dble by actiontech.

the class JoinNode method findTbNameByUsing.

private String findTbNameByUsing(PlanNode node, String using) {
    String table = node.getCombinedName();
    if (table != null) {
        return table;
    }
    boolean found = false;
    for (NamedField field : node.getOuterFields().keySet()) {
        if (field.getName().equalsIgnoreCase(using)) {
            if (!found) {
                found = true;
                table = field.getTable();
            } else {
                throw new MySQLOutPutException(ErrorCode.ER_NON_UNIQ_ERROR, "23000", " Column '" + using + "' in from clause is ambiguous");
            }
        }
    }
    return table;
}
Also used : NamedField(com.actiontech.dble.plan.NamedField) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 17 with MySQLOutPutException

use of com.actiontech.dble.plan.common.exception.MySQLOutPutException 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 18 with MySQLOutPutException

use of com.actiontech.dble.plan.common.exception.MySQLOutPutException 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 19 with MySQLOutPutException

use of com.actiontech.dble.plan.common.exception.MySQLOutPutException 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 20 with MySQLOutPutException

use of com.actiontech.dble.plan.common.exception.MySQLOutPutException 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

MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)35 Item (com.actiontech.dble.plan.common.item.Item)10 NamedField (com.actiontech.dble.plan.NamedField)9 ItemField (com.actiontech.dble.plan.common.item.ItemField)6 SQLSelectOrderByItem (com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)6 PlanNode (com.actiontech.dble.plan.node.PlanNode)5 ArrayList (java.util.ArrayList)5 Order (com.actiontech.dble.plan.Order)4 PushDownVisitor (com.actiontech.dble.backend.mysql.nio.handler.builder.sqlvisitor.PushDownVisitor)3 ItemInSubQuery (com.actiontech.dble.plan.common.item.subquery.ItemInSubQuery)3 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)3 CastType (com.actiontech.dble.plan.common.CastType)2 ItemString (com.actiontech.dble.plan.common.item.ItemString)2 ItemFuncEqual (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)2 ItemCondAnd (com.actiontech.dble.plan.common.item.function.operator.logic.ItemCondAnd)2 ItemFuncNot (com.actiontech.dble.plan.common.item.function.operator.logic.ItemFuncNot)2 ItemAllAnySubQuery (com.actiontech.dble.plan.common.item.subquery.ItemAllAnySubQuery)2 JoinNode (com.actiontech.dble.plan.node.JoinNode)2 HandlerBuilder (com.actiontech.dble.backend.mysql.nio.handler.builder.HandlerBuilder)1 DMLResponseHandler (com.actiontech.dble.backend.mysql.nio.handler.query.DMLResponseHandler)1