use of io.mycat.backend.mysql.nio.handler.MiddlerResultHandler in project Mycat_plus by coderczp.
the class ShareRowOutPutDataHandler method writeHeader.
public void writeHeader(String dataNode, List<byte[]> afields, List<byte[]> bfields) {
sendField++;
if (sendField == 1) {
// huangyiming add 只是中间过程数据不能发送给客户端
MiddlerResultHandler middlerResultHandler = sc.getSession2().getMiddlerResultHandler();
if (middlerResultHandler == null) {
ctx.writeHeader(afields, bfields);
}
setAllFields(afields, bfields);
// EngineCtx.LOGGER.info("发送字段2:" + dataNode);
}
}
use of io.mycat.backend.mysql.nio.handler.MiddlerResultHandler in project Mycat_plus by coderczp.
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;
}
use of io.mycat.backend.mysql.nio.handler.MiddlerResultHandler in project Mycat_plus by coderczp.
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);
}
}
use of io.mycat.backend.mysql.nio.handler.MiddlerResultHandler in project Mycat-Server by MyCATApache.
the class ShareRowOutPutDataHandler method writeHeader.
public void writeHeader(String dataNode, List<byte[]> afields, List<byte[]> bfields) {
sendField++;
if (sendField == 1) {
// huangyiming add 只是中间过程数据不能发送给客户端
MiddlerResultHandler middlerResultHandler = sc.getSession2().getMiddlerResultHandler();
if (middlerResultHandler == null) {
ctx.writeHeader(afields, bfields);
}
setAllFields(afields, bfields);
// EngineCtx.LOGGER.info("发送字段2:" + dataNode);
}
}
use of io.mycat.backend.mysql.nio.handler.MiddlerResultHandler in project Mycat-Server by MyCATApache.
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");
}
});
}
Aggregations