Package com.alimama.mdrill.json

Examples of com.alimama.mdrill.json.JSONObject


    return new JSONObject(rtn).toString();
  }
 
  public static String insert(String key,String value) throws Exception
  {
    JSONObject jsonObj = new JSONObject();

    SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
    String day = fmt.format(new Date());
    Map stormconf = Utils.readStormConfig();
    String connstr = (String) stormconf.get("higo.download.offline.conn");
    String uname = (String) stormconf.get("higo.download.offline.username");
    String passwd = (String) stormconf.get("higo.download.offline.passwd");
 
    MySqlConn m_fpsql = new MySqlConn(connstr, uname, passwd);
   
    Connection conn = m_fpsql.getConn();
    String strSql = "insert into tab_infos " +
        "(tab_key,tab_value)" +
        "values" +
        "(?,?)";
    PreparedStatement m_fps = conn.prepareStatement(strSql);
    try {
      int index=1;
      m_fps.setString(index++, key);
      m_fps.setString(index++, value);
      m_fps.executeUpdate();
      jsonObj.put("code", "1");
      JSONObject daa = new JSONObject();
      jsonObj.put("data", daa);
      jsonObj.put("____debug", m_fps.toString());
    } catch (Exception e) {
      jsonObj.put("____debug2", m_fps.toString());
      jsonObj.put("message", e.toString());
View Full Code Here


//    return new JSONObject(rtn).toString();
//  }
 
  public static String del(String key) throws Exception
  {
    JSONObject jsonObj = new JSONObject();
    jsonObj.put("code", "0");
    SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
    String day = fmt.format(new Date());
    Map stormconf = Utils.readStormConfig();
    String connstr = (String) stormconf.get("higo.download.offline.conn");
    String uname = (String) stormconf.get("higo.download.offline.username");
    String passwd = (String) stormconf.get("higo.download.offline.passwd");
 
    MySqlConn m_fpsql = new MySqlConn(connstr, uname, passwd);
   
    Connection conn = m_fpsql.getConn();
    String strSql = "delete from tab_infos  where tab_key=? ";
    PreparedStatement m_fps = conn.prepareStatement(strSql);
    try {
      int index=1;
      m_fps.setString(index++, key);
      m_fps.executeUpdate();
      jsonObj.put("code", "1");
    } catch (Exception e) {
      jsonObj.put("message", e.toString());
      jsonObj.put("code", "0");
    }finally{
      m_fps.close();
      m_fpsql.close();
    }
   
    return jsonObj.toString();

  }
View Full Code Here

  }
 
  public static String update(String key,String value) throws Exception
  {
    JSONObject jsonObj = new JSONObject();

    SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
    String day = fmt.format(new Date());
    Map stormconf = Utils.readStormConfig();
    String connstr = (String) stormconf.get("higo.download.offline.conn");
    String uname = (String) stormconf.get("higo.download.offline.username");
    String passwd = (String) stormconf.get("higo.download.offline.passwd");
 
    MySqlConn m_fpsql = new MySqlConn(connstr, uname, passwd);
   
    Connection conn = m_fpsql.getConn();
    String strSql = "update tab_infos set tab_value=? where tab_key=? ";
    PreparedStatement m_fps = conn.prepareStatement(strSql);
    try {
      int index=1;
      m_fps.setString(index++, value);
      m_fps.setString(index++, key);
      m_fps.executeUpdate();
      jsonObj.put("code", "1");
      JSONObject daa = new JSONObject();
      jsonObj.put("data", daa);
      jsonObj.put("____debug", m_fps.toString());
    } catch (Exception e) {
      jsonObj.put("____debug2", m_fps.toString());
      jsonObj.put("____debugerror", e.toString());
View Full Code Here


    HashMap<String,String> tablecount=getUserTablesCount(username, 1,"");
 
   
    JSONObject jsonObj = new JSONObject();
    if(tablecount!=null&&tablecount.containsKey("cnt")&&Integer.parseInt(tablecount.get("cnt"))>=20)
    {
      jsonObj.put("code", "0");
      jsonObj.put("message", "你已经创建了"+tablecount.get("cnt")+"个个人表了,单用户最多创建20个个人表");
      if (callback != null && callback.length() > 0) {
        return callback + "(" + jsonObj.toString() + ")";
      } else {
        return jsonObj.toString();
      }
    }

    SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
    String day = fmt.format(new Date());
    Map stormconf = Utils.readStormConfig();
    String hdpConf = (String) stormconf.get("hadoop.conf.dir");
    String connstr = (String) stormconf.get("higo.download.offline.conn");
    String uname = (String) stormconf.get("higo.download.offline.username");
    String passwd = (String) stormconf.get("higo.download.offline.passwd");
    String store = (String) stormconf.get("higo.download.offline.store")
        + "/" + day + "/" + java.util.UUID.randomUUID().toString();
    MySqlConn m_fpsql = new MySqlConn(connstr, uname, passwd);
   
    String tableName=java.util.UUID.randomUUID().toString();
    Connection conn = m_fpsql.getConn();
    String strSql = "insert into adhoc_joins " +
        "(tableShowName,tableName,colsShowName,colsName,colsType,splitString,txtStorePath,indexStorePath,status,username,createtime,lastuptime,joins,percent,memo)" +
        "values" +
        "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    PreparedStatement m_fps = conn.prepareStatement(strSql);
    try {
      int index=1;
      m_fps.setString(index++, tableShowName);
      m_fps.setString(index++, tableName);
      m_fps.setString(index++, colsShowName);
      StringBuffer colsName=new StringBuffer();
      StringBuffer colsType=new StringBuffer();
      String[] cols=colsShowName.split(",");
      String join="";
      HashMap<String,String> colsNames=new HashMap<String, String>();
      for(int i=0;i<cols.length;i++)
      {
        String colname="cols_"+i+"_s";
        colsName.append(join);
        colsName.append(colname);
        colsType.append(join);
        colsType.append("string");
        colsNames.put(cols[i],colname);
        join=",";
      }
      m_fps.setString(index++, colsName.toString());
      m_fps.setString(index++, colsType.toString());
      m_fps.setString(index++, MakeIndex.parseSplit(splitString));
      m_fps.setString(index++, store+"/txt");
      m_fps.setString(index++, store+"/index");
      m_fps.setString(index++, "init");
      m_fps.setString(index++, username);
   
      long nowtims=System.currentTimeMillis();
      m_fps.setTimestamp(index++, new java.sql.Timestamp(nowtims));
      m_fps.setTimestamp(index++, new java.sql.Timestamp(nowtims));
     
      StringBuffer joinbuff=new StringBuffer();
      String joinchar="";
      for(String joindesc:joins.split(","))
      {
        String[] arr=joindesc.split(":");
        joinbuff.append(joinchar);
        joinbuff.append(arr[0]);
        joinbuff.append(":");
        joinbuff.append(arr[1]);
        joinbuff.append(":");
        joinbuff.append(colsNames.get(arr[2]));
        joinchar=",";
      }
      m_fps.setString(index++,joinbuff.toString());
      m_fps.setString(index++,"");
      m_fps.setString(index++,String.valueOf(memo));
      m_fps.executeUpdate();
      jsonObj.put("code", "1");
      JSONObject daa = new JSONObject();

      daa.put("tableid", tableName);
      jsonObj.put("data", daa);
      jsonObj.put("____debug", m_fps.toString());
    } catch (Exception e) {
      jsonObj.put("____debug2", m_fps.toString());
      jsonObj.put("____debugerror", e.toString());
View Full Code Here

    }
    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(",");
      p.leftkey=obj.getString("leftkey");
      p.rightkey=obj.getString("rightkey");
      p.returnPrefix=obj.getString("prefix");
      p.sort=obj.has("sort")?obj.getString("sort"):"";
      rtn[i]=p;
    }
    return rtn;
  }
View Full Code Here

      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);
      }
View Full Code Here

    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"))
        {
          filterType=obj.getString("filter").toUpperCase();
        }
        ArrayList<String> sublist=fqList(isnothedate,obj.getJSONArray("list").toString(), shard, fieldColumntypeMap);
        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 field = (String)iter.next();
                if(isnothedate&&"thedate".equals(field))
                {
                  continue;
                }

                  JSONObject jsonStr2= obj.getJSONObject(field);
                  int operate = Integer.parseInt(jsonStr2.getString("operate"));
                  String valueList=parseFqValue(jsonStr2.getString("value"),operate);
                String fq = parseFqOperate(operate, field, valueList, shard, fieldColumntypeMap);
                if (fq != null) {
                  fqList.add(fq);
                }
              }
View Full Code Here

    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);
View Full Code Here

      jsonObj.put("code", "1");
      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();
View Full Code Here

        long totalRecord = p.getValue();
         
        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;
          }
            
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.