Search in sources :

Example 1 with EdgeInfo

use of org.vertexium.accumulo.iterator.model.EdgeInfo in project vertexium by visallo.

the class AccumuloGraph method findRelatedEdgeSummary.

@Override
public Iterable<RelatedEdge> findRelatedEdgeSummary(Iterable<String> vertexIds, Long endTime, Authorizations authorizations) {
    Set<String> vertexIdsSet = IterableUtils.toSet(vertexIds);
    Span trace = Trace.start("findRelatedEdgeSummary");
    try {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("findRelatedEdgeSummary:\n  %s", IterableUtils.join(vertexIdsSet, "\n  "));
        }
        if (vertexIdsSet.size() == 0) {
            return new ArrayList<>();
        }
        List<org.apache.accumulo.core.data.Range> ranges = new ArrayList<>();
        for (String vertexId : vertexIdsSet) {
            ranges.add(RangeUtils.createRangeFromString(vertexId));
        }
        Long startTime = null;
        int maxVersions = 1;
        FetchHints fetchHints = FetchHints.builder().setIncludeOutEdgeRefs(true).build();
        ScannerBase scanner = createElementScanner(fetchHints, ElementType.VERTEX, maxVersions, startTime, endTime, ranges, false, authorizations);
        IteratorSetting edgeRefFilterSettings = new IteratorSetting(1000, EdgeRefFilter.class.getSimpleName(), EdgeRefFilter.class);
        EdgeRefFilter.setVertexIds(edgeRefFilterSettings, vertexIdsSet);
        scanner.addScanIterator(edgeRefFilterSettings);
        final long timerStartTime = System.currentTimeMillis();
        try {
            List<RelatedEdge> results = new ArrayList<>();
            List<String> softDeletedEdgeIds = new ArrayList<>();
            for (Map.Entry<Key, Value> row : scanner) {
                Text columnFamily = row.getKey().getColumnFamily();
                if (!columnFamily.equals(AccumuloVertex.CF_OUT_EDGE)) {
                    if (columnFamily.equals(AccumuloVertex.CF_OUT_EDGE_SOFT_DELETE) || columnFamily.equals(AccumuloVertex.CF_OUT_EDGE_HIDDEN)) {
                        softDeletedEdgeIds.add(row.getKey().getColumnQualifier().toString());
                        results.removeIf(relatedEdge -> softDeletedEdgeIds.contains(relatedEdge.getEdgeId()));
                    }
                    continue;
                }
                org.vertexium.accumulo.iterator.model.EdgeInfo edgeInfo = new EdgeInfo(row.getValue().get(), row.getKey().getTimestamp());
                String edgeId = row.getKey().getColumnQualifier().toString();
                String outVertexId = row.getKey().getRow().toString();
                String inVertexId = edgeInfo.getVertexId();
                String label = getNameSubstitutionStrategy().inflate(edgeInfo.getLabel());
                if (!softDeletedEdgeIds.contains(edgeId)) {
                    results.add(new RelatedEdgeImpl(edgeId, label, outVertexId, inVertexId));
                }
            }
            return results;
        } finally {
            scanner.close();
            GRAPH_LOGGER.logEndIterator(System.currentTimeMillis() - timerStartTime);
        }
    } finally {
        trace.stop();
    }
}
Also used : Span(org.apache.accumulo.core.trace.Span) EdgeInfo(org.vertexium.accumulo.iterator.model.EdgeInfo) IteratorFetchHints(org.vertexium.accumulo.iterator.model.IteratorFetchHints) Text(org.apache.hadoop.io.Text) IndexHint(org.vertexium.search.IndexHint) Value(org.apache.accumulo.core.data.Value) StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey) EdgeInfo(org.vertexium.accumulo.iterator.model.EdgeInfo)

Example 2 with EdgeInfo

use of org.vertexium.accumulo.iterator.model.EdgeInfo in project vertexium by visallo.

the class AccumuloGraphTestBase method testGetKeyValuePairsForEdgeMutation.

