Example #1
0
  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;
    ShareDBJoinHandler joinHandler = new ShareDBJoinHandler(this, joinParser.getJoinLkey());
    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);
            }
            ctx.writeEof();
            EngineCtx.LOGGER.info("发送数据OK");
          }
        });
  }
Example #2
0
 public void writeHeader(String dataNode, List<byte[]> afields, List<byte[]> bfields) {
   sendField++;
   if (sendField == 1) {
     ctx.writeHeader(afields, bfields);
     setAllFields(afields, bfields);
     // EngineCtx.LOGGER.info("发送字段2:" + dataNode);
   }
 }
Example #3
0
 public void endJobInput(String dataNode, boolean failed) {
   mjob++;
   if (mjob >= maxjob) {
     createQryJob(Integer.MAX_VALUE);
     ctx.endJobInput();
   }
   // EngineCtx.LOGGER.info("完成"+mjob+":" + dataNode+" failed:"+failed);
 }
Example #4
0
 // private void createQryJob(String dataNode,int batchSize) {
 private void createQryJob(int batchSize) {
   int count = 0;
   Map<String, byte[]> batchRows = new ConcurrentHashMap<String, byte[]>();
   String theId = null;
   StringBuilder sb = new StringBuilder().append('(');
   String svalue = "";
   for (Map.Entry<String, String> e : ids.entrySet()) {
     theId = e.getKey();
     batchRows.put(theId, rows.remove(theId));
     if (!svalue.equals(e.getValue())) {
       sb.append(e.getValue()).append(',');
     }
     svalue = e.getValue();
     if (count++ > batchSize) {
       break;
     }
   }
   /*
   while ((theId = ids.poll()) != null) {
   	batchRows.put(theId, rows.remove(theId));
   	sb.append(theId).append(',');
   	if (count++ > batchSize) {
   		break;
   	}
   }
   */
   if (count == 0) {
     return;
   }
   jointTableIsData = true;
   sb.deleteCharAt(sb.length() - 1).append(')');
   String sql = String.format(joinParser.getChildSQL(), sb);
   // if (!childRoute){
   getRoute(sql);
   // childRoute=true;
   // }
   ctx.executeNativeSQLParallJob(
       getDataNodes(),
       sql,
       new ShareRowOutPutDataHandler(
           this, fields, joinindex, joinParser.getJoinRkey(), batchRows));
   EngineCtx.LOGGER.info("SQLParallJob:" + getDataNode(getDataNodes()) + " sql:" + sql);
 }
Example #5
0
 public void writeRow(RowDataPacket rowDataPkg) {
   ctx.writeRow(rowDataPkg);
 }