메뉴 건너뛰기

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

번호 제목 글쓴이 날짜 조회 수
63 kudu의 내부 table명 변경하는 방법 gooper 2022.11.10 22
62 new Gson().toJson(new ObjectId())을 사용하면 값이 다르게 나오는 경우가 있음 총관리자 2016.12.23 44
61 Master rejected startup because clock is out of sync 오류 해결방법 총관리자 2016.05.03 60
60 Mysql DB 생성 및 권한. 특정아이피, 대역에 대한 접근 허용 총관리자 2017.05.04 60
59 org.apache.hadoop.hbase.ClockOutOfSyncException: org.apache.hadoop.hbase.ClockOutOfSyncException 오류시 조치사항 총관리자 2016.07.14 62
58 권한회수 및 권한부여 명령 몇가지 총관리자 2017.11.16 63
57 bin/cassandra -f -R로 startup할때 NullPointerException오류가 나면 조치할 내용 총관리자 2016.04.14 70
56 hbase startrow와 endrow를 지정하여 검색하기 샘플 총관리자 2016.12.07 70
55 테이블의 row수를 빠르게 카운트 하는 방법 총관리자 2017.01.26 77
54 HBase write 성능 튜닝 file 총관리자 2017.07.18 87
53 MongoDB에 있는 특정컬럼의 값을 casting(string->integer)하여 update하기 java 소스 총관리자 2016.12.19 88
52 centos 6에서 mariadb 5.1 to 10.0 으로 upgrade 총관리자 2016.11.01 106
51 tablet별 disk사용량 확인하는 방법 총관리자 2021.08.27 118
50 HBase 설정 최적화하기(VCNC) file 총관리자 2017.07.18 120
49 console명령과 API비교 총관리자 2015.12.21 120
48 like검색한 결과를 기준으로 집계를 수행하는 java 소스 총관리자 2016.12.19 129
47 SQL문장과 Mongo에서 사용하는 명령어를 비교한 것입니다. 총관리자 2015.09.30 141
46 mongodb에서 큰데이타 sort시 오류발생에 대한 해결방법 총관리자 2015.12.22 145
45 hbase CustomFilter만들기 (0.98.X이상) 총관리자 2015.05.08 162
44 mongodb 2.6.6 설치(64bit) 총관리자 2015.09.30 185

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.

위로