메뉴 건너뛰기

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



번호 제목 글쓴이 날짜 조회 수
341 우분투 16.04 설치후 APM (Apache2, PHP, MySQL) 설치 총관리자 2017.01.29 185
340 mongodb 2.6.6 설치(64bit) 총관리자 2015.09.30 185
339 Soft memory limit exceeded (at 100.05% of capacity) 오류 조치 총관리자 2022.01.17 181
338 cloudera에서 spark-shell를 실행했을때 default master는 spark.master=yarn-client임 총관리자 2018.06.20 181
337 lagom을 이용한 샘플 경매 프로그램 실행방법 총관리자 2017.06.20 181
336 drools를 이용한 로그,rule matching등의 테스트 java프로그램 file 총관리자 2016.07.21 181
335 java quartz 시간 설정 참고사항 총관리자 2015.12.16 179
334 cloudera서비스 중지및 기동순서 총관리자 2020.02.14 178
333 build할때 unmappable character for encoding MS949 에러 발생시 조치사항 총관리자 2016.08.03 178
332 mybais #과 $의 차이점 총관리자 2015.11.10 178
331 Oracle 12c DB의 LOB타입 컬럼이 있는 테이블을 import할 때 주의 할 사항 gooper 2022.09.14 175
330 문자열을 숫자(integer)로 casting하기 총관리자 2016.01.13 175
329 scala-eclipse 다운로드 총관리자 2019.06.09 174
328 shard3가 있는 서버에 문제가 있는 상태에서 solr query를 요청하는 경우 "no servers hosting shard: shard3" 오류가 발생하는 경우 조치사항 총관리자 2018.01.04 174
327 Mountable HDFS on CentOS 6.x(hadoop 2.7.2의 nfs기능을 이용) 총관리자 2016.11.24 174
326 jena/fuseki 3.4.0 설치 총관리자 2017.07.25 172
325 kerberos설정된 상태의 spooldir->memory->hdfs로 저장하는 과정의 flume agent configuration구성 예시 총관리자 2019.05.30 171
324 HDFS Balancer설정및 수행 총관리자 2018.03.21 171
323 Embedded PostgreSql설정을 외부의 MariaDB로변경하기 [1] 총관리자 2018.05.22 170
322 javax.net.ssl.SSLHanshakeException: SSLHandshakeException invoking https://mainCluster.gooper.com:7183/api/v1/users: sun.security.validator.ValidatorException: No trusted certificate found gooper 2022.06.29 169

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.

위로