메뉴 건너뛰기

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



번호 제목 글쓴이 날짜 조회 수
340 DataNode를 기동할때 "Block pool ID needed, but service not yet registered with NN" 오류 발생에 따른 조치사항 총관리자 2018.05.28 961
339 postgresql-9.4에서 FATAL: remaining connection slots are reserved for non-replication superuser connections가 나올때 조치 총관리자 2018.08.16 945
338 column family삭제시 Column family 'delete' does not exist오류 발생하는 경우 총관리자 2014.04.14 932
337 동일서버에서 LA와 LC동시에 기동하여 테스트 총관리자 2014.04.01 928
336 Current heap configuration for MemStore and BlockCache exceeds the threshold required for successful cluster operation 총관리자 2017.07.18 892
335 unique한 값 생성 총관리자 2014.04.25 888
334 sqoop export/import등을 할때 driver를 못찾는 오류가 발생하면... 총관리자 2014.05.15 867
333 Impala의 Queries탭에서 여러조건으로 쿼리 찾기 총관리자 2018.05.09 864
332 oozie 4.1 설치 - maven을 이용한 source compile on hadoop 2.5.2 with postgresql 9.3 총관리자 2015.04.30 862
331 Hive JDBC Connection과 유형별 에러및 필요한 jar파일 총관리자 2021.05.24 836
330 dual table만들기 총관리자 2014.05.16 826
329 hive query에서 mapreduce돌리지 않고 select하는 방법 총관리자 2014.05.23 811
328 update 샘플 총관리자 2018.03.12 810
327 oozie job 구동시 JA009: User: hadoop is not allowed to impersonate hadoop 오류나는 경우 총관리자 2014.06.02 807
326 sentry설정 방법및 활성화시 설정이 필요한 파일및 설정값, 계정생성 방법 총관리자 2018.08.16 779
325 mongodb aggregation query를 Java code로 변환한 샘플 총관리자 2016.12.15 777
324 oracle to hive data type정리표 총관리자 2018.08.22 765
323 [Kerberos]Kerberos상태의 클러스터에 JDBC로 접근할때 케이스별 오류내용 총관리자 2020.02.14 764
322 beeline실행시 User: root is not allowed to impersonate오류 발생시 조치사항 총관리자 2016.06.03 760
321 [DBeaver 4.3.0]import/export시 "Client home is not specified for connection" 오류발생시 조치사항 총관리자 2017.12.21 753

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.

위로