메뉴 건너뛰기

Cloudera, BigData, Semantic IoT, Hadoop, NoSQL

Cloudera CDH/CDP 및 Hadoop EcoSystem, Semantic IoT등의 개발/운영 기술을 정리합니다. gooper@gooper.com로 문의 주세요.


* MongoDB shell 구문을 Java Code로 표현하면 아래와 같다.

 db.employee.aggregate({$unwind: '$dp.fin.Record'},       
 {$match:{"dp.mon":"patch.metrics",'dp.fin.Record':{$exists:1}}},      
 {$group:{_id: '$dp.fin.Record', count:{$sum:1}}},      
 {$project:{count:'$count'}},   {$group:{_id:'Total
 Count',total:{$sum:'$count'}}});


-->

DBCollection table=null;
MongoClient mongoClient=null;
DB db = null;

mongoClient = new MongoClient(new ServerAddress(db_server, Integer.parseInt(db_port)));
db = mongoClient.getDB(db_name);
table = db.getCollection(collection_name);


//Forming Unwind parts
DBObject unwind = new BasicDBObject("$unwind","$dp.fin.record");

//Forming Match parts
DBObject match = new BasicDBObject();
match.put("dp.mon","patch.metrics");
match.put("dp.fin.Record", new BasicDBObject("$exists",1));

//Forming Group parts
DBObject group1 = new BasicDBObject();
group1.put("_id", "$dp.fin.Record");
group1.put("count", new BasicDBObject("$sum", 1));

//Forming Project parts
DBObject project = new BasicDBObject();
project.put("count", "$count");

//Forming Group parts
DBObject group2 = new BasicDBObject();
group2.put("_id", "Total Count");
group2.put("total", new BasicDBObject("$sum", "$count"));


/**
 * Executing aggregation 
 */
AggregationOutput output = table.getCollection("employee").aggregate(unwind,				                                                                            
          new BasicDBObject("$match",match),			                                                                            
          new BasicDBObject("$group",group1),				                                                                            
          new BasicDBObject("$project",project),				                                                                            
          new BasicDBObject("$group",group2));

// 결과확인		
System.out.println("output : "+output);;


번호 제목 날짜 조회 수
430 cloudera서비스 중지및 기동순서 2020.02.14 4219
429 컬럼및 라인의 구분자를 지정하여 sqoop으로 데이타를 가져오고 hive테이블을 생성하는 명령문 2018.08.03 4219
428 json 값 다루기 2014.04.17 4218
427 Kafka의 API중 Consumer.createJavaConsumerConnector()를 이용하고 다수의 thread를 생성하여 Kafka broker의 topic에 접근하여 데이타를 가져오고 처리하는 예제 소스 2017.04.26 4211
426 Windows7 64bit 환경에서 Apache Hadoop 2.7.1설치하기 2017.07.26 4210
425 [TLS/SSL]Kudu Tablet Server설정 2022.05.13 4208
424 [sentry]role부여후 테이블명이 변경되어 오류가 발생할때 조치방법 2018.10.16 4199
423 Failed to write to server: (no server available): 2022.01.17 4196
422 [TLS/SSL]Cloudera 6.3.4기준 Oozie Web UI TLS설정 항목및 설정값 2022.05.13 4195
421 AIX 7.1에서 hive실행시 "hive: line 86: readlink: command not found" 오류가 발생시 임시 조치사항 2016.09.25 4195
420 [Sentry] sentry메타 DB를 이용하여 테이블에 매핑되어 있는 role명칭 찾는 방법. 2022.06.22 4191
419 not leader of this config: current role FOLLOWER 오류 발생시 확인방법 2022.01.17 4184
418 It is indirectly referenced from required .class files 오류 발생시 조치방법 2017.03.09 4182
417 hadoop의 data디렉토리를 변경하는 방법 2014.08.24 4179
416 DB별 JDBC 드라이버 2015.10.02 4177
415 vuestorefrontui.io를 이용한 front end project 생성하기 2022.02.06 4176
414 centos 5.X에 hadoop 2.0.5 alpha 설치 2013.12.16 4172
413 hive metastore db중 TBLS, TABLE_PARAMS테이블 설명 2021.10.22 4162
412 java.lang.OutOfMemoryError: unable to create new native thread오류 발생지 조치사항 2016.10.17 4160
411 [AD(LADP)] CDP1.7에서 AD및 Kerberos를 연동해도 각 노드에 os account, os group은 생성되어야 하지만 SSSD서비스를 이용하면 직접 생성될 필요가 없다. 2022.06.10 4159
위로