메뉴 건너뛰기

Cloudera, BigData, Semantic IoT, Hadoop, NoSQL

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


* _uri및 ct에 like검색을 수행하여 리턴되는 결과값 중에서 con의 값을 string->interger로 casting한후 원래의 _id를 key로 하여

update하는 java소스 코드이다.(주의할점은 아래의 예제는 makeStringMap를 이용하여 모든 값을 String으로 변경되므로 숫자등의 속성이 유지 되어야 하는 값은 적절하게 변환하여 주어야 한다)


// MongoDB연결
		try {
			mongoClient = new MongoClient(new ServerAddress(db_server, Integer.parseInt(db_port)));
			db = mongoClient.getDB(db_name);
			table = db.getCollection(collection_name);
		} catch (Exception ex) {
			log.debug("MongoDB connection error : "+ex.getMessage());
			if(db != null) {
				db.cleanCursors(true);
				db = null;				
			}
			if(table != null) {table = null;}
			if(mongoClient != null ) {
				mongoClient.close();
			}
			throw ex;
		} 

// con값에 대한 형변환(String -> Integer)
		// 형변환(shell 코드)
	/*		db.resource.find (
				    {"_uri": /TicketCount/status/CONTENT_INST/, "ct": /20161213/}
				)
				    .forEach(function(x) {
				    x.con = new NumberInt(x.con);  
				      db.resource.save(x)  })
	*/		
	   DBObject searchCastQuery = new BasicDBObject();  //"$match", new BasicDBObject("ct", new BasicDBObject("$gte", "20161213T160000")));
	   searchCastQuery.put("_uri", new BasicDBObject("$regex", "TicketCount/status/CONTENT_INST"));
	   //searchCastQuery.put("ct", new BasicDBObject("$regex", "20161213"));
	   searchCastQuery.put("ct", new BasicDBObject("$regex", Utils.sysdateFormat.format(new Date())));
		
		DBCursor cursor = table.find(searchCastQuery);
		while (cursor.hasNext()) {
			DBObject oldObj = cursor.next();
			
			@SuppressWarnings("unchecked")
			Map<String, String> map = makeStringMap(oldObj.toMap());
			//map.put("_id", new ObjectId(map.get("_id")));
			
			ObjectId id = new ObjectId(map.get("_id"));
			BasicDBObject newObj = new BasicDBObject(map);
			newObj.append("_id", id);
                        newObj.append("con", Integer.parseInt(map.get("con")));
			newObj.append("ty", Integer.parseInt(map.get("ty")));
			newObj.append("st", Integer.parseInt(map.get("st")));
			newObj.append("cs", Integer.parseInt(map.get("cs")));
			
			String lbl_tmp = map.get("lbl");
			Gson gson = new Gson();
			String[] lbl_json = gson.fromJson(lbl_tmp ,String[].class);
			
			newObj.append("lbl", lbl_json);

			BasicDBObject updateObj = new BasicDBObject();
			updateObj.put("$set", newObj);

			table.update(oldObj, updateObj);
		}


makeStringMap함수

public Map<String,String> makeStringMap(Map<String, String> map) {
		Map<String, String> newMap = new HashMap<String, String>();
		
    	Set<String> entry = map.keySet();
    	Iterator<String> itr = entry.iterator();
    	
    	while(itr.hasNext()) {
    		String key = String.valueOf(itr.next());
    		//System.out.println("key : "+key);
    		String value = String.valueOf(map.get(key));
    		//System.out.println("value : "+value);
    		
    		newMap.put(key, value);
    	}
    	
	    return newMap;
	}



번호 제목 날짜 조회 수
287 CM의 Impala->Query tab에서 FINISHED query가 보이지 않는 현상 2021.08.31 4494
286 zookeeper 3.4.6 설치(3대) 2015.04.28 4492
285 sqoop export/import등을 할때 driver를 못찾는 오류가 발생하면... 2014.05.15 4490
284 index생성, 삭제, 활용 2014.04.25 4488
283 [Cloudera Agent] Metadata-Plugin throttling_logger INFO (713 skipped) Unable to send data to nav server. Will try again. 2022.05.16 4484
282 Error: IO_ERROR : java.io.IOException: Error while connecting Oozie server 2022.05.02 4483
281 hue.desktop_document2의 type의 종류 2020.02.10 4483
280 클러스터내의 전체 workflow및 coordinator현황을 사용자별로 추출하는 방법 2021.11.25 4479
279 postgresql-9.4에서 FATAL: remaining connection slots are reserved for non-replication superuser connections가 나올때 조치 2018.08.16 4479
278 ExWordCount jar파일 file 2013.03.06 4476
277 DataNode를 기동할때 "Block pool ID needed, but service not yet registered with NN" 오류 발생에 따른 조치사항 2018.05.28 4469
276 secureCRT에서 backspace키가 작동하지 않는 경우 해결방법 2015.05.11 4468
275 cloudera(python 2.7.5)에서 anaconda3로 설치한 외부 python(3.6.6)을 이용하여 pyspark를 사용하는 설정 2018.09.14 4464
274 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable원인 2015.04.27 4460
273 kudu 테이블 metadata강제 삭제시 발생하는 오류 메세지 2022.01.12 4457
272 Cannot create /var/run/oozie/oozie.pid: Directory nonexistent오류 2014.06.03 4451
271 Error: Could not find or load main class nodemnager 가 발생할때 해결하는 방법 2015.06.05 4448
270 unique한 값 생성 2014.04.25 4448
269 Hadoop Clsuter에 이미 포함된 host의 hostname변경시 처리 절차 2023.03.24 4446
268 source의 type을 spooldir로 하는 경우 해당 경로에 파일이 들어오면 파일단위로 전송함 2014.05.20 4442
위로