Search in sources :

Example 1 with PushDownVisitor

use of com.actiontech.dble.backend.mysql.nio.handler.builder.sqlvisitor.PushDownVisitor in project dble by actiontech.

the class JoinNodeHandlerBuilder method mergeBuild.

@Override
public void mergeBuild() {
    try {
        this.needWhereHandler = false;
        this.canPushDown = !node.existUnPushDownGroup();
        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, "", "join node mergebuild exception!", e);
    }
}
Also used : RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) PushDownVisitor(com.actiontech.dble.backend.mysql.nio.handler.builder.sqlvisitor.PushDownVisitor) ItemString(com.actiontech.dble.plan.common.item.ItemString) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 2 with PushDownVisitor

use of com.actiontech.dble.backend.mysql.nio.handler.builder.sqlvisitor.PushDownVisitor in project dble by actiontech.

the class NoNameNodeHandlerBuilder method buildOwn.

@Override
public void buildOwn() {
    PushDownVisitor visitor = new PushDownVisitor(node, true);
    visitor.visit();
    this.canPushDown = true;
    String sql = visitor.getSql().toString();
    String schema = session.getSource().getSchema();
    SchemaConfig schemaConfig = schemaConfigMap.get(schema);
    RouteResultsetNode[] rrss = getTableSources(schemaConfig.getAllDataNodes(), sql);
    hBuilder.checkRRSs(rrss);
    MultiNodeMergeHandler mh = new MultiNodeMergeHandler(getSequenceId(), rrss, session.getSource().isAutocommit() && !session.getSource().isTxStart(), session, null);
    addHandler(mh);
}
Also used : SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) MultiNodeMergeHandler(com.actiontech.dble.backend.mysql.nio.handler.query.impl.MultiNodeMergeHandler) PushDownVisitor(com.actiontech.dble.backend.mysql.nio.handler.builder.sqlvisitor.PushDownVisitor)

Example 3 with PushDownVisitor

use of com.actiontech.dble.backend.mysql.nio.handler.builder.sqlvisitor.PushDownVisitor 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 4 with PushDownVisitor

use of com.actiontech.dble.backend.mysql.nio.handler.builder.sqlvisitor.PushDownVisitor 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

PushDownVisitor (com.actiontech.dble.backend.mysql.nio.handler.builder.sqlvisitor.PushDownVisitor)4 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)4 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)3 MultiNodeMergeHandler (com.actiontech.dble.backend.mysql.nio.handler.query.impl.MultiNodeMergeHandler)1 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)1 Item (com.actiontech.dble.plan.common.item.Item)1 ItemString (com.actiontech.dble.plan.common.item.ItemString)1 ArrayList (java.util.ArrayList)1