Search in sources :

Example 36 with RouteResultsetNode

use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.

the class ServerLoadDataInfileHandler method parseOneLine.

private void parseOneLine(List<SQLExpr> columns, String table, String[] line, boolean toFile, String lineEnd) {
    if (loadData.getEnclose() != null && loadData.getEnclose().charAt(0) > 0x0020) {
        for (int i = 0; i < line.length; i++) {
            line[i] = line[i].trim();
        }
    }
    RouteResultset rrs = tryDirectRoute(sql, line);
    if (rrs == null || rrs.getNodes() == null || rrs.getNodes().length == 0) {
        String insertSql = makeSimpleInsert(columns, line, table);
        rrs = serverConnection.routeSQL(insertSql, ServerParse.INSERT);
    }
    if (rrs == null || rrs.getNodes() == null || rrs.getNodes().length == 0) {
    // do nothing
    } else {
        for (RouteResultsetNode routeResultsetNode : rrs.getNodes()) {
            String name = routeResultsetNode.getName();
            LoadData data = routeResultMap.get(name);
            if (data == null) {
                data = new LoadData();
                data.setCharset(loadData.getCharset());
                data.setEnclose(loadData.getEnclose());
                data.setFieldTerminatedBy(loadData.getFieldTerminatedBy());
                data.setLineTerminatedBy(loadData.getLineTerminatedBy());
                data.setEscape(loadData.getEscape());
                routeResultMap.put(name, data);
            }
            String jLine = joinField(line, data);
            if (data.getData() == null) {
                data.setData(Lists.newArrayList(jLine));
            } else {
                data.getData().add(jLine);
            }
            if (toFile && data.getData().size() > 10000) {
                // avoid OOM
                saveDataToFile(data, name);
            }
        }
    }
}
Also used : LoadData(com.actiontech.dble.sqlengine.mpp.LoadData) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) RouteResultset(com.actiontech.dble.route.RouteResultset)

Example 37 with RouteResultsetNode

use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.

the class SQLJob method run.

public void run() {
    try {
        if (ds == null) {
            RouteResultsetNode node = new RouteResultsetNode(dataNodeOrDatabase, ServerParse.SELECT, sql);
            // create new connection
            PhysicalDBNode dn = DbleServer.getInstance().getConfig().getDataNodes().get(node.getName());
            dn.getConnection(dn.getDatabase(), true, true, node, this, node);
        } else {
            ds.getConnection(dataNodeOrDatabase, true, this, null);
        }
    } catch (Exception e) {
        LOGGER.info("can't get connection for sql ,error:" + e);
        doFinished(true);
    }
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode)

Example 38 with RouteResultsetNode

use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.

the class BaseHandlerBuilder method noShardBuild.

/**
 * no shard-ing node,just send to the first node
 */
protected final void noShardBuild() {
    this.needCommon = false;
    GlobalVisitor visitor = new GlobalVisitor(node, true);
    visitor.visit();
    String sql = visitor.getSql().toString();
    RouteResultsetNode[] rrss = getTableSources(node.getNoshardNode(), sql);
    hBuilder.checkRRSs(rrss);
    MultiNodeMergeHandler mh = new MultiNodeMergeHandler(getSequenceId(), rrss, session.getSource().isAutocommit() && !session.getSource().isTxStart(), session, null);
    addHandler(mh);
}
Also used : RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) GlobalVisitor(com.actiontech.dble.backend.mysql.nio.handler.builder.sqlvisitor.GlobalVisitor)

Example 39 with RouteResultsetNode

use of com.actiontech.dble.route.RouteResultsetNode 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 40 with RouteResultsetNode

use of com.actiontech.dble.route.RouteResultsetNode 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

RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)48 BackendConnection (com.actiontech.dble.backend.BackendConnection)12 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)9 RouteResultset (com.actiontech.dble.route.RouteResultset)8 TableConfig (com.actiontech.dble.config.model.TableConfig)6 SQLNonTransientException (java.sql.SQLNonTransientException)6 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)5 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)5 PushDownVisitor (com.actiontech.dble.backend.mysql.nio.handler.builder.sqlvisitor.PushDownVisitor)4 AbstractPartitionAlgorithm (com.actiontech.dble.route.function.AbstractPartitionAlgorithm)4 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)4 ServerConfig (com.actiontech.dble.config.ServerConfig)3 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)3 RouteCalculateUnit (com.actiontech.dble.route.parser.druid.RouteCalculateUnit)3 LoadData (com.actiontech.dble.sqlengine.mpp.LoadData)3 LayerCachePool (com.actiontech.dble.cache.LayerCachePool)2 DruidShardingParseInfo (com.actiontech.dble.route.parser.druid.DruidShardingParseInfo)2 SQLException (java.sql.SQLException)2 SQLSyntaxErrorException (java.sql.SQLSyntaxErrorException)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2