Package com.alimama.mdrill.json

Examples of com.alimama.mdrill.json.JSONArray


    TableJoin.LOG.info("getUserTables:"+sql);
    ResultSet res = stmt.executeQuery(sql);
    JSONObject jsonObj = new JSONObject();
    jsonObj.put("code", "1");
    jsonObj.put("_exehql", sql);
    JSONArray jsonArray = new JSONArray();

    while (res.next()) {
      JSONObject item = new JSONObject();

      item.put("source", res.getString("source"));
      item.put("tableShowName", res.getString("tableShowName"));//展示名称
      item.put("tableName", res.getString("tableName"));//uuid
      item.put("colsShowName", res.getString("colsShowName").replaceAll("\\(", "_").replaceAll("\\)", "_").replaceAll(" ", "").replaceAll("_,", ",").replaceAll(",$", ""));
      item.put("colsName", res.getString("colsName"));
      item.put("colsType", res.getString("colsType"));
      item.put("splitString", res.getString("splitString"));
      item.put("txtStorePath", res.getString("txtStorePath"));
      item.put("indexStorePath", res.getString("indexStorePath"));
      item.put("extval", res.getString("extval"));
      item.put("status", res.getString("status"));
      item.put("username", res.getString("username"));
      item.put("createtime", res.getString("createtime"));
      item.put("lastuptime", res.getString("lastuptime"));
      item.put("joins", res.getString("joins"));
      item.put("stage", res.getString("stage"));
      item.put("percent", res.getString("percent"));
      item.put("resultkb", parseInt(res.getString("resultkb"))>0?res.getString("resultkb"):"<1");
      item.put("memo", String.valueOf(res.getString("memo")));
      boolean isoversize= (!res.getString("source").equals("8"))&&parseInt(res.getString("resultkb"))>512000;

      boolean issuccess=res.getString("status").equals("INDEX")&&res.getString("extval").equals("0");
     
     
      boolean iserror=res.getString("status").equals("FAIL")||!res.getString("extval").equals("0");
      double percent=parsePercent(res.getString("stage"),res.getString("percent"),issuccess);
     
     
      if(percent>=100&&res.getString("source").equals("8")&&parseInt(res.getString("resultkb"))<=0)
      {
        issuccess=false;
        iserror=true;
      }
     
      boolean isallowEdit=!res.getString("status").equals("INDEXING")&&res.getString("source").equals("1");
      item.put("allowCreate",String.valueOf(res.getString("source").equals("2")&&issuccess&&percent>=100&&!isoversize));//是否允许将离线下载转换为个人表
      item.put("allowUpload",String.valueOf(isallowEdit&&res.getString("status").equals("init")));//上传
      item.put("allowDownload",String.valueOf((issuccess||res.getString("status").equals("DUMP"))&&percent>=100));//下载
      item.put("allowJoin",String.valueOf(res.getString("source").equals("1")&&issuccess&&percent>=100&&!isoversize));//join
      item.put("allowSend",String.valueOf(issuccess&&percent>=100));//推送
      item.put("isError", iserror);
      String uuidshow=iserror?("<br>"+res.getString("tableName")):"";
      item.put("proccess", ((res.getString("status").equals("DUMP")||iserror)?"0":DF_FORMAT.format(percent))+"%");

      item.put("msg", String.valueOf(iserror?"服务器异常":isoversize?"数据文件超过500M  ":res.getString("status").equals("DUMP")?"设置关联关系的字段有重复值":issuccess&&percent>=100?"成功":res.getString("status").equals("init")?"等待上传数据":"处理中...")+uuidshow);

      
      jsonArray.put(item);
     
        }
    HashMap<String,String> cnt=getUserTablesCount(username, type,moduleName);

    JSONObject data = new JSONObject();
