메뉴 건너뛰기

Bigdata, Semantic IoT, Hadoop, NoSQL

Bigdata, 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;
	}



번호 제목 글쓴이 날짜 조회 수
339 hadoop에서 yarn jar ..를 이용하여 appliction을 실행하여 정상적(?)으로 수행되었으나 yarn UI의 어플리케이션 목록에 나타나지 않는 문제 총관리자 2017.05.02 77
338 A Cluster의 HDFS 디렉토리및 파일을 사용자및 권한 유지 하여 다운 받아서 B Cluster에 넣기 총관리자 2020.05.06 77
337 Query Status: Sender xxx.xxx.xxx.xxx timed out waiting for receiver fragment instance: 1234:cdsf, dest node: 10 의 오류 원인및 대응방안 총관리자 2021.11.03 77
336 파일끝에 붙는 ^M 일괄 지우기(linux, unix(AIX)) 혹은 파일내에 있는 ^M지우기 총관리자 2016.09.24 78
335 Components of the Impala Server 총관리자 2018.03.21 78
334 Query 1234:1234 expired due to client inactivity(timeout is 5m)및 invalid query handle gooper 2022.06.10 81
333 TLS/SSl설정시 방법및 참고 사항 총관리자 2021.10.08 83
332 Hue Job Browser의 Queries탭에서 조건을 지정하는 방법 총관리자 2018.05.10 84
331 각 서버에 설치되는 cloudera서비스 프로그램 목록(CDH 5.14.0의 경우) 총관리자 2018.03.29 85
330 kudu rebalance수행 command예시 총관리자 2022.01.17 85
329 hive의 메타정보 테이블을 MariaDB로 사용하는 경우 table comment나 column comment에 한글 입력시 깨지는 경우 utf8로 바꾸는 방법. gooper 2023.03.10 86
328 HBase write 성능 튜닝 file 총관리자 2017.07.18 87
» MongoDB에 있는 특정컬럼의 값을 casting(string->integer)하여 update하기 java 소스 총관리자 2016.12.19 88
326 Cloudera Manager재설치하는 동안 "Host is in bad health"오류가 발생하는 경우 확인/조치 사항 총관리자 2018.05.24 88
325 Authorization within Hadoop Projects gooper 2022.06.13 88
324 [2.7.2] distribute-exclude.sh사용할때 ssh 포트변경에 따른 오류발생시 조치사항 총관리자 2018.01.02 89
323 우분투 16.04LTS에 Jupyter설치 총관리자 2018.04.17 90
322 impala session type별 표시되는 정보로 구분하는 방법 총관리자 2021.05.25 90
321 Kudu tablet이 FAILED일때 원인 확인 방법 총관리자 2022.01.17 90
320 It is indirectly referenced from required .class files 오류 발생시 조치방법 총관리자 2017.03.09 93

A personal place to organize information learned during the development of such Hadoop, Hive, Hbase, Semantic IoT, etc.
We are open to the required minutes. Please send inquiries to gooper@gooper.com.

위로