Search in sources :

Example 11 with Snapshot

use of org.apache.fluo.api.client.Snapshot in project incubator-rya by apache.

the class BatchIT method getNodeIdStrings.

private List<String> getNodeIdStrings(FluoClient fluoClient, String queryId) throws UnsupportedQueryException {
    List<String> nodeStrings;
    try (Snapshot sx = fluoClient.newSnapshot()) {
        FluoQuery query = dao.readFluoQuery(sx, queryId);
        nodeStrings = FluoQueryUtils.collectNodeIds(query);
    }
    return nodeStrings;
}
Also used : Snapshot(org.apache.fluo.api.client.Snapshot) FluoQuery(org.apache.rya.indexing.pcj.fluo.app.query.FluoQuery)

Example 12 with Snapshot

use of org.apache.fluo.api.client.Snapshot in project incubator-rya by apache.

the class CreateDeletePeriodicPCJ method getFluoTableEntries.

private List<Bytes> getFluoTableEntries(final FluoClient fluoClient) {
    try (Snapshot snapshot = fluoClient.newSnapshot()) {
        final List<Bytes> rows = new ArrayList<>();
        final RowScanner rscanner = snapshot.scanner().over(Span.prefix("")).byRow().build();
        for (final ColumnScanner cscanner : rscanner) {
            rows.add(cscanner.getRow());
        }
        return rows;
    }
}
Also used : Snapshot(org.apache.fluo.api.client.Snapshot) Bytes(org.apache.fluo.api.data.Bytes) ArrayList(java.util.ArrayList) RowScanner(org.apache.fluo.api.client.scanner.RowScanner) ColumnScanner(org.apache.fluo.api.client.scanner.ColumnScanner)

Example 13 with Snapshot

use of org.apache.fluo.api.client.Snapshot in project incubator-rya by apache.

the class GetPcjMetadata method getMetadata.

/**
 * Get the {@link PcjMetadata} of a query that is being maintained by the
 * Fluo app.
 *
 * @param pcjStorage - The PCJ Storage that will be searched. (not null)
 * @param fluo - The Fluo instance that will be searched. (not null)
 * @param queryId - The Query Id whose metadata will be fetched. (not null)
 * @return The {@link PcjMetadata} of the query.
 * @throws NotInFluoException The query Id does not have a PCJ export able
 *   associated with it in the Fluo table.
 * @throws NotInAccumuloException The PCJ export table that was found either
 *   does not exist in Accumulo or it is not a PCJ table.
 */
public PcjMetadata getMetadata(final PrecomputedJoinStorage pcjStorage, final FluoClient fluo, final String queryId) throws NotInFluoException, NotInAccumuloException {
    requireNonNull(pcjStorage);
    requireNonNull(fluo);
    requireNonNull(queryId);
    // Lookup the Rya PCJ ID associated with the query.
    String pcjId = null;
    try (Snapshot snap = fluo.newSnapshot()) {
        pcjId = FluoQueryUtils.convertFluoQueryIdToPcjId(queryId);
        if (pcjId == null) {
            throw new NotInFluoException("Could not get the PcjMetadata for queryId '" + queryId + "' because a Rya PCJ ID not stored in the Fluo table.");
        }
    }
    // Fetch the metadata from the storage.
    try {
        return pcjStorage.getPcjMetadata(pcjId);
    } catch (final PcjException e) {
        throw new NotInAccumuloException("Could not get the PcjMetadata for queryId '" + queryId + "' because the metadata was missing from the Rya storage.", e);
    }
}
Also used : Snapshot(org.apache.fluo.api.client.Snapshot) PcjException(org.apache.rya.indexing.pcj.storage.PcjException)

Example 14 with Snapshot

use of org.apache.fluo.api.client.Snapshot in project incubator-rya by apache.

the class ListQueryIds method listQueryIds.

/**
 * Finds all queries that are being managed by this instance of Fluo that
 * are also being exported to the provided instance of Accumulo.
 *
 * @param fluo - The Fluo instance that will be searched. (not null)
 * @return An ascending alphabetically sorted list of the Query IDs being
 *   managed by the Fluo app and exported to an instance of Accumulo.
 */
