Package com.alimama.mdrill.json

Examples of com.alimama.mdrill.json.JSONObject


    return groupbyFields;
  }
 
  public static String parseStatList(String projectName, String queryStr,  String fl, String groupby,String dimvalue) throws JSONException, SQLException
  {
    JSONObject jsonObj = new JSONObject();
    ArrayList<String> StatFields=new ArrayList<String>();
    ArrayList<String> StatFieldsDisplay=new ArrayList<String>();
    HashMap<String,ArrayList<String>> namelist=AdhocWebServiceParams.parseFieldToNames(fl, groupby, dimvalue, null);
    ArrayList<String> namelistread=namelist.get("namelist");
    ArrayList<String> showFields = namelist.get("field");
    StatFields.add("count(*)");
    StatFieldsDisplay.add("计数(*)");
    for(int i=0;i<showFields.size()&&i<namelistread.size();i++){
      String showfield=showFields.get(i);
      String showfieldDisplay=namelistread.get(i);
      StateField showfielda=WebServiceParams.parseStat(showfield);
      if(showfielda.isstat)
      {
        StatFields.add(showfield);
        StatFieldsDisplay.add(showfieldDisplay);

      }
    }
    jsonObj.put("stats", StatFields);
    jsonObj.put("statsShow", StatFieldsDisplay);

    jsonObj.put("project", projectName);
    return jsonObj.toString();
  }
View Full Code Here


  }
 
 
  public static String parseGroupList(String projectName, String queryStr,  String fl, String groupby,String dimvalue) throws JSONException, SQLException
  {
    JSONObject jsonObj = new JSONObject();
    ArrayList<String> StatFields=new ArrayList<String>();
    ArrayList<String> StatFieldsDisplay=new ArrayList<String>();
    HashMap<String,ArrayList<String>> namelist=AdhocWebServiceParams.parseFieldToNames(fl, groupby, dimvalue, null);
    ArrayList<String> namelistread=namelist.get("namelist");
    ArrayList<String> showFields = namelist.get("field");
    for(int i=0;i<showFields.size()&&i<namelistread.size();i++){
      String showfield=showFields.get(i);
      String showfieldDisplay=namelistread.get(i);
      StateField showfielda=WebServiceParams.parseStat(showfield);
      if(!showfielda.isstat)
      {
        StatFields.add(showfield);
        StatFieldsDisplay.add(showfieldDisplay);

      }
    }
    jsonObj.put("group", StatFields);
    jsonObj.put("groupShow", StatFieldsDisplay);

    jsonObj.put("project", projectName);
    return jsonObj.toString();
  }
View Full Code Here

    return jsonObj.toString();
  }
 
  public static String parseStat(String projectName, String queryStr,  String fl, String groupby,String dimvalue) throws JSONException, SQLException
  {
    JSONObject jsonObj = new JSONObject();
    ArrayList<String> groupbyFields=new ArrayList<String>();
    ArrayList<String> showFields = WebServiceParams.showFields(fl);
    jsonObj.put("pie_stat", "count(*)");
    for (String showfield : showFields) {
      StateField showfielda=WebServiceParams.parseStat(showfield);
      if(showfielda.isstat)
      {
        jsonObj.put("pie_stat", showfield);

      }else{
        groupbyFields.add(showfield);
      }
     
    }
    jsonObj.put("fieldToName", AdhocWebServiceParams.parseFieldToNames(fl, groupby, dimvalue, null));
    jsonObj.put("pie_dimvalue", dimvalue);
    jsonObj.put("pie_groupby",groupbyFields);
    jsonObj.put("project", projectName);

    jsonObj.put("q", queryStr);
    jsonObj.put("sort", String.valueOf(jsonObj.getString("pie_stat")));
    jsonObj.put("order", String.valueOf("desc"));
   
    return jsonObj.toString();
  }
