메뉴 건너뛰기

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

번호 제목 글쓴이 날짜 조회 수
440 LUBM 데이타 생성구문 총관리자 2017.07.24 143
439 Core with name 'xx_shard4_replica1' already exists. 발생시 조치사항 총관리자 2017.07.22 62
438 9대가 hbase cluster로 구성된 서버에서 테스트 data를 halyard에 적재하고 테스트 하는 방법및 절차 총관리자 2017.07.21 56
437 갑자기 DataNode가 java.io.IOException: Premature EOF from inputStream를 반복적으로 발생시키다가 java.lang.OutOfMemoryError: Java heap space를 내면서 죽는 경우 조치방법 총관리자 2017.07.19 1676
436 Current heap configuration for MemStore and BlockCache exceeds the threshold required for successful cluster operation 총관리자 2017.07.18 892
435 HBase 설정 최적화하기(VCNC) file 총관리자 2017.07.18 120
434 HBase write 성능 튜닝 file 총관리자 2017.07.18 87
433 schema.xml vs managed-schema 지정 사용하기 - 두개를 동시에 사용할 수는 없음 총관리자 2017.07.09 153
432 halyard의 console스크립트에서 생성한 repository는 RDF4J Web Applications에서 공유가 되지 않는다. 총관리자 2017.07.05 45
431 halyard 1.3의 rdf4j-server.war와 rdf4j-workbench.war를 tomcat deploy후 조회시 java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/Cell발생시 조치사항 총관리자 2017.07.05 65
430 halyard 1.3을 다른 서버로 이전하는 방법 총관리자 2017.07.05 66
429 python test.py실행시 "ImportError: No module named pyspark" 혹은 "ImportError: No module named py4j.protocol"등의 오류 발생시 조치사항 총관리자 2017.07.04 765
428 solr명령 실행시 "Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect" 오류발생 총관리자 2017.06.30 202
427 mysql에서 외부 디비를 커넥션할 경우 접속 속도가 느려질때 총관리자 2017.06.30 1079
426 solr 6.2에 한글 형태소 분석기(arirang 6.x) 적용 및 테스트 file 총관리자 2017.06.27 879
425 elasticsearch 기동시 permission denied on key 'vm.max_map_count' 오류발생시 조치사항 총관리자 2017.06.23 431
424 http://blog.naver.com... 총관리자 2017.06.23 88
423 Not enough replica available for query at consistency QUORUM가 발생하는 경우 총관리자 2017.06.21 256
422 cassandra cluster 문제가 있는 node제거 하기(DN상태의 노드가 있으면 cassandra cluster 전체에 문제가 발생하므로 반드시 제거할것) 총관리자 2017.06.21 309
421 VPS에서는 root로 실행해도 swap파일을 만들지 못하게 만들어 두었지만 swap파일을 생성하는 방법 총관리자 2017.06.20 120

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.

위로