用于从HBase读取Titan顶点的分页

用于从HBase读取Titan顶点的分页,hbase,titan,Hbase,Titan,我目前正在创建一个Java代码,可以从Hadoop HBase后端读取Titan Vertex。我知道blueprint api在每个TransactionalGraph上都提供了一个getVertices()方法,但我仍在尝试实现我自己的方法。现在,对于通常的顶点读取,我已经有了一个可以读取整个HBase后端并从Titan Graph获取所有顶点的工作代码,但是我在实现分页时遇到了一个问题 到目前为止,我的代码是: Scan scan = new Scan(); Filter

我目前正在创建一个Java代码,可以从Hadoop HBase后端读取Titan Vertex。我知道blueprint api在每个TransactionalGraph上都提供了一个getVertices()方法,但我仍在尝试实现我自己的方法。现在,对于通常的顶点读取,我已经有了一个可以读取整个HBase后端并从Titan Graph获取所有顶点的工作代码,但是我在实现分页时遇到了一个问题

到目前为止,我的代码是:

    Scan scan = new Scan();
    Filter pageFilter = new ColumnPaginationFilter(DEFAULT_PAGE_SIZE, currentOffSet);
    scan.setFilter(pageFilter);
    scan.addFamily(Backend.EDGESTORE_NAME.getBytes());
    scan.setMaxVersions(10);
    List<Vertex> vertexList = new ArrayList<>(DEFAULT_PAGE_SIZE);
    HTablePool pool = new HTablePool(config, DEFAULT_PAGE_SIZE);
    ResultScanner scanner = pool.getTable(attributeMap.get("storage.tablename")).getScanner(scan);
Scan扫描=新扫描();
Filter pageFilter=新的ColumnPaginationFilter(默认页面大小,currentOffSet);
scan.setFilter(页面过滤器);
scan.addFamily(Backend.EDGESTORE_NAME.getBytes());
scan.setMaxVersions(10);
列表顶点列表=新的ArrayList(默认页面大小);
HTablePool-pool=新的HTablePool(配置,默认页面大小);
ResultScanner scanner=pool.getTable(attributeMap.get(“storage.tablename”)).getScanner(scan);
但是结果扫描返回整个图形

currentOffSet是一个确定当前页码的int变量

我还尝试了ResultScanner#next(int rowCount)。它很好用。但在这个过程中,我没有选择返回上一页

有人能帮我吗


提前谢谢。我已经解决了。逻辑很简单。您必须在scanner实例上使用setStartRow方法。这是第一次没有必要,因为扫描应该从第一行开始。然后我们需要获取*(页面大小+1)*行数。ResultScanner中的最后一行将用作下一页的起始行

为了返回到上一页,我们需要使用一个缓冲区或堆栈来存储所有先前访问的页面的起始行

以下是我的代码片段:

    Scan scan = (new Scan()).addFamily(Backend.EDGESTORE_NAME.getBytes());
    Filter filter = new PageFilter(DEFAULT_PAGE_SIZE + 1);
    scan.setFilter(filter);
    if (currentPageStartRowForHBase != null) {
        scan.setStartRow(currentPageStartRowForHBase);
    }
    List<Vertex> vertexList = new ArrayList<>(DEFAULT_PAGE_SIZE + 1);
    HTablePool pool = null;
    ResultScanner scanner = null;
    try {
        if (pool == null) {
            pool = new HTablePool(config, DEFAULT_PAGE_SIZE + 1);

        }
        scanner = pool.getTable(attributeMap.get("storage.tablename")).getScanner(scan);
        for (Result result : scanner) {
            ByteBuffer byteBuffer = ByteBuffer.wrap(result.getRow());
            Vertex vertex = this.getVertex(IDHandler.getKeyID(byteBuffer));
            if (vertexList.size() < DEFAULT_PAGE_SIZE)
                vertexList.add(vertex);
            else {
                nextPageStartRowForHBase = byteBuffer.array();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
Scan Scan=(new Scan()).addFamily(Backend.EDGESTORE_NAME.getBytes());
过滤器过滤器=新页面过滤器(默认页面大小+1);
scan.setFilter(filter);
如果(currentPageStartRowForHBase!=null){
scan.setStartRow(currentPageStartRowForHBase);
}
列表顶点列表=新的ArrayList(默认页面大小+1);
HTablePool=null;
结果扫描程序=空;
试一试{
如果(池==null){
pool=新的HTablePool(配置,默认页面大小+1);
}
scanner=pool.getTable(attributeMap.get(“storage.tablename”)).getScanner(scan);
用于(结果:扫描仪){
ByteBuffer ByteBuffer=ByteBuffer.wrap(result.getRow());
顶点顶点=this.getVertex(IDHandler.getKeyID(byteBuffer));
if(vertexList.size()
nextPageStartRowForHBasecurrentPageStartRowForHBase字节[]


这满足了我的要求。但如果有人有更好的解决方案,请与我们分享。

我刚刚开始评估Titan,我的理解是,曾经无法直接从Hbase读取/写入Titan graph数据。看起来你在说这是可能的。你能给我举一些例子来说明如何做到这一点吗?上面的代码是你所要求的最简单的例子。列表顶点列表是我用来保存顶点的集合
IDHandler.getKeyID(byteBuffer)
这一行实际上从HBase后端返回顶点id。现在,一旦我得到顶点id,得到顶点实例就不太复杂了。我需要的是一种从HBase后端和Cassandra读取数据的简单方法,因为Titan不支持全局查询。如果您想要从HBase或Cassandra读取数据的更好方法,您完全可以通过探索后端功能来实现。