메뉴 건너뛰기

Bigdata, Semantic IoT, Hadoop, NoSQL

Bigdata, Hadoop ecosystem, Semantic IoT등의 프로젝트를 진행중에 습득한 내용을 정리하는 곳입니다.
필요한 분을 위해서 공개하고 있습니다. 문의사항은 gooper@gooper.com로 메일을 보내주세요.


* 호출하는 쪽에서 사용하는 예시

if(paging) {
   // pageNumber를 100개 이내로 제한한다.
   if(pageNumber <= 0 || pageNumber >= 100) throw new NotProperRangeException("pageNumber is not in proper ranges(0 < pageNumber < 100)");
   rows=StoreUtil.listScanWithPaging(conn, tableName,Bytes.toBytes(startRow),Bytes.toBytes(stopRow), pageNumber, pageSize);
  } else {
   // maxRows를 10000개 이내로 제한한다.
   if(maxRows <= 0 || maxRows >= 10000) throw new NotProperRangeException("maxRows is not in proper ranges(0 < maxRows < 10000)");
   rows=StoreUtil.listScan(conn, tableName,Bytes.toBytes(startRow),Bytes.toBytes(stopRow),maxRows);
  }



------------------------------StoreUtil.java에 포함되는 메서드중 일부 --------------------------------

 // scan with  paging
 static public List<Map<String, byte[]>> listScanWithPaging(HConnection conn, String tableName, byte[] startRow, byte[] stopRow, int pageNumber, int pageSize) throws Exception {
  HTableInterface table = null;
  try {
   table=conn.getTable(Bytes.toBytes(tableName));
   Scan scan=new Scan(startRow);
   if(stopRow!=null)
    scan.setStopRow(stopRow);

   ResultScanner scanner = table.getScanner(scan);
   
   List<Map<String, byte[]>> rows=new LinkedList<Map<String, byte[]>>();
   int skipCnt = 1;
   int rowCnt = 1;
   
   // 잘못된 값이 들어오면 0건 return
   if(pageNumber <= 0 || pageSize <= 0) return rows;
   
   if(pageNumber == 1) pageNumber = 2;
   
   try {
    for (Result rs : scanner) {
     if(skipCnt++ <= ((pageNumber-1) * pageSize)) {
      //System.out.println("skipCnt  == > ["+(skipCnt-1)+"]");
      continue;
     } else {
      //System.out.println("includeCnt  == > ["+(skipCnt-1)+"]");
     }
     
     // 지정한 수만큼 row를 뽑아냄
     if(rowCnt++ > pageSize) break;
     
     Map<String, byte[]> m=new LinkedHashMap<String, byte[]>();
     m.put("rowId", rs.getRow());
           NavigableMap<byte[], NavigableMap<byte[], byte[]>> familyQualifierMap = rs.getNoVersionMap();
           for (byte[] familyBytes : familyQualifierMap.keySet()) {
               NavigableMap<byte[], byte[]> qualifierMap = familyQualifierMap.get(familyBytes);
               for (byte[] qualifier : qualifierMap.keySet())
                m.put(Bytes.toString(qualifier), qualifierMap.get(qualifier));
           }
     rows.add(m);
    }
   } finally {
    scanner.close();
   }
   return rows;
  } finally {
   if(table!=null)table.close();
  }
 }
 
 // count
 static public long getCount(HConnection conn, String tableName, String startRow, String stopRow) throws Exception {
  HTableInterface table = null;
  try {
   if(startRow == null || startRow.equals("")) throw new NullPointerException("startRow is null or '' ");
   if(stopRow == null || stopRow.equals("")) throw new NullPointerException("stopRow is null or '' ");
   
   table=conn.getTable(Bytes.toBytes(tableName));
   Scan scan=new Scan(Bytes.toBytes(startRow));
   if(stopRow!=null)
    scan.setStopRow(Bytes.toBytes(stopRow));

   ResultScanner scanner = table.getScanner(scan);
   
   long cnt=0L;
   try {
    for (Result rs = scanner.next(); rs != null; rs = scanner.next()) {
        cnt++;
    }   
   } finally {
    scanner.close();
   }
   return cnt;
  } finally {
   if(table!=null)table.close();
  }
 }

번호 제목 글쓴이 날짜 조회 수
417 .git폴더를 삭제하고 다시 git에 추가하고 서버에 반영하는 방법 총관리자 2017.06.19 4069
416 [Dovecot] -ERR [SYS/PERM] Permission denied 총관리자 2017.06.13 236
415 숭실대 교수님등 강의영상(바이오데이터마이닝, 빅데이터분산컴퓨팅, 컴퓨터 그래픽스, 데이터베이스응용및 프로그램밍, 데이터베이스, 의생명영상처리, 웹그로그래밍, 데이터마이닝, 컴퓨터구조) file 총관리자 2017.06.13 204
414 시맨틱 관련 논문 모음 사이트 총관리자 2017.06.13 94
413 [dovecot]dovecot restart할때 root@gsda4:/usr/lib/dovecot# service dovecot restart 오류 발생시 조치사항 총관리자 2017.06.12 492
412 sendmail + dovecot(pop3) + saslauthd 설치 총관리자 2017.06.11 180
411 sendmail전송시 421 4.3.0 collect: Cannot write ./dfv5BA2EBS010579 (bfcommit, uid=0, gid=114): No such file or directory 발생시 조치사항 총관리자 2017.06.11 694
410 Eclipse 에서 bitbucket.org 연동 하기 file 총관리자 2017.06.08 256
409 [u-Auctions]목록이 1개만 나오는 문제 총관리자 2017.05.29 38
408 Ubuntu 16.04 LTS에서 sendmail설치및 설정(수신,발신 가능)및 메일서버 만들기 총관리자 2017.05.23 1111
407 Ubuntu 16.04LTS 설치후 초기에 주어야 하는 작업(php, apache, mariadb설치및 OS보안설정등) file 총관리자 2017.05.23 5261
406 Ubuntu 16.04 LTS에서 사이트에 무료인증서를 이용하여 SSL적용 file 총관리자 2017.05.23 353
405 fuseki용 config-examples.ttl 예시 내용 총관리자 2017.05.17 646
404 webid에서 google처럼 검색할 수 있도록 하는 프로그램 총관리자 2017.05.16 46
403 mysql-server 기동시 Do you already have another mysqld server running on port 오류 발생할때 확인및 조치방법 총관리자 2017.05.14 2656
402 php auction 프로그램 총관리자 2017.05.14 94
401 [PHP7.0]로그파일 위치 총관리자 2017.05.07 151
400 mapreduce appliction을 실행시 "is running beyond virtual memory limits" 오류 발생시 조치사항 총관리자 2017.05.04 16888
399 Mysql DB 생성 및 권한. 특정아이피, 대역에 대한 접근 허용 총관리자 2017.05.04 60
398 Hive MetaStore Server기동시 Could not create "increment"/"table" value-generation container SEQUENCE_TABLE since autoCreate flags do not allow it. 오류발생시 조치사항 총관리자 2017.05.03 340

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.

위로