2017-05-13 7 views
0

MaprdbJava으로 연결하려고합니다. Maprdb 자바 코드로 테이블을 만들 수 있지만 테이블을 스캔 할 수 없습니다.Java로 Maprdb에 연결하여 레코드를 검색하는 방법

<dependencies> 
<dependency> 
    <groupId>com.mapr.db</groupId> 
    <artifactId>maprdb</artifactId> 
    <version>5.2.0-mapr</version> 
</dependency> 
<dependency> 
    <groupId>com.mapr.hadoop</groupId> 
    <artifactId>maprfs-core</artifactId> 
    <version>5.2.0-mapr</version> 
</dependency> 
<dependency> 
    <groupId>com.mapr.hadoop</groupId> 
    <artifactId>maprfs</artifactId> 
    <version>5.2.0-mapr</version> 
</dependency> 
<dependency> 
<groupId>org.apache.hbase</groupId> 
<artifactId>hbase-client</artifactId> 
<version>1.1.8-mapr-1703</version> 
</dependency> 
<dependency> 
<groupId>org.apache.hbase</groupId> 
<artifactId>hbase-client</artifactId> 
<version>1.1.8-mapr-1703</version> 

샘플 코드

Configuration conf = HBaseConfiguration.create(); 
    String Tablepath = "Tablelocationpath"; 
    HTable hTable= new HTable(conf,Tablepath); 

    Get get2 = new Get(Bytes.toBytes("Rowname")); 
    Result r = hTable.get(get2); 
    byte[] value = r.getValue(Bytes.toBytes("CF"), 
      Bytes.toBytes("COlumnqualifier")); 
    String valueStr = Bytes.toString(value); 
    System.out.println("GET: " + valueStr); 

것은 이미이에이 GithubcodeMaprdb with Java Github

모든 리드가 가득 도움이 될 것입니다 다음입니다.

답변

0

이 레벨에서 HBase와 매우 비슷합니다.

스캔하려면 수행 할 스캔 유형을 지정하는 Scan 인스턴스가 필요합니다. 그런 다음이 작업을 사용하여 Scanner을 가져 와서 반복합니다.

// Configuration... 
String tablePath = "Tablelocationpath"; 
Configuration conf; 

// set up your Scan object 
Scan scan = new Scan(); 
scan.setStartRow(...); 
scan.setStopRow(...); 

Connection connection = null; 
Table table = null; 
ResultScanner scanner = null; 
try { 
    connection = ConnectionFactory.createConnection(conf); 
    table = connection.getTable(TableName.valueOf(tablePath)); 
    scanner = table.getScanner(scan); 
    Iterator it = scanner.iterator(); 

    while (it.hasNext()) { 
    Result e1 = (Result) it.next(); 
    // do whatever you want to do with your Result, before getting next one 
    } 

} catch (IOException e) { 
    // handle IOException during connecting/scanning 

} finally { 
    try { 
    if (scanner != null) { 
     scanner.close(); 
    } 

    if (table != null) { 
     table.close(); 
    } 

    if (connection != null) { 
     connection.close(); 
    } 
    } catch (IOException e2) { 
    // handle error on close 
    } 

} 
:

다음은 일반적인 개요입니다