Search in sources :

Example 1 with BindingSetRow

use of org.apache.rya.indexing.pcj.fluo.app.BindingSetRow in project incubator-rya by apache.

the class BatchIT method countResults.

private int countResults(FluoClient fluoClient, String nodeId, Column bsColumn) {
    try (Transaction tx = fluoClient.newTransaction()) {
        int count = 0;
        Optional<NodeType> type = NodeType.fromNodeId(nodeId);
        Bytes prefixBytes = Bytes.of(type.get().getNodeTypePrefix());
        RowScanner scanner = tx.scanner().over(Span.prefix(prefixBytes)).fetch(bsColumn).byRow().build();
        Iterator<ColumnScanner> colScanners = scanner.iterator();
        while (colScanners.hasNext()) {
            ColumnScanner colScanner = colScanners.next();
            BindingSetRow bsRow = BindingSetRow.makeFromShardedRow(prefixBytes, colScanner.getRow());
            if (bsRow.getNodeId().equals(nodeId)) {
                Iterator<ColumnValue> vals = colScanner.iterator();
                while (vals.hasNext()) {
                    vals.next();
                    count++;
                }
            }
        }
        tx.commit();
        return count;
    }
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) Transaction(org.apache.fluo.api.client.Transaction) NodeType(org.apache.rya.indexing.pcj.fluo.app.NodeType) BindingSetRow(org.apache.rya.indexing.pcj.fluo.app.BindingSetRow) RowScanner(org.apache.fluo.api.client.scanner.RowScanner) ColumnScanner(org.apache.fluo.api.client.scanner.ColumnScanner) ColumnValue(org.apache.fluo.api.data.ColumnValue)

Example 2 with BindingSetRow

use of org.apache.rya.indexing.pcj.fluo.app.BindingSetRow in project incubator-rya by apache.

the class ConstructQueryResultObserver method process.

@Override
public void process(TransactionBase tx, Bytes row, Column col) throws Exception {
    // Build row for parent that result will be written to
    BindingSetRow bsRow = BindingSetRow.makeFromShardedRow(Bytes.of(CONSTRUCT_PREFIX), row);
    String constructNodeId = bsRow.getNodeId();
    String bsString = bsRow.getBindingSetString();
    String parentNodeId = queryDao.readMetadadataEntry(tx, constructNodeId, FluoQueryColumns.CONSTRUCT_PARENT_NODE_ID).toString();
    Bytes rowBytes = BindingHashShardingFunction.getShardedScanPrefix(parentNodeId, bsString);
    // Get NodeType of the parent node
    NodeType parentType = NodeType.fromNodeId(parentNodeId).get();
    // Get data for the ConstructQuery result
    Bytes bytes = tx.get(row, col);
    // Write result to parent
    tx.set(rowBytes, parentType.getResultColumn(), bytes);
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) NodeType(org.apache.rya.indexing.pcj.fluo.app.NodeType) BindingSetRow(org.apache.rya.indexing.pcj.fluo.app.BindingSetRow)

Example 3 with BindingSetRow

use of org.apache.rya.indexing.pcj.fluo.app.BindingSetRow in project incubator-rya by apache.

the class BindingHashShardingFunctionTest method bindingSetRowTest.

@Test
public void bindingSetRowTest() {
    String nodeId = NodeType.generateNewFluoIdForType(NodeType.STATEMENT_PATTERN);
    QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("entity", vf.createURI("urn:entity"));
    bs.addBinding("location", vf.createLiteral("location_1"));
    VisibilityBindingSet vBs = new VisibilityBindingSet(bs);
    VariableOrder varOrder = new VariableOrder("entity", "location");
    Bytes row = RowKeyUtil.makeRowKey(nodeId, varOrder, vBs);
    Bytes shardedRow = BindingHashShardingFunction.addShard(nodeId, varOrder, vBs);
    BindingSetRow expected = BindingSetRow.make(row);
    BindingSetRow actual = BindingSetRow.makeFromShardedRow(Bytes.of(SP_PREFIX), shardedRow);
    Assert.assertEquals(expected, actual);
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) BindingSetRow(org.apache.rya.indexing.pcj.fluo.app.BindingSetRow) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Aggregations

Bytes (org.apache.fluo.api.data.Bytes)3 BindingSetRow (org.apache.rya.indexing.pcj.fluo.app.BindingSetRow)3 NodeType (org.apache.rya.indexing.pcj.fluo.app.NodeType)2 Transaction (org.apache.fluo.api.client.Transaction)1 ColumnScanner (org.apache.fluo.api.client.scanner.ColumnScanner)1 RowScanner (org.apache.fluo.api.client.scanner.RowScanner)1 ColumnValue (org.apache.fluo.api.data.ColumnValue)1 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)1 VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)1 Test (org.junit.Test)1 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)1