Search in sources :

Example 11 with MySQLOutPutException

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

the class MySQLItemVisitor method getCastType.

private CastType getCastType(SQLDataTypeImpl dataTypeImpl) {
    CastType castType = new CastType();
    String upType = dataTypeImpl.getName().toUpperCase();
    List<Integer> args = changeExprListToInt(dataTypeImpl.getArguments());
    switch(upType) {
        case "BINARY":
            castType.setTarget(CastTarget.ITEM_CAST_BINARY);
            if (args.size() > 0) {
                castType.setLength(args.get(0));
            }
            break;
        case "DATE":
            castType.setTarget(CastTarget.ITEM_CAST_DATE);
            break;
        case "DATETIME":
            castType.setTarget(CastTarget.ITEM_CAST_DATETIME);
            if (args.size() > 0) {
                castType.setLength(args.get(0));
            }
            break;
        case "DECIMAL":
            castType.setTarget(CastTarget.ITEM_CAST_DECIMAL);
            if (args.size() > 0) {
                castType.setLength(args.get(0));
            }
            if (args.size() > 1) {
                castType.setDec(args.get(1));
            }
            break;
        case "NCHAR":
            castType.setTarget(CastTarget.ITEM_CAST_NCHAR);
            if (args.size() > 0) {
                castType.setLength(args.get(0));
            }
            break;
        case "SIGNED":
            castType.setTarget(CastTarget.ITEM_CAST_SIGNED_INT);
            break;
        case "UNSIGNED":
            castType.setTarget(CastTarget.ITEM_CAST_UNSIGNED_INT);
            break;
        case "TIME":
            castType.setTarget(CastTarget.ITEM_CAST_TIME);
            if (args.size() > 0) {
                castType.setLength(args.get(0));
            }
            break;
        default:
            // not support SIGNED INT /UNSIGNED INT/JSON
            throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "not supported cast as:" + upType);
    }
    return castType;
}
Also used : CastType(com.actiontech.dble.plan.common.CastType) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 12 with MySQLOutPutException

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

the class NonBlockingSession method executeMultiSelect.

private void executeMultiSelect(RouteResultset rrs) {
    SQLSelectStatement ast = (SQLSelectStatement) rrs.getSqlStatement();
    MySQLPlanNodeVisitor visitor = new MySQLPlanNodeVisitor(this.getSource().getSchema(), this.getSource().getCharset().getResultsIndex(), DbleServer.getInstance().getTmManager(), false);
    visitor.visit(ast);
    PlanNode node = visitor.getTableNode();
    if (node.isCorrelatedSubQuery()) {
        throw new MySQLOutPutException(ErrorCode.ER_UNKNOWN_ERROR, "", "Correlated Sub Queries is not supported ");
    }
    node.setSql(rrs.getStatement());
    node.setUpFields();
    PlanUtil.checkTablesPrivilege(source, node, ast);
    node = MyOptimizer.optimize(node);
    if (PlanUtil.containsSubQuery(node)) {
        final PlanNode finalNode = node;
        DbleServer.getInstance().getComplexQueryExecutor().execute(new Runnable() {

            // sub Query build will be blocked, so use ComplexQueryExecutor
            @Override
            public void run() {
                executeMultiResultSet(finalNode);
            }
        });
    } else {
        if (!visitor.isContainSchema()) {
            node.setAst(ast);
        }
        executeMultiResultSet(node);
    }
}
Also used : PlanNode(com.actiontech.dble.plan.node.PlanNode) SQLSelectStatement(com.alibaba.druid.sql.ast.statement.SQLSelectStatement) MySQLPlanNodeVisitor(com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 13 with MySQLOutPutException

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

the class NonBlockingSession method executeMultiResultSet.

private void executeMultiResultSet(PlanNode node) {
    init();
    HandlerBuilder builder = new HandlerBuilder(node, this);
    try {
        // no next
        builder.build(false);
    } catch (SQLSyntaxErrorException e) {
        LOGGER.info(String.valueOf(source) + " execute plan is : " + node, e);
        source.writeErrMessage(ErrorCode.ER_YES, "optimizer build error");
    } catch (NoSuchElementException e) {
        LOGGER.info(String.valueOf(source) + " execute plan is : " + node, e);
        this.terminate();
        source.writeErrMessage(ErrorCode.ER_NO_VALID_CONNECTION, "no valid connection");
    } catch (MySQLOutPutException e) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info(String.valueOf(source) + " execute plan is : " + node, e);
        }
        this.terminate();
        source.writeErrMessage(e.getSqlState(), e.getMessage(), e.getErrorCode());
    } catch (Exception e) {
        LOGGER.info(String.valueOf(source) + " execute plan is : " + node, e);
        this.terminate();
        source.writeErrMessage(ErrorCode.ER_HANDLE_DATA, e.toString());
    }
}
Also used : SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) HandlerBuilder(com.actiontech.dble.backend.mysql.nio.handler.builder.HandlerBuilder) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 14 with MySQLOutPutException

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

the class JoinNode method buildJoinFilters.

private void buildJoinFilters() {
    nameContext.setFindInSelect(false);
    nameContext.setSelectFirst(false);
    if (usingFields != null) {
        for (String using : usingFields) {
            using = StringUtil.removeBackQuote(using);
            String lName = findTbNameByUsing(this.getLeftNode(), using);
            String rName = findTbNameByUsing(this.getRightNode(), using);
            if (lName.equals(rName)) {
                throw new MySQLOutPutException(ErrorCode.ER_NONUNIQ_TABLE, "42000", "Not unique table/alias: '" + lName + "'");
            }
            Item filter = setUpItem(genJoinFilter(using, lName, rName));
            joinFilter.add((ItemFuncEqual) filter);
        }
    } else {
        for (int index = 0; index < joinFilter.size(); index++) {
            Item bf = joinFilter.get(index);
            bf = setUpItem(bf);
            if (bf.getReferTables().size() == 1) {
                throw new MySQLOutPutException(ErrorCode.ER_NONUNIQ_TABLE, "42000", "Not unique table/alias: '" + this.getLeftNode().getPureName() + "'");
            }
            joinFilter.set(index, (ItemFuncEqual) bf);
        }
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 15 with MySQLOutPutException

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

the class JoinNode method getFieldList.

private List<String> getFieldList(PlanNode node) {
    List<String> fields = new ArrayList<>();
    Set<String> checkDup = new HashSet<>();
    for (NamedField field : node.getOuterFields().keySet()) {
        String fieldName = field.getName().toLowerCase();
        if (checkDup.contains(fieldName)) {
            throw new MySQLOutPutException(ErrorCode.ER_DUP_FIELDNAME, "42S21", " Duplicate column name '" + fieldName + "'");
        }
        checkDup.add(fieldName);
        fields.add(fieldName);
    }
    return fields;
}
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