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
 // 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 #3
0
  public void route(
      SystemConfig sysConfig,
      SchemaConfig schema,
      int sqlType,
      String realSQL,
      String charset,
      ServerConnection sc,
      LayerCachePool cachePool) {
    int rs = ServerParse.parse(realSQL);
    this.sqltype = rs & 0xff;
    this.sysConfig = sysConfig;
    this.schema = schema;
    this.charset = charset;
    this.sc = sc;
    this.cachePool = cachePool;
    try {
      //  RouteStrategy routes=RouteStrategyFactory.getRouteStrategy();
      // rrs =RouteStrategyFactory.getRouteStrategy().route(sysConfig, schema, sqlType2,
      // realSQL,charset, sc, cachePool);
      MySqlStatementParser parser = new MySqlStatementParser(realSQL);
      SQLStatement statement = parser.parseStatement();
      if (statement instanceof SQLSelectStatement) {
        SQLSelectStatement st = (SQLSelectStatement) statement;
        SQLSelectQuery sqlSelectQuery = st.getSelect().getQuery();
        if (sqlSelectQuery instanceof MySqlSelectQueryBlock) {
          MySqlSelectQueryBlock mysqlSelectQuery =
              (MySqlSelectQueryBlock) st.getSelect().getQuery();
          joinParser = new JoinParser(mysqlSelectQuery, realSQL);
          joinParser.parser();
        }
      }
      /*
       if (routes instanceof DruidMysqlRouteStrategy) {
        SQLSelectStatement st=((DruidMysqlRouteStrategy) routes).getSQLStatement();
        SQLSelectQuery sqlSelectQuery =st.getSelect().getQuery();
      if(sqlSelectQuery instanceof MySqlSelectQueryBlock) {
      	MySqlSelectQueryBlock mysqlSelectQuery = (MySqlSelectQueryBlock)st.getSelect().getQuery();
      	joinParser=new JoinParser(mysqlSelectQuery,realSQL);
      	joinParser.parser();
      }
       }
       */
    } catch (Exception e) {

    }
  }