Search in sources :

Example 11 with ScannerBase

use of org.apache.accumulo.core.client.ScannerBase in project incubator-rya by apache.

the class AccumuloTemporalIndexer method queryInstantBeforeInstant.

/**
 * get statements where the db row ID is BEFORE the given queryInstant.
 */
@Override
public CloseableIteration<Statement, QueryEvaluationException> queryInstantBeforeInstant(final TemporalInstant queryInstant, final StatementConstraints constraints) throws QueryEvaluationException {
    // get rows where the repository time is before the given time.
    final Query query = new Query() {

        @Override
        public Range getRange(final KeyParts keyParts) {
            Text start = null;
            if (keyParts.constraintPrefix != null) {
                // <-- start specific logic
                start = keyParts.constraintPrefix;
            } else {
                start = new Text(KeyParts.HASH_PREFIX_FOLLOWING);
            }
            // <-- end specific logic
            final Text endAt = keyParts.getQueryKey();
            // System.out.println("Scanning queryInstantBeforeInstant: from:" + KeyParts.toHumanString(start) + " up to:" + KeyParts.toHumanString(endAt));
            return new Range(start, true, endAt, false);
        }
    };
    final ScannerBase scanner = query.doQuery(queryInstant, constraints);
    return getContextIteratorWrapper(scanner, constraints.getContext());
}
Also used : ScannerBase(org.apache.accumulo.core.client.ScannerBase) Text(org.apache.hadoop.io.Text) KeyParts(org.apache.rya.indexing.KeyParts) Range(org.apache.accumulo.core.data.Range)

Example 12 with ScannerBase

use of org.apache.accumulo.core.client.ScannerBase in project vertexium by visallo.

the class AccumuloFindPathStrategy method getConnectedVertexIds.

private Map<String, Set<String>> getConnectedVertexIds(Set<String> vertexIds) {
    Span trace = Trace.start("getConnectedVertexIds");
    try {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("getConnectedVertexIds:\n  %s", IterableUtils.join(vertexIds, "\n  "));
        }
        if (vertexIds.size() == 0) {
            return new HashMap<>();
        }
        List<org.apache.accumulo.core.data.Range> ranges = new ArrayList<>();
        for (String vertexId : vertexIds) {
            ranges.add(RangeUtils.createRangeFromString(vertexId));
        }
        int maxVersions = 1;
        Long startTime = null;
        Long endTime = null;
        ScannerBase scanner = graph.createElementScanner(FetchHints.EDGE_REFS, ElementType.VERTEX, maxVersions, startTime, endTime, ranges, false, authorizations);
        IteratorSetting connectedVertexIdsIteratorSettings = new IteratorSetting(1000, ConnectedVertexIdsIterator.class.getSimpleName(), ConnectedVertexIdsIterator.class);
        ConnectedVertexIdsIterator.setLabels(connectedVertexIdsIteratorSettings, deflatedLabels);
        ConnectedVertexIdsIterator.setExcludedLabels(connectedVertexIdsIteratorSettings, deflatedExcludedLabels);
        scanner.addScanIterator(connectedVertexIdsIteratorSettings);
        final long timerStartTime = System.currentTimeMillis();
        try {
            Map<String, Set<String>> results = new HashMap<>();
            for (Map.Entry<Key, Value> row : scanner) {
                try {
                    Map<String, Boolean> verticesExist = graph.doVerticesExist(ConnectedVertexIdsIterator.decodeValue(row.getValue()), authorizations);
                    Set<String> rowVertexIds = stream(verticesExist.keySet()).filter(key -> verticesExist.getOrDefault(key, false)).collect(Collectors.toSet());
                    results.put(row.getKey().getRow().toString(), rowVertexIds);
                } catch (IOException e) {
                    throw new VertexiumException("Could not decode vertex ids for row: " + row.getKey().toString(), e);
                }
            }
            return results;
        } finally {
            scanner.close();
            AccumuloGraph.GRAPH_LOGGER.logEndIterator(System.currentTimeMillis() - timerStartTime);
        }
    } finally {
        trace.stop();
    }
}
Also used : java.util(java.util) Trace(org.apache.accumulo.core.trace.Trace) ConnectedVertexIdsIterator(org.vertexium.accumulo.iterator.ConnectedVertexIdsIterator) VertexiumLogger(org.vertexium.util.VertexiumLogger) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) VertexiumLoggerFactory(org.vertexium.util.VertexiumLoggerFactory) ScannerBase(org.apache.accumulo.core.client.ScannerBase) org.vertexium(org.vertexium) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) IterableUtils(org.vertexium.util.IterableUtils) StreamUtils.stream(org.vertexium.util.StreamUtils.stream) Key(org.apache.accumulo.core.data.Key) Value(org.apache.accumulo.core.data.Value) Span(org.apache.accumulo.core.trace.Span) RangeUtils(org.vertexium.accumulo.util.RangeUtils) Span(org.apache.accumulo.core.trace.Span) ConnectedVertexIdsIterator(org.vertexium.accumulo.iterator.ConnectedVertexIdsIterator) ScannerBase(org.apache.accumulo.core.client.ScannerBase) IOException(java.io.IOException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key)

Aggregations

ScannerBase (org.apache.accumulo.core.client.ScannerBase)12 Key (org.apache.accumulo.core.data.Key)8 Value (org.apache.accumulo.core.data.Value)8 Range (org.apache.accumulo.core.data.Range)7 Text (org.apache.hadoop.io.Text)4 KeyParts (org.apache.rya.indexing.KeyParts)4 IOException (java.io.IOException)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 BatchScanner (org.apache.accumulo.core.client.BatchScanner)3 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)3 Scanner (org.apache.accumulo.core.client.Scanner)3 Span (org.apache.accumulo.core.trace.Span)3 HashMap (java.util.HashMap)2 BatchWriter (org.apache.accumulo.core.client.BatchWriter)2 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)2 ClientSideIteratorScanner (org.apache.accumulo.core.client.ClientSideIteratorScanner)2 Connector (org.apache.accumulo.core.client.Connector)2 IsolatedScanner (org.apache.accumulo.core.client.IsolatedScanner)2 SampleNotPresentException (org.apache.accumulo.core.client.SampleNotPresentException)2