Search in sources :

Example 31 with MySQLOutPutException

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

the class HandlerTool method createFieldItem.

protected static ItemField createFieldItem(Item col, List<Field> fields, int startIndex) {
    int index = findField(col, fields, startIndex);
    if (index < 0)
        throw new MySQLOutPutException(ErrorCode.ER_QUERYHANDLER, "", "field not found:" + col);
    ItemField ret = new ItemField(fields.get(index));
    ret.setItemName(col.getPushDownName() == null ? col.getItemName() : col.getPushDownName());
    return ret;
}
Also used : ItemField(com.actiontech.dble.plan.common.item.ItemField) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 32 with MySQLOutPutException

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

the class ItemCreate method createFuncCast.

public ItemFunc createFuncCast(Item a, CastType type) {
    CastTarget castType = type.getTarget();
    ItemFunc res = null;
    if (castType == CastTarget.ITEM_CAST_BINARY) {
        res = new ItemFuncBinary(a, type.getLength());
    } else if (castType == CastTarget.ITEM_CAST_SIGNED_INT) {
        res = new ItemFuncSigned(a);
    } else if (castType == CastTarget.ITEM_CAST_UNSIGNED_INT) {
        res = new ItemFuncUnsigned(a);
    } else if (castType == CastTarget.ITEM_CAST_DATE) {
        res = new ItemDateTypecast(a);
    } else if (castType == CastTarget.ITEM_CAST_TIME || castType == CastTarget.ITEM_CAST_DATETIME) {
        if (type.getLength() > MyTime.DATETIME_MAX_DECIMALS) {
            throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "too big precision in cast time/datetime,max 6,current:" + type.getLength());
        }
        if (type.getLength() == -1) {
            res = (castType == CastTarget.ITEM_CAST_TIME) ? new ItemTimeTypecast(a) : new ItemDatetimeTypecast(a);
        } else {
            res = (castType == CastTarget.ITEM_CAST_TIME) ? new ItemTimeTypecast(a, type.getLength()) : new ItemDatetimeTypecast(a, type.getLength());
        }
    } else if (castType == CastTarget.ITEM_CAST_DECIMAL) {
        if (type.getLength() < type.getDec()) {
            throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "For float(m,d), double(m,d) or decimal(m,d), M must be >= d");
        }
        if (type.getLength() > MySQLcom.DECIMAL_MAX_PRECISION) {
            throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "Too big precision " + type.getLength() + " max is " + MySQLcom.DECIMAL_MAX_PRECISION);
        }
        if (type.getDec() > MySQLcom.DECIMAL_MAX_SCALE) {
            throw new MySQLOutPutException(ErrorCode.ER_OPTIMIZER, "", "Too big scale " + type.getDec() + " max is " + MySQLcom.DECIMAL_MAX_SCALE);
        }
        res = new ItemDecimalTypecast(a, type.getLength(), type.getDec());
    } else if (castType == CastTarget.ITEM_CAST_NCHAR) {
        int len = -1;
        if (type.getLength() > 0)
            len = type.getLength();
        res = new ItemNCharTypecast(a, len);
    } else {
        assert (false);
    }
    return res;
}
Also used : CastTarget(com.actiontech.dble.plan.common.CastTarget) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 33 with MySQLOutPutException

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

the class JoinNodeHandlerBuilder method buildPre.