View Full Code Here

     
      String rtn= MdrillService.result(projectName, null, startStr,rowsStr, queryStr, null, fl, groupby, sort, order, null, null);

        HashMap<String,Object> rtna=new HashMap<String, Object>();

      JSONObject jsonObj = new JSONObject(rtn);
      if(!jsonObj.getString("code").equals("1"))
      {
        rtna.put("code",0);
        rtna.put("msg","服务器异常,请稍后再试");
        hb.stop();
        return new JSONObject(rtna).toString();
      }
      JSONArray list=jsonObj.getJSONObject("data").getJSONArray("docs");
      ArrayList<Object> data=new ArrayList< Object>();
      ArrayList<String> showFields = WebServiceParams.showFields(fl);
      String flkey=groupby;
      String flvalue="";
      for (String showfield : showFields) {
          StateField showfielda=WebServiceParams.parseStat(showfield);
          if(showfielda.isstat)
          {
            flvalue=showfield;
          }
         
      }
      JSONArray filterother=new JSONArray(WebServiceParams.query(queryStr));
      JSONArray filterother2=new JSONArray();

      for(int i=0;i<list.length();i++)
      {
        JSONObject item=list.getJSONObject(i);
        JSONObject newitem=new JSONObject();
        newitem.put("label", String.valueOf(item.get(flkey)));
        newitem.put("data", Double.parseDouble(item.getString(flvalue)));
        data.add(newitem);

        JSONObject newitemfilter=new JSONObject();
        newitemfilter.put("key", flkey);
        newitemfilter.put("operate", "2");
        newitemfilter.put("value",  String.valueOf(item.get(flkey)));
        filterother.put(newitemfilter);
        filterother2.put(newitemfilter);
       

      }
     
      if("Y".equals(showOther))
      {
        String rtnother= MdrillService.result(projectName, null, startStr,rowsStr, filterother.toString(), null, flvalue, null, sort, order, null, null);
        JSONObject jsonObjother = new JSONObject(rtnother);
        if(jsonObjother.getString("code").equals("1"))
        {
          JSONArray listother=jsonObjother.getJSONObject("data").getJSONArray("docs");
          for(int i=0;i<listother.length();i++)
          {
            JSONObject item=listother.getJSONObject(i);
            Double d=Double.parseDouble(item.getString(flvalue));
            if(d>0)
            {
            JSONObject newitem=new JSONObject();
            newitem.put("label", "其他");
            newitem.put("data",d );
            data.add(newitem);
            }
          }
        }
      }
     
      hb.stop();
     
   
        rtna.put("code", 1);
      rtna.put("其他", filterother2);

        rtna.put("data", data);

        String rtnstr= new JSONObject(rtna).toString();
        out.write(rtnstr);
        return rtnstr;

  }
View Full Code Here

  public String[] SqlPartions(String queryStr) throws Exception {
    HashSet<String> rtn = new HashSet<String>();
    JSONArray jsonStr = new JSONArray(queryStr.trim());

    for (int j = 0; j < jsonStr.length(); j++) {
      JSONObject obj = jsonStr.getJSONObject(j);
      if (obj.has(this.fieldname)) {
        JSONObject thedate = obj.getJSONObject(this.fieldname);
        Integer operate = Integer.parseInt(thedate.get("operate").toString());
        OperateType optype=WebServiceParams.parseOperateType(operate);
        String[] val = WebServiceParams.parseFqValue(thedate.getString("value"), operate).split(",");
        if (optype.equals(OperateType.eq)||optype.equals(OperateType.in))
        {
          for (String dir : val) {
            rtn.add(dir);
          }
View Full Code Here

  public String SqlFilter(String queryStr) throws Exception {
    JSONArray rtn = new JSONArray();
    JSONArray jsonStr = new JSONArray(queryStr.trim());

    for (int j = 0; j < jsonStr.length(); j++) {
      JSONObject obj = jsonStr.getJSONObject(j);
      if (!obj.has(this.fieldname)) {
        rtn.put(obj);
      }
    }
    return rtn.toString();
  }
View Full Code Here

TOP

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

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.