Package com.alimama.mdrill.json

Examples of com.alimama.mdrill.json.JSONObject


      generateList(be.getLeftExpression(), linkList,parent);
      generateList(be.getRightExpression(), linkList,parent);
 
    }else if(ex instanceof Parenthesis){
      JSONArray sublist = new JSONArray();//{colname:{operate:1,value:xxxx}}
      JSONObject subQuery=new JSONObject();
      subQuery.put("subQuery", "1");
      subQuery.put("filter", "AND");
      subQuery.put("list", sublist);
      Expression exp = getExpressionWithoutParenthesis(ex);
      linkList.put(subQuery);
      generateList(exp,sublist,subQuery);
     
    }else{
      JSONObject item=new JSONObject();//
      processExpression(ex,item);
      linkList.put(item);
    }
    return linkList;
  }
View Full Code Here


      }
    }else{
      oe.setExp((String)invokeMethod(e, "toString"));
    }
   
    JSONObject subitem=new JSONObject();
    String op=oe.getExp();
    String colname=oe.getColumnname();
    String val=String.valueOf(oe.getValue());
    JSONArray rtn=new JSONArray();
    rtn.put(val);
    subitem.put("value", rtn);
    if(op.equals("="))
    {
      subitem.put("operate", "1");
    }else if(op.equals("<>"))
    {
      subitem.put("operate", "2");
    }
    else if(op.equals(">="))
    {
      subitem.put("operate", "3");
    }
    else if(op.equals(">"))
    {
      subitem.put("operate", "13");
    }
    else if(op.equals("<="))
    {
      subitem.put("operate", "4");
    }
    else if(op.equals("<"))
    {
      subitem.put("operate", "14");
    }
    else if(op.toLowerCase().equals("like"))
    {
      subitem.put("operate", "1000");
      subitem.put("value", colname+":"+transValue(val.replaceAll("%", "*")));
      colname=String.valueOf(Math.random());
    }
    else if(op.indexOf("NOT IN")>=0 )
    {
      String[] cols=op.split("NOT IN");
      String list=cols[1].replaceAll("^[ ]*\\(", "").replaceAll("\\)[ ]*$", "");
      subitem.put("operate", "7");
      subitem.put("value", toJSONArray(list,","));
    }
    else if(op.indexOf("IN")>=0 )
    {
      String[] cols=op.split("IN");
      String list=cols[1].replaceAll("^[ ]*\\(", "").replaceAll("\\)[ ]*$", "");
      subitem.put("operate", "5");
      subitem.put("value", toJSONArray(list,","));
    }else{
      subitem.put("operate", op);
      subitem.put("value", toJSONArray(val,","));
    }
    item.put(colname, subitem);
   
    return oe;
  }
View Full Code Here

      CCJSqlParserManager pm = new CCJSqlParserManager();
      PlainSelect plainSelect =  (PlainSelect)((Select) pm.parse(new StringReader("select * from abc where "+where))).getSelectBody();
      Expression e  = getExpressionWithoutParenthesis(plainSelect.getWhere());
      JSONArray jsonObj = new JSONArray();//{colname:{operate:1,value:xxxx}}

      JSONObject subQuery=new JSONObject();
      subQuery.put("subQuery", "1");
      subQuery.put("filter", "AND");
      subQuery.put("list", jsonObj);
      this.queryStr=generateList(e, jsonObj, subQuery).toString();
    }
  }
View Full Code Here

      text = (new String(baf.toByteArray(), "utf-8")).trim();
    }
   
   
    content=text;
    JSONObject jsonObj = new JSONObject(text);
    if(!"1".equals(jsonObj.get("code")))
    {
      return -1l;
    }
    Long total=jsonObj.getLong("total");
    JSONObject data=jsonObj.getJSONObject("data");
    JSONArray list=data.getJSONArray("docs");
    for(int i=0;i<list.length();i++)
    {
      JSONObject rowMap=list.getJSONObject(i);
      ArrayList<Object> row=new ArrayList<Object>();
      for(int j=0;j<this.parser.colsNames.length;j++)
      {
        String colname=this.parser.colsNames[j];
        row.add(j, String.valueOf(rowMap.opt(colname)));
      }
      results.add(row);
    }
    return total;