public List<String> listQueryIds(final FluoClient fluo) {
    checkNotNull(fluo);
    final List<String> queryIds = new ArrayList<>();
    try (Snapshot snap = fluo.newSnapshot()) {
        // Create an iterator that iterates over the QUERY_ID column.
        final CellScanner cellScanner = snap.scanner().fetch(FluoQueryColumns.QUERY_NODE_ID).build();
        for (RowColumnValue rcv : cellScanner) {
            queryIds.add(rcv.getsValue());
        // TODO this was doing a snap.get that seemed unnecessary
        }
    }
    // Sort them alphabetically.
    Collections.sort(queryIds);
    return queryIds;
}
Also used : Snapshot(org.apache.fluo.api.client.Snapshot) ArrayList(java.util.ArrayList) CellScanner(org.apache.fluo.api.client.scanner.CellScanner) RowColumnValue(org.apache.fluo.api.data.RowColumnValue)

Example 15 with Snapshot

use of org.apache.fluo.api.client.Snapshot in project incubator-rya by apache.

the class PeriodicNotificationBinPrunerIT method compareFluoCounts.

private void compareFluoCounts(FluoClient client, String pcjId, long bin) {
    QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding(IncrementalUpdateConstants.PERIODIC_BIN_ID, new LiteralImpl(Long.toString(bin), XMLSchema.LONG));
    VariableOrder varOrder = new VariableOrder(IncrementalUpdateConstants.PERIODIC_BIN_ID);
    try (Snapshot sx = client.newSnapshot()) {
        String fluoQueryId = NodeType.generateNewIdForType(NodeType.QUERY, pcjId);
        Set<String> ids = new HashSet<>();
        PeriodicQueryUtil.getPeriodicQueryNodeAncestorIds(sx, fluoQueryId, ids);
        for (String id : ids) {
            NodeType optNode = NodeType.fromNodeId(id).orNull();
            if (optNode == null)
                throw new RuntimeException("Invalid NodeType.");
            Bytes prefix = RowKeyUtil.makeRowKey(id, varOrder, bs);
            RowScanner scanner = sx.scanner().fetch(optNode.getResultColumn()).over(Span.prefix(prefix)).byRow().build();
            int count = 0;
            Iterator<ColumnScanner> colScannerIter = scanner.iterator();
            while (colScannerIter.hasNext()) {
                ColumnScanner colScanner = colScannerIter.next();
                String row = colScanner.getRow().toString();
                Iterator<ColumnValue> values = colScanner.iterator();
                while (values.hasNext()) {
                    values.next();
                    count++;
                }
            }
            Assert.assertEquals(0, count);
        }
    }
}
Also used : VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) ColumnScanner(org.apache.fluo.api.client.scanner.ColumnScanner) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) LiteralImpl(org.openrdf.model.impl.LiteralImpl) Snapshot(org.apache.fluo.api.client.Snapshot) Bytes(org.apache.fluo.api.data.Bytes) NodeType(org.apache.rya.indexing.pcj.fluo.app.NodeType) RowScanner(org.apache.fluo.api.client.scanner.RowScanner) ColumnValue(org.apache.fluo.api.data.ColumnValue) HashSet(java.util.HashSet)

Aggregations

Snapshot (org.apache.fluo.api.client.Snapshot)23 FluoClient (org.apache.fluo.api.client.FluoClient)13 Transaction (org.apache.fluo.api.client.Transaction)13 Test (org.junit.Test)13 VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)10 ArrayList (java.util.ArrayList)4 ColumnScanner (org.apache.fluo.api.client.scanner.ColumnScanner)4 RowScanner (org.apache.fluo.api.client.scanner.RowScanner)3 Bytes (org.apache.fluo.api.data.Bytes)3 BigInteger (java.math.BigInteger)2 AggregationElement (org.apache.rya.api.function.aggregation.AggregationElement)2 FluoQuery (org.apache.rya.indexing.pcj.fluo.app.query.FluoQuery)2 HashSet (java.util.HashSet)1 CellScanner (org.apache.fluo.api.client.scanner.CellScanner)1 ColumnValue (org.apache.fluo.api.data.ColumnValue)1 RowColumnValue (org.apache.fluo.api.data.RowColumnValue)1 ConstructGraph (org.apache.rya.indexing.pcj.fluo.app.ConstructGraph)1 NodeType (org.apache.rya.indexing.pcj.fluo.app.NodeType)1 FilterMetadata (org.apache.rya.indexing.pcj.fluo.app.query.FilterMetadata)1 JoinMetadata (org.apache.rya.indexing.pcj.fluo.app.query.JoinMetadata)1