@SuppressWarnings("UnusedAssignment")
@Test
public void testGetKeyValuePairsForEdgeMutation() {
    EdgeBuilderByVertexId m = graph.prepareEdge("e1", "v1", "v2", LABEL_LABEL1, 100L, VISIBILITY_A);
    Metadata metadata = new Metadata();
    metadata.add("key1_prop2_m1", "m1_value", VISIBILITY_A);
    metadata.add("key1_prop2_m2", "m2_value", VISIBILITY_A);
    m.addPropertyValue("key1", "author", "value_key1_author", metadata, 400L, VISIBILITY_A_AND_B);
    metadata = new Metadata();
    metadata.add("key1_prop1_m1", "m1_value", VISIBILITY_A);
    metadata.add("key1_prop1_m2", "m2_value", VISIBILITY_A);
    m.addPropertyValue("key1", "prop1", "value_key1_prop1", metadata, 200L, VISIBILITY_A);
    metadata = new Metadata();
    metadata.add("key2_prop1_m1", "m1_value", VISIBILITY_A);
    metadata.add("key2_prop1_m2", "m2_value", VISIBILITY_A);
    m.addPropertyValue("key2", "prop1", "value_key2_prop1", metadata, 300L, VISIBILITY_B);
    List<KeyValuePair> keyValuePairs = toList(((EdgeBuilderWithKeyValuePairs) m).getEdgeTableKeyValuePairs());
    Collections.sort(keyValuePairs);
    assertEquals(12, keyValuePairs.size());
    String authorDeflated = substitutionDeflate("author");
    int i = 0;
    KeyValuePair pair;
    pair = keyValuePairs.get(i++);
    assertEquals(new Key(new Text("e1"), AccumuloEdge.CF_SIGNAL, new Text(LABEL_LABEL1), new Text("a"), 100L), pair.getKey());
    assertEquals(ElementMutationBuilder.EMPTY_VALUE, pair.getValue());
    pair = keyValuePairs.get(i++);
    assertEquals(new Key(new Text("e1"), AccumuloEdge.CF_IN_VERTEX, new Text("v2"), new Text("a"), 100L), pair.getKey());
    assertEquals(ElementMutationBuilder.EMPTY_VALUE, pair.getValue());
    pair = keyValuePairs.get(i++);
    assertEquals(new Key(new Text("e1"), AccumuloEdge.CF_OUT_VERTEX, new Text("v1"), new Text("a"), 100L), pair.getKey());
    assertEquals(ElementMutationBuilder.EMPTY_VALUE, pair.getValue());
    pair = keyValuePairs.get(i++);
    assertEquals(new Key(new Text("e1"), AccumuloElement.CF_PROPERTY, new Text(authorDeflated + "\u001fkey1"), new Text("a&b"), 400L), pair.getKey());
    assertTrue(pair.getValue().toString().contains("value_key1_author"));
    pair = keyValuePairs.get(i++);
    assertEquals(new Key(new Text("e1"), AccumuloElement.CF_PROPERTY, new Text("prop1\u001fkey1"), new Text("a"), 200L), pair.getKey());
    assertTrue(pair.getValue().toString().contains("value_key1_prop1"));
    pair = keyValuePairs.get(i++);
    assertEquals(new Key(new Text("e1"), AccumuloElement.CF_PROPERTY, new Text("prop1\u001fkey2"), new Text("b"), 300L), pair.getKey());
    assertTrue(pair.getValue().toString().contains("value_key2_prop1"));
    pair = keyValuePairs.get(i++);
    assertEquals(new Key(new Text("e1"), AccumuloElement.CF_PROPERTY_METADATA, new Text(authorDeflated + "\u001fkey1\u001Fa&b\u001Fkey1_prop2_m1"), new Text("a"), 400L), pair.getKey());
    assertTrue(pair.getValue().toString().contains("m1_value"));
    pair = keyValuePairs.get(i++);
    assertEquals(new Key(new Text("e1"), AccumuloElement.CF_PROPERTY_METADATA, new Text(authorDeflated + "\u001fkey1\u001Fa&b\u001Fkey1_prop2_m2"), new Text("a"), 400L), pair.getKey());
    assertTrue(pair.getValue().toString().contains("m2_value"));
    pair = keyValuePairs.get(i++);
    assertEquals(new Key(new Text("e1"), AccumuloElement.CF_PROPERTY_METADATA, new Text("prop1\u001fkey1\u001Fa\u001Fkey1_prop1_m1"), new Text("a"), 200L), pair.getKey());
    assertTrue(pair.getValue().toString().contains("m1_value"));
    pair = keyValuePairs.get(i++);
    assertEquals(new Key(new Text("e1"), AccumuloElement.CF_PROPERTY_METADATA, new Text("prop1\u001fkey1\u001Fa\u001Fkey1_prop1_m2"), new Text("a"), 200L), pair.getKey());
    assertTrue(pair.getValue().toString().contains("m2_value"));
    pair = keyValuePairs.get(i++);
    assertEquals(new Key(new Text("e1"), AccumuloElement.CF_PROPERTY_METADATA, new Text("prop1\u001fkey2\u001Fb\u001Fkey2_prop1_m1"), new Text("a"), 300L), pair.getKey());
    assertTrue(pair.getValue().toString().contains("m1_value"));
    pair = keyValuePairs.get(i++);
    assertEquals(new Key(new Text("e1"), AccumuloElement.CF_PROPERTY_METADATA, new Text("prop1\u001fkey2\u001Fb\u001Fkey2_prop1_m2"), new Text("a"), 300L), pair.getKey());
    assertTrue(pair.getValue().toString().contains("m2_value"));
    i = 0;
    keyValuePairs = toList(((EdgeBuilderWithKeyValuePairs) m).getVertexTableKeyValuePairs());
    Collections.sort(keyValuePairs);
    assertEquals(2, keyValuePairs.size());
    pair = keyValuePairs.get(i++);
    org.vertexium.accumulo.iterator.model.EdgeInfo edgeInfo = new EdgeInfo(getGraph().getNameSubstitutionStrategy().deflate(LABEL_LABEL1), "v2");
    assertEquals(new Key(new Text("v1"), AccumuloVertex.CF_OUT_EDGE, new Text("e1"), new Text("a"), 100L), pair.getKey());
    assertEquals(edgeInfo.toValue(), pair.getValue());
    pair = keyValuePairs.get(i++);
    edgeInfo = new EdgeInfo(getGraph().getNameSubstitutionStrategy().deflate(LABEL_LABEL1), "v1");
    assertEquals(new Key(new Text("v2"), AccumuloVertex.CF_IN_EDGE, new Text("e1"), new Text("a"), 100L), pair.getKey());
    assertEquals(edgeInfo.toValue(), pair.getValue());
}
Also used : Text(org.apache.hadoop.io.Text) EdgeInfo(org.vertexium.accumulo.iterator.model.EdgeInfo) DataTableRowKey(org.vertexium.accumulo.keys.DataTableRowKey) Key(org.apache.accumulo.core.data.Key) EdgeInfo(org.vertexium.accumulo.iterator.model.EdgeInfo) Test(org.junit.Test)

