메뉴 건너뛰기

Cloudera, BigData, Semantic IoT, Hadoop, NoSQL

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


1. 정렬 수행

        // data를 담고 있는 List변수

List<Map<String, String>> list = new ArrayList<Map<String, String>>();

        // List에 담기는 Map변수

HashMap<String,String> row = new HashMap<String, String>;


// 정렬실행

Collections.sort(list, new MapStringComparator("rest_type"));

Collections.sort(list, new MapStringComparator("corner_id"));

Collections.sort(list, new MapFloatComparator("cnt"));


2. 정렬 클래스(문자열)

class MapStringComparator implements Comparator<Map<String, String>> {
		private final String key;
		
		public MapStringComparator(String key) {
			this.key = key;
		}
		
		@Override
		public int compare(Map<String, String> first, Map<String, String> second) {
			String firstValue =first.get(key);
	        String secondValue = second.get(key);
	        
	         // 내림차순 정렬
             return firstValue.compareTo(secondValue);
		}
	}


3. 정렬 클래스(숫자)

class MapFloatComparator implements Comparator<Map<String, String>> {
		private final String key;
		
		public MapFloatComparator(String key) {
			this.key = key;
		}
		
		@Override
		public int compare(Map<String, String> first, Map<String, String> second) {
			float firstValue = Float.valueOf(first.get(key));
	         float secondValue = Float.valueOf(second.get(key));
	         
			// 내림차순 정렬
	         if (firstValue > secondValue) {
	             return -1;
	         } else if (firstValue < secondValue) {
	             return 1;
	         } else /* if (firstValue == secondValue) */ {
	             return 0;
	         }
		}
	}


번호 제목 날짜 조회 수
341 Scala를 이용한 Streaming예제 2018.03.08 512
340 mongodb에서 큰데이타 sort시 오류발생에 대한 해결방법 2015.12.22 513
339 Windows7 64bit 환경에서 Apache Hadoop 2.7.1설치하기 2017.07.26 513
338 우분투 16.04LTS에 Jupyter설치 2018.04.17 514
337 Soft memory limit exceeded (at 100.05% of capacity) 오류 조치 2022.01.17 515
336 서버중 slave,worker,regionserver만 재기동해야 할때 필요한 기동스크립트및 사용방법 2017.02.03 516
335 streaming작업시 입력된 값에 대한 사본을 만들게 되는데 이것이 실패했을때 발생하는 경고메세지 2017.04.03 516
334 fuseki에서 제공하는 script중 s-post를 사용하는 예문 2017.09.15 517
333 우분투 서버에 GUI로 접속하기 file 2018.05.27 518
332 [HIVESERVER2]프로세스의 thread및 stack trace를 덤프하는 방법(pstack, jstack) 2022.05.11 518
331 Caused by: java.lang.ClassNotFoundException: org.apache.spark.Logging 발생시 조치사항 2017.04.19 519
330 AIX 7.1에서 hive실행시 "hive: line 86: readlink: command not found" 오류가 발생시 임시 조치사항 2016.09.25 520
329 Error: E0501 : E0501: Could not perform authorization operation, User: hadoop is not allowed to impersonate hadoop 해결하는 방법 2015.06.07 521
328 hadoop 어플리케이션을 사용하는 사용자 변경시 바꿔줘야 하는 부분 2016.09.23 524
327 Could not configure server becase SASL configuration did not allow the Zookeeper server to authenticate itself properly: javax.security.auth.login.LoginException: Checksum failed 2019.05.18 525
326 python실행시 ValueError: zero length field name in format오류 해결방법 2016.05.27 527
325 new Gson().toJson(new ObjectId())을 사용하면 값이 다르게 나오는 경우가 있음 2016.12.23 531
324 halyard의 console스크립트에서 생성한 repository는 RDF4J Web Applications에서 공유가 되지 않는다. 2017.07.05 533
323 github에 있는 프로젝트와 로컬에서 작업한 프로젝트 합치기 2016.11.22 536
322 여러 홈페이지를 운영하거나 혹은 서버에 가입한 사용자들에게 홈페이지 계정을 나누어 줄수 있도록 설정/계정 생성방법 2018.01.23 536
위로