Search in sources :

Example 6 with MiddlerResultHandler

use of io.mycat.backend.mysql.nio.handler.MiddlerResultHandler in project Mycat-Server by MyCATApache.

the class ShareRowOutPutDataHandler method onRowData.

@Override
public boolean onRowData(String dataNode, byte[] rowData) {
    RowDataPacket rowDataPkgold = ResultSetUtil.parseRowData(rowData, bfields);
    // 拷贝一份batchRows
    Map<String, byte[]> batchRowsCopy = new ConcurrentHashMap<String, byte[]>();
    batchRowsCopy.putAll(arows);
    // 获取Id字段,
    String id = ByteUtil.getString(rowDataPkgold.fieldValues.get(joinR));
    // 查找ID对应的A表的记录
    // arows.remove(id);
    byte[] arow = getRow(batchRowsCopy, id, joinL);
    // byte[] arow = getRow(id,joinL);//arows.remove(id);
    while (arow != null) {
        // ctx.getAllFields());
        RowDataPacket rowDataPkg = ResultSetUtil.parseRowData(arow, afields);
        for (int i = 1; i < rowDataPkgold.fieldCount; i++) {
            // 设置b.name 字段
            byte[] bname = rowDataPkgold.fieldValues.get(i);
            rowDataPkg.add(bname);
            rowDataPkg.addFieldCount(1);
        }
        // RowData(rowDataPkg);
        // huangyiming add
        MiddlerResultHandler middlerResultHandler = session.getMiddlerResultHandler();
        if (null == middlerResultHandler) {
            ctx.writeRow(rowDataPkg);
        } else {
            if (middlerResultHandler instanceof MiddlerQueryResultHandler) {
                // if(middlerResultHandler.getDataType().equalsIgnoreCase("string")){
                byte[] columnData = rowDataPkg.fieldValues.get(0);
                if (columnData != null && columnData.length > 0) {
                    String rowValue = new String(columnData);
                    middlerResultHandler.add(rowValue);
                }
            // }
            }
        }
        arow = getRow(batchRowsCopy, id, joinL);
    // arow = getRow(id,joinL);
    }
    return false;
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) MiddlerResultHandler(io.mycat.backend.mysql.nio.handler.MiddlerResultHandler) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MiddlerQueryResultHandler(io.mycat.backend.mysql.nio.handler.MiddlerQueryResultHandler)

Example 7 with MiddlerResultHandler

use of io.mycat.backend.mysql.nio.handler.MiddlerResultHandler in project Mycat_plus by coderczp.

the class ShareRowOutPutDataHandler method processSQL.

public void processSQL(String sql, EngineCtx ctx) {
    String ssql = joinParser.getSql();
    getRoute(ssql);
    RouteResultsetNode[] nodes = rrs.getNodes();
    if (nodes == null || nodes.length == 0 || nodes[0].getName() == null || nodes[0].getName().equals("")) {
        ctx.getSession().getSource().writeErrMessage(ErrorCode.ER_NO_DB_ERROR, "No dataNode found ,please check tables defined in schema:" + ctx.getSession().getSource().getSchema());
        return;
    }
    this.ctx = ctx;
    String[] dataNodes = getDataNodes();
    maxjob = dataNodes.length;
    // huangyiming
    ShareDBJoinHandler joinHandler = new ShareDBJoinHandler(this, joinParser.getJoinLkey(), sc.getSession2());
    ctx.executeNativeSQLSequnceJob(dataNodes, ssql, joinHandler);
    EngineCtx.LOGGER.info("Catlet exec:" + getDataNode(getDataNodes()) + " sql:" + ssql);
    ctx.setAllJobFinishedListener(new AllJobFinishedListener() {

        @Override
        public void onAllJobFinished(EngineCtx ctx) {
            if (!jointTableIsData) {
                ctx.writeHeader(fields);
            }
            MiddlerResultHandler middlerResultHandler = sc.getSession2().getMiddlerResultHandler();
            if (middlerResultHandler != null) {
                // sc.getSession2().setCanClose(false);
                middlerResultHandler.secondEexcute();
            } else {
                ctx.writeEof();
            }
            EngineCtx.LOGGER.info("发送数据OK");
        }
    });
}
Also used : RouteResultsetNode(io.mycat.route.RouteResultsetNode) AllJobFinishedListener(io.mycat.sqlengine.AllJobFinishedListener) EngineCtx(io.mycat.sqlengine.EngineCtx) MiddlerResultHandler(io.mycat.backend.mysql.nio.handler.MiddlerResultHandler)

Example 8 with MiddlerResultHandler

use of io.mycat.backend.mysql.nio.handler.MiddlerResultHandler in project Mycat-Server by MyCATApache.

the class ShareRowOutPutDataHandler method onHeader.

@Override
public void onHeader(String dataNode, byte[] header, List<byte[]> bfields) {
    this.bfields = bfields;
    joinR = this.ctx.getFieldIndex(bfields, joinRkey);
    MiddlerResultHandler middlerResultHandler = session.getMiddlerResultHandler();
    if (middlerResultHandler == null) {
        ctx.writeHeader(dataNode, afields, bfields);
    }
}
Also used : MiddlerResultHandler(io.mycat.backend.mysql.nio.handler.MiddlerResultHandler)

Aggregations

MiddlerResultHandler (io.mycat.backend.mysql.nio.handler.MiddlerResultHandler)8 MiddlerQueryResultHandler (io.mycat.backend.mysql.nio.handler.MiddlerQueryResultHandler)2 RowDataPacket (io.mycat.net.mysql.RowDataPacket)2 RouteResultsetNode (io.mycat.route.RouteResultsetNode)2 AllJobFinishedListener (io.mycat.sqlengine.AllJobFinishedListener)2 EngineCtx (io.mycat.sqlengine.EngineCtx)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2