mongoDb的mapReduce應用 外部變數使用關鍵區段springMVC;

來源:互聯網
上載者:User

標籤:mapred   putty   into   function   str   ndt   red   style   全域變數   

long interval = 900000;
long startTime = new Date("2016/03/01 01:00:00").getTime();
long endTime = new Date("2016/03/31 23:59:59").getTime();
String tagUid=(String) arr.get(i);

Query query = Query.query(Criteria.where("TagGuid").in(tagUid));//查詢過濾條件            query.addCriteria(Criteria.where("mDay").is(1));//添加過濾條件            MapReduceOptions options = MapReduceOptions.options();//設定reduce配置項            Map scope = new HashMap();            scope.put("interval", interval);            scope.put("startTime", startTime);            options.scopeVariables(scope).verbose(true).outputTypeInline();//mapreduce外部變數插入            String mapFunction1 = "function () {"                    + "var sSecond=new Date(this.Atime).getTime(),"                    + "tag=parseInt((sSecond-startTime)/interval);"                    + "emit({guid:this.TagGuid,time:tag},{tagUid:this.TagGuid,atime:this.Atime,value:this.TagValue,year:this.mYear,month:this.mMonth,day:this.mDay,seeId:this.SeeID})}";//map方法編寫            String reduceFunction = "function(key,values){ return values[0];} ";//reduce方法編寫                    MapReduceResults<ReturnMessage> result = mongoTemplate.mapReduce(query, "Hdata03", mapFunction1, reduceFunction,options, ReturnMessage.class);//方法調用            Iterator<ReturnMessage> it = result.iterator();//得到結果            long p=0;            while (it.hasNext()) {                ReturnMessage message = it.next();//自訂實體類容器                String  key=(String) JSONObject.fromObject(message.getId()).get("guid");                String insertSql="INSERT  INTO  t_base_data (data) VALUES  (‘"+message.getValue()+"‘)";//插入postgresql                baseDao.updateBySql(insertSql);            }

最後插入postgesql做了迴圈插入  很不科學,浪費大量時間;

主要示範了一個mapreduce全域變數的使用;

其他迴圈只是測試用的,有點累贅;可以不看;

mongoDb的mapReduce應用 外部變數使用關鍵區段springMVC;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.