Search in sources :

Example 1 with CallBackHandler

use of com.actiontech.dble.backend.mysql.nio.handler.util.CallBackHandler in project dble by actiontech.

the class BaseHandlerBuilder method handleSubQuery.

private void handleSubQuery(final ReentrantLock lock, final Condition finishSubQuery, final AtomicBoolean finished, final AtomicInteger subNodes, final CopyOnWriteArrayList<ErrorPacket> errorPackets, final PlanNode planNode, final SubQueryHandler tempHandler) {
    DbleServer.getInstance().getComplexQueryExecutor().execute(new Runnable() {

        @Override
        public void run() {
            try {
                DMLResponseHandler endHandler = hBuilder.buildNode(session, planNode, false);
                endHandler.setNextHandler(tempHandler);
                CallBackHandler tempDone = new CallBackHandler() {

                    @Override
                    public void call() throws Exception {
                        if (tempHandler.getErrorPacket() != null) {
                            errorPackets.add(tempHandler.getErrorPacket());
                        }
                        subQueryFinished(subNodes, lock, finished, finishSubQuery);
                    }
                };
                tempHandler.setTempDoneCallBack(tempDone);
                HandlerBuilder.startHandler(endHandler);
            } catch (Exception e) {
                LOGGER.info("execute ItemScalarSubQuery error", e);
                ErrorPacket errorPackage = new ErrorPacket();
                errorPackage.setErrNo(ErrorCode.ER_UNKNOWN_ERROR);
                String errorMsg = e.getMessage() == null ? e.toString() : e.getMessage();
                errorPackage.setMessage(errorMsg.getBytes(StandardCharsets.UTF_8));
                errorPackets.add(errorPackage);
            }
        }
    });
}
Also used : CallBackHandler(com.actiontech.dble.backend.mysql.nio.handler.util.CallBackHandler) ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket) DMLResponseHandler(com.actiontech.dble.backend.mysql.nio.handler.query.DMLResponseHandler) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 2 with CallBackHandler

use of com.actiontech.dble.backend.mysql.nio.handler.util.CallBackHandler 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)

Aggregations

DMLResponseHandler (com.actiontech.dble.backend.mysql.nio.handler.query.DMLResponseHandler)2 CallBackHandler (com.actiontech.dble.backend.mysql.nio.handler.util.CallBackHandler)2 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)2 TempTableHandler (com.actiontech.dble.backend.mysql.nio.handler.query.impl.TempTableHandler)1 ErrorPacket (com.actiontech.dble.net.mysql.ErrorPacket)1 Item (com.actiontech.dble.plan.common.item.Item)1 ItemString (com.actiontech.dble.plan.common.item.ItemString)1 PlanNode (com.actiontech.dble.plan.node.PlanNode)1 ArrayList (java.util.ArrayList)1