Example 3 with EdgeInfo

use of org.vertexium.accumulo.iterator.model.EdgeInfo in project vertexium by visallo.

the class ElementMutationBuilder method saveEdgeInfoOnVertex.

private void saveEdgeInfoOnVertex(String edgeId, String outVertexId, String inVertexId, String edgeLabel, ColumnVisibility edgeColumnVisibility) {
    Text edgeIdText = new Text(edgeId);
    // Update out vertex.
    Mutation addEdgeToOutMutation = new Mutation(outVertexId);
    EdgeInfo edgeInfo = new EdgeInfo(getNameSubstitutionStrategy().deflate(edgeLabel), inVertexId);
    addEdgeToOutMutation.put(AccumuloVertex.CF_OUT_EDGE, edgeIdText, edgeColumnVisibility, edgeInfo.toValue());
    saveVertexMutation(addEdgeToOutMutation);
    // Update in vertex.
    Mutation addEdgeToInMutation = new Mutation(inVertexId);
    edgeInfo = new EdgeInfo(getNameSubstitutionStrategy().deflate(edgeLabel), outVertexId);
    addEdgeToInMutation.put(AccumuloVertex.CF_IN_EDGE, edgeIdText, edgeColumnVisibility, edgeInfo.toValue());
    saveVertexMutation(addEdgeToInMutation);
}
Also used : Text(org.apache.hadoop.io.Text) Mutation(org.apache.accumulo.core.data.Mutation) EdgeInfo(org.vertexium.accumulo.iterator.model.EdgeInfo)

Example 4 with EdgeInfo

use of org.vertexium.accumulo.iterator.model.EdgeInfo in project vertexium by visallo.

the class VertexIterator method removeHiddenAndSoftDeletes.

