메뉴 건너뛰기

Cloudera, BigData, Semantic IoT, Hadoop, NoSQL

Cloudera CDH/CDP 및 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();
  }
 }

번호 제목 날짜 조회 수
370 hive 0.13.1 설치 + meta정보는 postgresql 9.3에 저장 2015.04.30 4115
369 like검색한 결과를 기준으로 집계를 수행하는 java 소스 2016.12.19 4120
368 원격의 origin/master를 기준으로 dev branch를 만들어 작업후 원격의 origin/dev에 push하는 방법 file 2016.11.22 4128
367 MapReduce2.0(YARN)기반의 CDH5 설치시 생성되는 사용자및 권한 부여 2018.05.30 4129
366 [Sentry]HDFS의 ACL을 Sentry와 연동후 테스트 2020.06.02 4132
365 solrdf초기 기동시 "Caused by: java.lang.IllegalAccessError: tried to access field org.apache.solr.handler.RequestHandlerBase.log from class org.gazzax.labs.solrdf.handler.update.RdfUpdateRequestHandler" 오류가 발생시 조치사항 2016.04.22 4134
364 source, sink를 직접 구현하여 사용하는 예시 2019.05.30 4136
363 fuseki가 제공하는 web ui를 통해서 dataset를 remove->create할 경우 동일한 동일한 이름으로 지정했을때 fuseki-server.jar가 뜨지 않는 현상 2017.02.03 4142
362 oozie 4.1 설치 - maven을 이용한 source compile on hadoop 2.5.2 with postgresql 9.3 2015.04.30 4144
361 "You are running Cloudera Manager in non-production mode.." warning메세지가 나타나지 않게 조치하는 방법 2018.05.23 4145
360 spark 2.3.0을 설치하가 위해서 parcel에 다음 url을 입력한다. 2018.07.15 4148
359 SQL문장과 Mongo에서 사용하는 명령어를 비교한 것입니다. 2015.09.30 4149
358 ServerInfo객체파일 2016.07.21 4150
357 Class.forName을 이용한 메서드 호출 샘플소스 2016.12.21 4152
356 Error: java.lang.RuntimeException: java.lang.OutOfMemoryError 오류가 발생하는 경우 2018.09.20 4153
355 자주쓰는 유용한 프로그램 2018.03.16 4155
354 ubuntu에 maven 3.6.1설치 및 환경변수 설정 2019.06.02 4157
353 SPIN(SPARQL Inference Notation)이란.. file 2016.02.25 4159
352 java.lang.OutOfMemoryError: unable to create new native thread오류 발생지 조치사항 2016.10.17 4160
351 Ubuntu 16.04 LTS에 4대에 Hadoop 2.8.0설치 2017.05.01 4160
위로