View Full Code Here

           fl[i]=((Column) insert.getColumns().get(i)).getColumnName();
         }
        
        
     ExpressionList explist=((ExpressionList) insert.getItemsList());
       JSONObject item=new JSONObject();

       List expressions=explist.getExpressions();
     for(int i=0;i<expressions.size();i++)
     {
      
       Object val=expressions.get(i);
       if(val instanceof StringValue)
       {
         StringValue vv=(StringValue)val;
         item.put(fl[i], String.valueOf(vv.getValue()));
       }
       if(val instanceof LongValue)
       {
         LongValue vv=(LongValue)val;
         item.put(fl[i], String.valueOf(vv.getValue()));
       }
      
       if(val instanceof DoubleValue)
       {
         DoubleValue vv=(DoubleValue)val;
         item.put(fl[i], String.valueOf(vv.getValue()));
       }
     }
   
   
        JSONArray list=new JSONArray();
View Full Code Here

    if (index > 100000000) {
      index = 0l;
      InsertIndex.set(index);
    }

    JSONObject rtn = new JSONObject();
 
    if(tp==null||tp.equals(FlushType.buffer))
    {
      ShardsList write =null;
      if(islocal)
      {
        ArrayList<ShardsList> list=new ArrayList<GetShards.ShardsList>(cores.length);
        for(ShardsList shard:cores)
        {
          if(shard.containsIp(localip))
          {
            list.add(shard);
          }
        }
        if(list.size()>0)
        {
          write =list.get((int) (index %list.size()));
        }
      }
      if(write==null)
      {
        write = cores[(int) (index % cores.length)];
      }
 
      for (String s : write.list) {
        String url = "http://" + s + "/solr/" + projectName;
        try{
        CommonsHttpSolrServer server = new CommonsHttpSolrServer(url);
        server.setConnectionManagerTimeout(60000l);
        server.setSoTimeout(60000);
        server.setConnectionTimeout(10000);
        server.setDefaultMaxConnectionsPerHost(100);
        server.setMaxTotalConnections(100);
        server.setFollowRedirects(false);
        server.setAllowCompression(false);
        server.setMaxRetries(4);
        server.setRequestWriter(new BinaryRequestWriter());
        UpdateRequest req = new UpdateRequest();
        req.add(docs);
        UpdateResponse rsp = req.process(server);
        rtn.put(s, rsp.toString());
        }catch(Throwable e)
        {
          LOG.error("insert error "+url,e);
          throw new Exception(e);
        }
      }

    }else if(tp.equals(FlushType.sync)||tp.equals(FlushType.syncHdfs))
    {
      for(ShardsList write:cores)
      {
        for (String s : write.list) {
          String url = "http://" + s + "/solr/" + projectName;
          try{
          CommonsHttpSolrServer server = new CommonsHttpSolrServer(url);
          server.setConnectionManagerTimeout(60000l);
          server.setSoTimeout(60000);
          server.setConnectionTimeout(10000);
          server.setDefaultMaxConnectionsPerHost(100);
          server.setMaxTotalConnections(100);
          server.setFollowRedirects(false);
          server.setAllowCompression(false);
          server.setMaxRetries(4);
          server.setRequestWriter(new BinaryRequestWriter());
          UpdateRequest req = new UpdateRequest();
          req.add(docs);
          UpdateResponse rsp = req.process(server);
          rtn.put(s, rsp.toString());
          }catch(Throwable e)
          {
            LOG.error("insert error "+url,e);
            throw new Exception(e);          }
        }
      }
    }
    rtn.put("code","1");
    rtn.put("message","success");
    return rtn.toString();


  }