private void removeHiddenAndSoftDeletes() {
    if (!getFetchHints().isIncludeHidden()) {
        for (Text edgeId : this.getElementData().hiddenEdges) {
            this.getElementData().inEdges.remove(edgeId);
            this.getElementData().outEdges.remove(edgeId);
        }
    }
    for (SoftDeleteEdgeInfo inSoftDelete : this.getElementData().inSoftDeletes) {
        EdgeInfo inEdge = this.getElementData().inEdges.get(inSoftDelete.getEdgeId());
        if (inEdge != null && inSoftDelete.getTimestamp() >= inEdge.getTimestamp()) {
            this.getElementData().inEdges.remove(inSoftDelete.getEdgeId());
        }
    }
    for (SoftDeleteEdgeInfo outSoftDelete : this.getElementData().outSoftDeletes) {
        EdgeInfo outEdge = this.getElementData().outEdges.get(outSoftDelete.getEdgeId());
        if (outEdge != null && outSoftDelete.getTimestamp() >= outEdge.getTimestamp()) {
            this.getElementData().outEdges.remove(outSoftDelete.getEdgeId());
        }
    }
}
Also used : SoftDeleteEdgeInfo(org.vertexium.accumulo.iterator.model.SoftDeleteEdgeInfo) Text(org.apache.hadoop.io.Text) EdgeInfo(org.vertexium.accumulo.iterator.model.EdgeInfo) SoftDeleteEdgeInfo(org.vertexium.accumulo.iterator.model.SoftDeleteEdgeInfo)

Example 5 with EdgeInfo

use of org.vertexium.accumulo.iterator.model.EdgeInfo in project vertexium by visallo.

the class ConnectedVertexIdsIterator method rowEncoder.

@Override
public Value rowEncoder(List<Key> keys, List<Value> values) throws IOException {
    Map<Text, String> inVertexIds = new HashMap<>();
    Map<Text, String> outVertexIds = new HashMap<>();
    for (int i = 0; i < keys.size(); i++) {
        Key key = keys.get(i);
        Value value = values.get(i);
        if (key.getColumnFamily().equals(VertexIterator.CF_OUT_EDGE)) {
            EdgeInfo edgeInfo = new EdgeInfo(value.get(), key.getTimestamp());
            if (isMatch(edgeInfo)) {
                outVertexIds.put(key.getColumnQualifier(), edgeInfo.getVertexId());
            }
        } else if (key.getColumnFamily().equals(VertexIterator.CF_OUT_EDGE_HIDDEN) || key.getColumnFamily().equals(VertexIterator.CF_OUT_EDGE_SOFT_DELETE)) {
            outVertexIds.remove(key.getColumnQualifier());
        } else if (key.getColumnFamily().equals(VertexIterator.CF_IN_EDGE)) {
            EdgeInfo edgeInfo = new EdgeInfo(value.get(), key.getTimestamp());
            if (isMatch(edgeInfo)) {
                inVertexIds.put(key.getColumnQualifier(), edgeInfo.getVertexId());
            }
        } else if (key.getColumnFamily().equals(VertexIterator.CF_IN_EDGE_HIDDEN) || key.getColumnFamily().equals(VertexIterator.CF_IN_EDGE_SOFT_DELETE)) {
            inVertexIds.remove(key.getColumnQualifier());
        }
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(baos);
    Set<String> vertexIds = new HashSet<>();
    vertexIds.addAll(inVertexIds.values());
    vertexIds.addAll(outVertexIds.values());
    DataOutputStreamUtils.encodeSetOfStrings(out, vertexIds);
    return new Value(baos.toByteArray());
}
Also used : Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) Key(org.apache.accumulo.core.data.Key) EdgeInfo(org.vertexium.accumulo.iterator.model.EdgeInfo)

Aggregations

Text (org.apache.hadoop.io.Text)8 EdgeInfo (org.vertexium.accumulo.iterator.model.EdgeInfo)8 Key (org.apache.accumulo.core.data.Key)4 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)3 Value (org.apache.accumulo.core.data.Value)2 ArrayList (java.util.ArrayList)1 Mutation (org.apache.accumulo.core.data.Mutation)1 PartialKey (org.apache.accumulo.core.data.PartialKey)1 Span (org.apache.accumulo.core.trace.Span)1 Test (org.junit.Test)1 IteratorFetchHints (org.vertexium.accumulo.iterator.model.IteratorFetchHints)1 SoftDeleteEdgeInfo (org.vertexium.accumulo.iterator.model.SoftDeleteEdgeInfo)1 DataTableRowKey (org.vertexium.accumulo.keys.DataTableRowKey)1 StreamingPropertyValue (org.vertexium.property.StreamingPropertyValue)1 IndexHint (org.vertexium.search.IndexHint)1