Search in sources :

Example 6 with MySQLOutPutException

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

the class MySQLItemVisitor method endVisit.

@Override
public void endVisit(SQLBinaryExpr x) {
    String binary = x.getValue();
    if (StringUtil.equals(binary, "")) {
        item = new ItemString(binary);
    } else {
        try {
            item = new ItemInt(Long.parseLong(binary, 2));
        } catch (NumberFormatException e) {
            throw new MySQLOutPutException(ErrorCode.ER_PARSE_ERROR, "", "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near " + x.toString());
        }
    }
    initName(x);
}
Also used : MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 7 with MySQLOutPutException

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

the class MySQLItemVisitor method endVisit.

@Override
public void endVisit(SQLUnaryExpr x) {
    Item a = getItem(x.getExpr());
    switch(x.getOperator()) {
        case Negative:
            item = new ItemFuncNeg(a);
            break;
        case Not:
        case NOT:
            item = new ItemFuncNot(a);
            break;
        case Compl:
            item = new ItemFuncBitInversion(a);
            break;
        case Plus:
            item = a;
            break;
        case BINARY:
            item = new ItemFuncBinary(a, -1);
            break;
        default:
            throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "not supported kind expression:" + x.getOperator());
    }
    item.setWithSubQuery(a.isWithSubQuery());
    item.setCorrelatedSubQuery(a.isCorrelatedSubQuery());
    initName(x);
}
Also used : SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem) ItemFuncNot(com.actiontech.dble.plan.common.item.function.operator.logic.ItemFuncNot) ItemFuncBinary(com.actiontech.dble.plan.common.item.function.castfunc.ItemFuncBinary) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 8 with MySQLOutPutException

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

the class MySQLItemVisitor method endVisit.

@Override
public void endVisit(SQLCastExpr x) {
    Item a = getItem(x.getExpr());
    SQLDataType dataType = x.getDataType();
    if (dataType instanceof SQLCharacterDataType) {
        SQLCharacterDataType charType = (SQLCharacterDataType) dataType;
        String upType = charType.getName().toUpperCase();
        List<Integer> args = changeExprListToInt(charType.getArguments());
        String charSetName = charType.getCharSetName();
        if (upType.equals("CHAR")) {
            int len = -1;
            if (args.size() > 0) {
                len = args.get(0);
            }
            item = new ItemCharTypecast(a, len, charSetName);
        } else if (charSetName == null) {
            int len = -1;
            if (args.size() > 0) {
                len = args.get(0);
            }
            item = new ItemNCharTypecast(a, len);
        } else {
            throw new MySQLOutPutException(ErrorCode.ER_PARSE_ERROR, "", "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'character set " + charSetName + ")'");
        }
    } else {
        CastType castType = getCastType((SQLDataTypeImpl) dataType);
        item = ItemCreate.getInstance().createFuncCast(a, castType);
    }
    initName(x);
}
Also used : ItemNCharTypecast(com.actiontech.dble.plan.common.item.function.castfunc.ItemNCharTypecast) SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem) ItemCharTypecast(com.actiontech.dble.plan.common.item.function.castfunc.ItemCharTypecast) SQLCharacterDataType(com.alibaba.druid.sql.ast.statement.SQLCharacterDataType) CastType(com.actiontech.dble.plan.common.CastType) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 9 with MySQLOutPutException

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

the class MySQLItemVisitor method handleAnySubQuery.

private void handleAnySubQuery(SQLBinaryOpExpr parent, SQLSelectQuery sqlSelect, boolean isAll) {
    SQLBinaryOperator operator = parent.getOperator();
    switch(operator) {
        case Equality:
            if (isAll) {
                item = new ItemAllAnySubQuery(currentDb, sqlSelect, operator, true, metaManager);
            } else {
                Item left = getItem(parent.getLeft());
                item = new ItemInSubQuery(currentDb, sqlSelect, left, false, metaManager);
            }
            break;
        case NotEqual:
        case LessThanOrGreater:
            if (isAll) {
                Item left = getItem(parent.getLeft());
                item = new ItemInSubQuery(currentDb, sqlSelect, left, true, metaManager);
            } else {
                item = new ItemAllAnySubQuery(currentDb, sqlSelect, operator, false, metaManager);
            }
            break;
        case LessThan:
        case LessThanOrEqual:
        case GreaterThan:
        case GreaterThanOrEqual:
            item = new ItemAllAnySubQuery(currentDb, sqlSelect, operator, isAll, metaManager);
            break;
        default:
            throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near all");
    }
}
Also used : SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem) ItemAllAnySubQuery(com.actiontech.dble.plan.common.item.subquery.ItemAllAnySubQuery) ItemInSubQuery(com.actiontech.dble.plan.common.item.subquery.ItemInSubQuery) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 10 with MySQLOutPutException

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

the class MySQLItemVisitor method endVisit.

@Override
public void endVisit(SQLAggregateExpr x) {
    List<Item> args = visitExprList(x.getArguments());
    String funcName = x.getMethodName().toUpperCase();
    SQLAggregateOption option = x.getOption();
    boolean isDistinct = option != null;
    switch(funcName) {
        case "MAX":
            item = new ItemSumMax(args, false, null);
            break;
        case "MIN":
            item = new ItemSumMin(args, false, null);
            break;
        case "SUM":
            item = new ItemSumSum(args, isDistinct, false, null);
            break;
        case "AVG":
            item = new ItemSumAvg(args, isDistinct, false, null);
            break;
        case "GROUP_CONCAT":
            SQLOrderBy orderExpr = (SQLOrderBy) x.getAttribute(ItemFuncKeyWord.ORDER_BY);
            List<Order> orderList = null;
            if (orderExpr != null) {
                orderList = new ArrayList<>();
                for (SQLSelectOrderByItem orderItem : orderExpr.getItems()) {
                    Order order = new Order(getItem(orderItem.getExpr()), orderItem.getType());
                    orderList.add(order);
                }
            }
            SQLCharExpr charExpr = (SQLCharExpr) x.getAttribute(ItemFuncKeyWord.SEPARATOR);
            String separator = ",";
            if (charExpr != null) {
                separator = charExpr.getText();
            }
            item = new ItemFuncGroupConcat(args, isDistinct, orderList, separator, false, null);
            break;
        case "COUNT":
            item = new ItemSumCount(args, isDistinct, false, null);
            break;
        case "STDDEV":
            item = new ItemSumStd(args, 0, false, null);
            break;
        default:
            throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "not supported " + funcName);
    }
}
Also used : Order(com.actiontech.dble.plan.Order) SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem) SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem) 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