View Full Code Here

    return create(userid, val,user);
  }
 
  public static String del(String userid,String user) throws Exception
  {
    JSONObject jsonObj = new JSONObject();
    jsonObj.put("code", "0");
    MySqlConn m_fpsql = getConn();

   
    Connection conn = m_fpsql.getConn();
    String strSql = "delete from users_json  where userid=? ";
    PreparedStatement m_fps = conn.prepareStatement(strSql);
    try {
      int index=1;
      m_fps.setString(index++, userid);
      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 create(String userid,Map<String,String> val,String user) throws Exception
  {
    MySqlConn m_fpsql = getConn();
    val.put("opuser", String.valueOf(user));
    val.put("optime", getNowTime());
    JSONObject jsonObj = new JSONObject();

    StringBuffer sqlbuffer=new StringBuffer();
    StringBuffer sqlbuffer2=new StringBuffer();

    String joinchar="";
    String[] indexval=new String[val.size()];
    int index=0;
    for(Entry<String, String> e:val.entrySet())
    {
      sqlbuffer.append(joinchar).append(e.getKey());
      sqlbuffer2.append(joinchar).append("?");

      joinchar=",";
      indexval[index]=e.getValue();
      index++;
    }
   
    Connection conn = m_fpsql.getConn();
    String strSql = "insert into users_json " +
        "("+sqlbuffer+")" +
        "values" +
        "("+sqlbuffer2+")";
    PreparedStatement m_fps = conn.prepareStatement(strSql);
    try {
      for(int i=0;i<indexval.length;i++)
      {
        m_fps.setString(i+1, indexval[i]);

      }
      m_fps.executeUpdate();
      jsonObj.put("code", "1");

      jsonObj.put("____debug", m_fps.toString());
    } catch (Exception e) {
      jsonObj.put("____debug2", m_fps.toString());
      jsonObj.put("____debugerror", e.toString());
      jsonObj.put("code", "0");
    }finally{
      m_fps.close();
      m_fpsql.close();
    }
    return jsonObj.toString();
  }
View Full Code Here

    }
    JSONArray jsonStr=new JSONArray(leftjoin.trim());
    HigoAdhocJoinParams[] rtn=new HigoAdhocJoinParams[jsonStr.length()];
    for(int i=0;i<jsonStr.length();i++)
    {
      JSONObject obj=jsonStr.getJSONObject(i);
      HigoAdhocJoinParams p=new HigoAdhocJoinParams();
      p.tablename=obj.getString("tablename");
     
      HashMap<String, String> map=TableJoin.getTableInfo(p.tablename);
      if(map!=null)
      {
        p.txtPath=map.get("txtStorePath");
      }
      p.hdfsPath=obj.getString("path")+"/part-00000";
      if(shard!=null)
      {
        p.fq=WebServiceParams.fqListHive(false,"dt",obj.getString("fq"),false,null,null,null,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"):"";
     
      String tmptblname=("tmp_"+p.tablename+"_"+System.currentTimeMillis()).replaceAll("-", "_");
      p.createSql=AdhocHiveTmpTable.createTmpTable(tmptblname, map.get("colsName").split(","), map.get("splitString"));
      p.DropSql=AdhocHiveTmpTable.dropTable(tmptblname);
      p.addData=AdhocHiveTmpTable.addData(tmptblname, map.get("txtStorePath"));
     
      StringBuffer sqlWhere = new StringBuffer();
      String join = " where ";
      for (String fq : p.fq) {
        sqlWhere.append(join);
        sqlWhere.append(fq);
        join = " and ";
      }
      HashSet<String> allfl=new HashSet<String>();
      for(String s:obj.getString("fl").split(","))
      {
        allfl.add(s.trim());
      }
      allfl.add(p.rightkey);
     
View Full Code Here

public class AdhocUi {
 
  public static String getTableListForUi() throws Exception
  {
    JSONObject jsonObj = new JSONObject();
    jsonObj.put("code", 1);
    jsonObj.put("message", "success");
   
    JSONArray modules = new JSONArray();
   
   
    HashMap<String,JSONObject> tableInfo=new HashMap<String, JSONObject>();
//    {
//      "moduleName": "P4P-推广",
//      "moduleId": "3",
//      "moduleTableName":"rpt_p4padhoc_product",
//      "begin":"2012-10-10",
//            "dateLimit": -30
//    }
    for(String s:TableList.getTablelist())
    {
      JSONObject item=new JSONObject();
      item.put("moduleName", s);
      item.put("moduleId", s);
    }
    Map stormconf = Utils.readStormConfig();
    String uiconfpath=(String) stormconf.get("higo.ui.conf.dir");

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.