@Override
public List<DMLResponseHandler> buildPre() {
    List<DMLResponseHandler> pres = new ArrayList<>();
    PlanNode left = node.getLeftNode();
    PlanNode right = node.getRightNode();
    if (node.getStrategy() == JoinNode.Strategy.NESTLOOP) {
        final boolean isLeftSmall = left.getNestLoopFilters() == null;
        final PlanNode tnSmall = isLeftSmall ? left : right;
        final PlanNode tnBig = isLeftSmall ? right : left;
        // prepare the column for sending
        List<Item> keySources = isLeftSmall ? node.getLeftKeys() : node.getRightKeys();
        List<Item> keyToPasses = isLeftSmall ? node.getRightKeys() : node.getLeftKeys();
        // just find one key as filter later, try to choose a simple column(FIELD_ITEM) from toPasses
        int columnIndex = 0;
        for (int index = 0; index < keyToPasses.size(); index++) {
            Item keyToPass = keyToPasses.get(index);
            if (keyToPass.type().equals(ItemType.FIELD_ITEM)) {
                columnIndex = index;
                break;
            }
        }
        final Item keySource = keySources.get(columnIndex);
        final Item keyToPass = keyToPasses.get(columnIndex);
        DMLResponseHandler endHandler = buildJoinChild(tnSmall, isLeftSmall);
        final TempTableHandler tempHandler = new TempTableHandler(getSequenceId(), session, keySource);
        endHandler.setNextHandler(tempHandler);
        tempHandler.setLeft(isLeftSmall);
        pres.add(tempHandler);
        CallBackHandler tempDone = new CallBackHandler() {

            @Override
            public void call() throws Exception {
                Set<String> valueSet = tempHandler.getValueSet();
                buildNestFilters(tnBig, keyToPass, valueSet, tempHandler.getMaxPartSize());
                DMLResponseHandler bigLh = buildJoinChild(tnBig, !isLeftSmall);
                synchronized (tempHandler) {
                    bigLh.setNextHandler(tempHandler.getNextHandler());
                }
                tempHandler.setCreatedHandler(bigLh);
                HandlerBuilder.startHandler(bigLh);
            }
        };
        if (isExplain) {
            buildNestFiltersForExplain(tnBig, keyToPass);
            DMLResponseHandler bigLh = buildJoinChild(tnBig, !isLeftSmall);
            tempHandler.setCreatedHandler(bigLh);
        }
        tempHandler.setTempDoneCallBack(tempDone);
    } else if (node.getStrategy() == JoinNode.Strategy.SORTMERGE) {
        DMLResponseHandler lh = buildJoinChild(left, true);
        pres.add(lh);
        DMLResponseHandler rh = buildJoinChild(right, false);
        pres.add(rh);
    } else {
        throw new MySQLOutPutException(ErrorCode.ER_QUERYHANDLER, "", "strategy [" + node.getStrategy() + "] not implement yet!");
    }
    return pres;
}
Also used : ArrayList(java.util.ArrayList) TempTableHandler(com.actiontech.dble.backend.mysql.nio.handler.query.impl.TempTableHandler) ItemString(com.actiontech.dble.plan.common.item.ItemString) Item(com.actiontech.dble.plan.common.item.Item) PlanNode(com.actiontech.dble.plan.node.PlanNode) CallBackHandler(com.actiontech.dble.backend.mysql.nio.handler.util.CallBackHandler) DMLResponseHandler(com.actiontech.dble.backend.mysql.nio.handler.query.DMLResponseHandler) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 34 with MySQLOutPutException

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

the class TableNodeHandlerBuilder method nestLoopBuild.

@Override
protected void nestLoopBuild() {
    try {
        List<Item> filters = node.getNestLoopFilters();
        PushDownVisitor pdVisitor = new PushDownVisitor(node, true);
        if (filters == null || filters.isEmpty())
            throw new MySQLOutPutException(ErrorCode.ER_QUERYHANDLER, "", "unexpected exception!");
        List<RouteResultsetNode> rrssList = new ArrayList<>();
        MergeBuilder mergeBuilder = new MergeBuilder(session, node, needCommon, pdVisitor);
        if (tableConfig == null || tableConfig.getTableType() == TableTypeEnum.TYPE_GLOBAL_TABLE) {
            for (Item filter : filters) {
                node.setWhereFilter(filter);
                RouteResultsetNode[] rrssArray = mergeBuilder.construct().getNodes();
                rrssList.addAll(Arrays.asList(rrssArray));
            }
            if (filters.size() == 1) {
                this.needCommon = false;
            }
        } else {
            boolean tryGlobal = filters.size() == 1;
            for (Item filter : filters) {
                node.setWhereFilter(filter);
                pdVisitor.visit();
                RouteResultsetNode[] rrssArray = mergeBuilder.construct().getNodes();
                rrssList.addAll(Arrays.asList(rrssArray));
            }
            if (tryGlobal) {
                this.needCommon = mergeBuilder.getNeedCommonFlag();
            }
        }
        RouteResultsetNode[] rrssArray = new RouteResultsetNode[rrssList.size()];
        rrssArray = rrssList.toArray(rrssArray);
        buildMergeHandler(node, rrssArray);
    } catch (Exception e) {
        throw new MySQLOutPutException(ErrorCode.ER_QUERYHANDLER, "", "", e);
    }
}
Also used : Item(com.actiontech.dble.plan.common.item.Item) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) ArrayList(java.util.ArrayList) PushDownVisitor(com.actiontech.dble.backend.mysql.nio.handler.builder.sqlvisitor.PushDownVisitor) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 35 with MySQLOutPutException

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

the class TableNodeHandlerBuilder method buildOwn.

@Override
public void buildOwn() {
    try {
        PushDownVisitor pdVisitor = new PushDownVisitor(node, true);
        MergeBuilder mergeBuilder = new MergeBuilder(session, node, needCommon, pdVisitor);
        String sql = null;
        if (node.getAst() != null && node.getParent() == null) {
            // it's root
            pdVisitor.visit();
            sql = pdVisitor.getSql().toString();
        }
        RouteResultsetNode[] rrssArray;
        // maybe some node is view
        if (sql == null) {
            rrssArray = mergeBuilder.construct().getNodes();
        } else {
            rrssArray = mergeBuilder.constructByStatement(sql, node.getAst()).getNodes();
        }
        this.needCommon = mergeBuilder.getNeedCommonFlag();
        buildMergeHandler(node, rrssArray);
    } catch (Exception e) {
        throw new MySQLOutPutException(ErrorCode.ER_QUERYHANDLER, "", "table node buildOwn exception!", e);
    }
}
Also used : RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) PushDownVisitor(com.actiontech.dble.backend.mysql.nio.handler.builder.sqlvisitor.PushDownVisitor) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException) 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