View Full Code Here


      jsonObj.put("code", "0");
      jsonObj.put("message", "正在创建索引中请稍后");
      return jsonObj.toString();
    }else
    {
    JSONArray list = new JSONArray();

    for(String username:mailto.split(","))
    {
      JSONObject result=createByMap(tableInfo, uuid,username);
      list.put(result);
    }
    jsonObj.put("code", "1");
    jsonObj.put("data", list);
  }
    if (callback != null && callback.length() > 0) {
View Full Code Here

    HashSet<String> rtn = new HashSet<String>();
    boolean isset = false;

    Long small = -1l;
    Long bigger = -1l;
    JSONArray jsonStr = new JSONArray(queryStr.trim());

    for (int j = 0; j < jsonStr.length(); j++) {
      JSONObject obj = jsonStr.getJSONObject(j);
      if (obj.has("thedate")) {
        JSONObject thedate = obj.getJSONObject("thedate");
        Integer operate = Integer.parseInt(thedate.get("operate").toString());
        OperateType optype=WebServiceParams.parseOperateType(operate);
View Full Code Here

  {
    if(leftjoin==null||leftjoin.trim().isEmpty())
    {
      return new HigoJoinParams[0];
    }
    JSONArray jsonStr=new JSONArray(leftjoin.trim());
    HigoJoinParams[] rtn=new HigoJoinParams[jsonStr.length()];
    for(int i=0;i<jsonStr.length();i++)
    {
      JSONObject obj=jsonStr.getJSONObject(i);
      HigoJoinParams p=new HigoJoinParams();
      p.tablename=obj.getString("tablename");
      p.hdfsPath=obj.getString("path")+"/part-00000";
      p.fq=WebServiceParams.fqList(false,obj.getString("fq"), shard,null);
      p.fl=obj.getString("fl").split(",");
View Full Code Here

    if (queryStr == null || queryStr.trim().equals("")) {
      queryStr = "[]";
    }
    queryStr = queryStr.trim();
    if (queryStr.startsWith("{") && queryStr.endsWith("}")) {
      JSONArray arr = new JSONArray();
      JSONObject jsonStr = new JSONObject(queryStr.trim());
      Iterator keys = jsonStr.keys();
      while (keys.hasNext()) {
        JSONObject item = new JSONObject();
        String key = (String) keys.next();
        item.put(key, jsonStr.getJSONObject(key));
        arr.put(item);
      }
      queryStr = arr.toString();
    }
   
    JSONArray jsonStr=new JSONArray(queryStr.trim());
    JSONArray rtn=new JSONArray();

    for(int i=0;i<jsonStr.length();i++)
    {
      JSONObject obj=jsonStr.getJSONObject(i);
      if(obj.has("key"))
      {
        JSONObject objnew=new JSONObject();
        JSONObject objself=new JSONObject();
        objself.put("operate", obj.get("operate"));
        objself.put("value", obj.get("value"));
        objnew.put(obj.getString("key"), objself);
        rtn.put(objnew);
      }else{
        rtn.put(obj);
      }
    }
     
      return rtn.toString();

  }
View Full Code Here

 
  public static ArrayList<String> fqList(boolean isnothedate,String queryStr,GetPartions.Shards shard,HashMap<String, String> fieldColumntypeMap) throws JSONException
  {
    queryStr=query(queryStr);
    ArrayList<String> fqList = new ArrayList<String>();
    JSONArray jsonStr=new JSONArray(queryStr.trim());
    for(int j=0;j<jsonStr.length();j++)
    {
      JSONObject obj=jsonStr.getJSONObject(j);
     
      if(obj.has("subQuery"))
      {
        String filterType="AND";
        if(obj.has("filter"))
View Full Code Here

  public static String parseFqValue(String valueList,int operate) throws JSONException
  {
    if (operate < 1000) {
      // for adhoc
      if (valueList.startsWith("[") && valueList.endsWith("]")) {
        JSONArray arr=new JSONArray(valueList);
            int len = arr.length();
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < len; i += 1) {
                if (i > 0) {
                    sb.append(",");
                }
                sb.append(arr.get(i));
            }
            valueList= sb.toString();
      }
     
      if(operate < 9&&operate>4)
View Full Code Here

      return fqList;
    }
   
    queryStr=WebServiceParams.query(queryStr);
   
    JSONArray jsonStr=new JSONArray(queryStr.trim());
    for(int j=0;j<jsonStr.length();j++)
    {
      JSONObject obj=jsonStr.getJSONObject(j);
      if(obj.has("subQuery"))
      {
        String filterType="AND";
        if(obj.has("filter"))
        {
          filterType=obj.getString("filter");
        }
        ArrayList<String> sublist=fqListHive(isNumber,part,obj.getJSONArray("list").toString(),isPartionByPt, filetypeMap,colMap,colMap2,tblname);
        if(sublist.size()==0)
        {
          continue;
        }
        if(sublist.size()==1)
        {
          fqList.add(sublist.get(0));
        }
        StringBuffer buff=new StringBuffer();
        buff.append("(");
        String joinchar="";
        for(String fq:sublist)
        {
          buff.append(joinchar);
          buff.append(fq);
          joinchar=" "+filterType+" ";
        }
       
        buff.append(")");
       
        fqList.add(buff.toString());
      }else{
     
          for  (Iterator iter = obj.keys(); iter.hasNext();) {
              String key = (String)iter.next();
                         
              JSONObject jsonStr2= obj.getJSONObject(key);
             
              int operate = Integer.parseInt(jsonStr2.getString("operate"));
              String valueList=jsonStr2.getString("value");
   
              if (operate < 1000) {
                // for adhoc
                if (valueList.startsWith("[") && valueList.endsWith("]")) {
                  JSONArray arr=new JSONArray(valueList);
                    int len = arr.length();
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < len; i += 1) {
                        if (i > 0) {
                            sb.append(",");
                        }
                        sb.append(arr.get(i));
                    }
                    valueList= sb.toString();
                }
                if(operate < 9&&operate>4)
                {
View Full Code Here

      jsonObj.put("message", "success");
      jsonObj.put("total", totalRecord);
    }
     
      JSONObject jsonObj2 = new JSONObject();
      JSONArray jsonArray = new JSONArray();

      ArrayList<Object> facetCounts=(ArrayList<Object>) ff.get("list");

      int fcsize = 0;
      if(facetCounts != null){
        fcsize = facetCounts.size();
      }
      if(groupValueCacheLast==null)
      {
        for(int i=0;i<fcsize;i++){
          GroupbyRow row = new GroupbyRow((ArrayList<Object>)facetCounts.get(i));
          row.setCross(crossFs, distFS);
          String groupValues = row.getKey().getKey();
             groupValueCache.put(groupValues, row);
             JSONObject jo = new JSONObject();
             setGroup(jo, groupFields, joins, groupValues);
          setStat(jo, showFields, row);
          jsonArray.add(i, jo);
        }
      }else{
        for(int i=0;i<fcsize;i++){
          GroupbyRow row = new GroupbyRow((ArrayList<Object>)facetCounts.get(i));
          row.setCross(crossFs, distFS);
          String groupValues = row.getKey().getKey();
             groupValueCache.put(groupValues, row);
        }
       
        int index=0;
        for(Entry<String,GroupbyRow> e:groupValueCacheLast.entrySet())
        {
             JSONObject jo = new JSONObject();
          String groupValues = e.getKey();
          GroupbyRow row = groupValueCache.get(groupValues);
          if(row==null)
          {
            row=e.getValue();
          }
          row.setCross(crossFs, distFS);

             setGroup(jo, groupFields, joins, groupValues);
          setStat(jo, showFields, row);
          jsonArray.add(index, jo);
          index++;
        }
      }
     
      jsonObj2.put("docs", jsonArray);
View Full Code Here

         
        jsonObj.put("code", "1");
        jsonObj.put("message", "success");
       
        JSONObject jsonObj2 = new JSONObject();
        JSONArray jsonArray = new JSONArray();

        ArrayList<Object> facetCounts=(ArrayList<Object>) ff.get("list");
       
        int fcsize = 0;
        if(facetCounts != null){
          fcsize = facetCounts.size();
        }
        jsonObj.put("total", totalRecord);

        for(int i=0;i<fcsize;i++){
             SelectDetailRow row = new SelectDetailRow((ArrayList<Object>)facetCounts.get(i));
            
             JSONObject jo = new JSONObject();
             String groupValues = row.getKey().getKey();
             if(groupValues==null)
             {
               continue;
             }
             String[] values =  EncodeUtils.decode(groupValues.split(UniqConfig.GroupJoinString(),-1));
             int valuesoffset=2;
             for(int j =0;j<(values.length-valuesoffset)&&j<showFields.size();j++){
               if(showFields.get(j).equals("higoempty_groupby_forjoin_l"))
               {
                 continue;
               }
               if(values[j+valuesoffset]==null || values[j+valuesoffset].equals(""))
               {
                    jo.put(showFields.get(j), " ");
               }
               else
               {
                 jo.put(showFields.get(j), transDate(values[j+valuesoffset]));
               }
             }
             int joinoffset=showFields.size()+valuesoffset;
          for(HigoJoinParams inv:joins)
          {
            for(int j=0;j<inv.fl.length;j++)
            {
              int pos=j+joinoffset;
              if(pos<values.length)
              {
                jo.put(inv.returnPrefix+"@"+inv.fl[j], transDate(values[pos]));
              }else{
                jo.put(inv.returnPrefix+"@"+inv.fl[j], " ");
              }
            }
            joinoffset+=inv.fl.length;
          }
            
             jsonArray.add(i, jo);
        }
        jsonObj2.put("docs", jsonArray);
        jsonObj.put("data", jsonObj2);
       
    }
View Full Code Here

TOP

Related Classes of com.alimama.mdrill.json.JSONArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.