Search in sources :

Example 26 with MySQLOutPutException

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

the class MySQLPlanNodeVisitor method visit.

public boolean visit(SQLExprTableSource tableSource) {
    PlanNode table;
    SQLExpr expr = tableSource.getExpr();
    if (expr instanceof SQLPropertyExpr) {
        SQLPropertyExpr propertyExpr = (SQLPropertyExpr) expr;
        table = new TableNode(StringUtil.removeBackQuote(propertyExpr.getOwner().toString()), StringUtil.removeBackQuote(propertyExpr.getName()), this.metaManager);
        containSchema = true;
    } else if (expr instanceof SQLIdentifierExpr) {
        SQLIdentifierExpr identifierExpr = (SQLIdentifierExpr) expr;
        if (identifierExpr.getName().equalsIgnoreCase("dual")) {
            this.tableNode = new NoNameNode(currentDb, null);
            return true;
        }
        // here to check if the table name is a view in metaManager
        QueryNode viewNode = metaManager.getSyncView(currentDb, identifierExpr.getName());
        if (viewNode != null) {
            // consider if the table with other name
            viewNode.setAlias(tableSource.getAlias() == null ? identifierExpr.getName() : tableSource.getAlias());
            this.tableNode = viewNode;
            this.tableNode.setSubQuery(true);
            this.tableNode.setExistView(true);
            return true;
        } else {
            table = new TableNode(this.currentDb, StringUtil.removeBackQuote(identifierExpr.getName()), this.metaManager);
        }
    } else {
        throw new MySQLOutPutException(ErrorCode.ER_PARSE_ERROR, "42000", "table is " + tableSource.toString());
    }
    ((TableNode) table).setHintList(tableSource.getHints());
    this.tableNode = table;
    return true;
}
Also used : SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLPropertyExpr(com.alibaba.druid.sql.ast.expr.SQLPropertyExpr) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 27 with MySQLOutPutException

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

the class MergeNode method setUpSelects.

@Override
protected void setUpSelects() {
    columnsSelected.clear();
    PlanNode firstNode = getChild();
    outerFields.clear();
    Set<NamedField> checkDup = new HashSet<>(firstNode.getOuterFields().size(), 1);
    for (NamedField coutField : firstNode.getOuterFields().keySet()) {
        ItemField column = new ItemField(null, null, coutField.getName());
        NamedField tmpField = new NamedField(coutField.getTable(), coutField.getName(), this);
        NamedField testDupField = new NamedField(null, coutField.getName(), this);
        if (checkDup.contains(testDupField) && getParent() != null) {
            throw new MySQLOutPutException(ErrorCode.ER_DUP_FIELDNAME, "", "Duplicate column name " + coutField.getName());
        }
        checkDup.add(testDupField);
        outerFields.put(tmpField, column);
        getColumnsSelected().add(column);
    }
}
Also used : NamedField(com.actiontech.dble.plan.NamedField) ItemField(com.actiontech.dble.plan.common.item.ItemField) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 28 with MySQLOutPutException

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

the class PlanNode method setUpGroupBy.

private void setUpGroupBy() {
    nameContext.setFindInSelect(true);
    nameContext.setSelectFirst(false);
    for (Order order : groups) {
        Item item = order.getItem();
        if (item.type() == Item.ItemType.INT_ITEM) {
            int index = item.valInt().intValue();
            if (index >= 1 && index <= getColumnsSelected().size())
                order.setItem(getColumnsSelected().get(index - 1));
            else
                throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "Unknown column '" + index + "' in group statement");
        } else {
            order.setItem(setUpItem(item));
        }
    }
}
Also used : Order(com.actiontech.dble.plan.Order) Item(com.actiontech.dble.plan.common.item.Item) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 29 with MySQLOutPutException

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

the class PlanNode method setUpOrderBy.

private void setUpOrderBy() {
    nameContext.setFindInSelect(true);
    nameContext.setSelectFirst(true);
    for (Order order : orderBys) {
        Item item = order.getItem();
        if (item.type() == Item.ItemType.INT_ITEM) {
            int index = item.valInt().intValue();
            if (index >= 1 && index <= getColumnsSelected().size())
                order.setItem(getColumnsSelected().get(index - 1));
            else
                throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "Unknown column '" + index + "' in order statement");
        } else {
            order.setItem(setUpItem(item));
        }
    }
}
Also used : Order(com.actiontech.dble.plan.Order) Item(com.actiontech.dble.plan.common.item.Item) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 30 with MySQLOutPutException

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

the class QueryNode method setUpInnerFields.

@Override
protected void setUpInnerFields() {
    innerFields.clear();
    for (PlanNode child : children) {
        child.setUpFields();
        for (NamedField childOutField : child.outerFields.keySet()) {
            NamedField tmpField = new NamedField(this.getAlias(), childOutField.getName(), childOutField.planNode);
            if (innerFields.containsKey(tmpField) && getParent() != null)
                throw new MySQLOutPutException(ErrorCode.ER_DUP_FIELDNAME, "42S21", "Duplicate column name '" + childOutField.getName() + "'");
            innerFields.put(tmpField, childOutField);
        }
    }
}
Also used : NamedField(com.actiontech.dble.plan.NamedField) 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