Search in sources :

Example 1 with StreamingPropertyValueRef

use of org.vertexium.property.StreamingPropertyValueRef in project vertexium by visallo.

the class AccumuloGraph method getHistoricalPropertyValues.

public Iterable<HistoricalPropertyValue> getHistoricalPropertyValues(Element element, String key, String name, Visibility visibility, Long startTime, Long endTime, Authorizations authorizations) {
    Span trace = Trace.start("getHistoricalPropertyValues");
    if (Trace.isTracing()) {
        trace.data("key", key);
        trace.data("name", name);
        trace.data("visibility", visibility.getVisibilityString());
        if (startTime != null) {
            trace.data("startTime", Long.toString(startTime));
        }
        if (endTime != null) {
            trace.data("endTime", Long.toString(endTime));
        }
    }
    try {
        ElementType elementType = ElementType.getTypeFromElement(element);
        FetchHints fetchHints = FetchHints.PROPERTIES_AND_METADATA;
        traceDataFetchHints(trace, fetchHints);
        org.apache.accumulo.core.data.Range range = RangeUtils.createRangeFromString(element.getId());
        final ScannerBase scanner = createElementScanner(fetchHints, elementType, ALL_VERSIONS, startTime, endTime, Lists.newArrayList(range), false, authorizations);
        try {
            Map<String, HistoricalPropertyValue> results = new HashMap<>();
            ArrayListMultimap<String, String> activeVisibilities = ArrayListMultimap.create();
            Map<String, Key> softDeleteObserved = Maps.newHashMap();
            for (Map.Entry<Key, Value> column : scanner) {
                String cq = column.getKey().getColumnQualifier().toString();
                String columnVisibility = column.getKey().getColumnVisibility().toString();
                if (column.getKey().getColumnFamily().equals(AccumuloElement.CF_PROPERTY)) {
                    if (visibility != null && !columnVisibility.equals(visibility.getVisibilityString())) {
                        continue;
                    }
                    PropertyColumnQualifier propertyColumnQualifier = KeyHelper.createPropertyColumnQualifier(cq, getNameSubstitutionStrategy());
                    if (name != null && !propertyColumnQualifier.getPropertyName().equals(name)) {
                        continue;
                    }
                    if (key != null && !propertyColumnQualifier.getPropertyKey().equals(key)) {
                        continue;
                    }
                    String resultsKey = propertyColumnQualifier.getDiscriminator(columnVisibility, column.getKey().getTimestamp());
                    long timestamp = column.getKey().getTimestamp();
                    Object value = vertexiumSerializer.bytesToObject(column.getValue().get());
                    Metadata metadata = new Metadata();
                    // TODO should we preserve these over time
                    Set<Visibility> hiddenVisibilities = null;
                    if (value instanceof StreamingPropertyValueRef) {
                        // noinspection unchecked
                        value = ((StreamingPropertyValueRef) value).toStreamingPropertyValue(this, timestamp);
                    }
                    String propertyKey = propertyColumnQualifier.getPropertyKey();
                    String propertyName = propertyColumnQualifier.getPropertyName();
                    Visibility propertyVisibility = accumuloVisibilityToVisibility(columnVisibility);
                    HistoricalPropertyValue hpv = new HistoricalPropertyValueBuilder(propertyKey, propertyName, timestamp).propertyVisibility(propertyVisibility).value(value).metadata(metadata).hiddenVisibilities(hiddenVisibilities).build();
                    String propIdent = propertyKey + ":" + propertyName;
                    activeVisibilities.put(propIdent, columnVisibility);
                    results.put(resultsKey, hpv);
                } else if (column.getKey().getColumnFamily().equals(AccumuloElement.CF_PROPERTY_SOFT_DELETE)) {
                    PropertyColumnQualifier propertyColumnQualifier = KeyHelper.createPropertyColumnQualifier(cq, getNameSubstitutionStrategy());
                    String propertyKey = propertyColumnQualifier.getPropertyKey();
                    String propertyName = propertyColumnQualifier.getPropertyName();
                    String propIdent = propertyKey + ":" + propertyName;
                    activeVisibilities.remove(propIdent, columnVisibility);
                    softDeleteObserved.put(propIdent, column.getKey());
                } else if (column.getKey().getColumnFamily().equals(AccumuloElement.CF_PROPERTY_METADATA)) {
                    PropertyMetadataColumnQualifier propertyMetadataColumnQualifier = KeyHelper.createPropertyMetadataColumnQualifier(cq, getNameSubstitutionStrategy());
                    String resultsKey = propertyMetadataColumnQualifier.getPropertyDiscriminator(column.getKey().getTimestamp());
                    HistoricalPropertyValue hpv = results.get(resultsKey);
                    if (hpv == null) {
                        continue;
                    }
                    Object value = vertexiumSerializer.bytesToObject(column.getValue().get());
                    Visibility metadataVisibility = accumuloVisibilityToVisibility(columnVisibility);
                    hpv.getMetadata().add(propertyMetadataColumnQualifier.getMetadataKey(), value, metadataVisibility);
                }
            }
            for (Key entry : softDeleteObserved.values()) {
                String cq = entry.getColumnQualifier().toString();
                PropertyColumnQualifier propertyColumnQualifier = KeyHelper.createPropertyColumnQualifier(cq, getNameSubstitutionStrategy());
                String propertyKey = propertyColumnQualifier.getPropertyKey();
                String propertyName = propertyColumnQualifier.getPropertyName();
                String propIdent = propertyKey + ":" + propertyName;
                List<String> active = activeVisibilities.get(propIdent);
                if (active == null || active.isEmpty()) {
                    long timestamp = entry.getTimestamp() + 1;
                    String columnVisibility = entry.getColumnVisibility().toString();
                    Visibility propertyVisibility = accumuloVisibilityToVisibility(columnVisibility);
                    HistoricalPropertyValue hpv = new HistoricalPropertyValueBuilder(propertyKey, propertyName, timestamp).propertyVisibility(propertyVisibility).isDeleted(true).build();
                    String resultsKey = propertyColumnQualifier.getDiscriminator(columnVisibility, timestamp);
                    results.put(resultsKey, hpv);
                }
            }
            return new TreeSet<>(results.values());
        } finally {
            scanner.close();
        }
    } finally {
        trace.stop();
    }
}
Also used : Span(org.apache.accumulo.core.trace.Span) IteratorFetchHints(org.vertexium.accumulo.iterator.model.IteratorFetchHints) PropertyMetadataColumnQualifier(org.vertexium.accumulo.iterator.model.PropertyMetadataColumnQualifier) StreamingPropertyValueRef(org.vertexium.property.StreamingPropertyValueRef) PropertyColumnQualifier(org.vertexium.accumulo.iterator.model.PropertyColumnQualifier) HistoricalPropertyValueBuilder(org.vertexium.HistoricalPropertyValue.HistoricalPropertyValueBuilder) Value(org.apache.accumulo.core.data.Value) StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Aggregations

Key (org.apache.accumulo.core.data.Key)1 PartialKey (org.apache.accumulo.core.data.PartialKey)1 Value (org.apache.accumulo.core.data.Value)1 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)1 Span (org.apache.accumulo.core.trace.Span)1 HistoricalPropertyValueBuilder (org.vertexium.HistoricalPropertyValue.HistoricalPropertyValueBuilder)1 IteratorFetchHints (org.vertexium.accumulo.iterator.model.IteratorFetchHints)1 PropertyColumnQualifier (org.vertexium.accumulo.iterator.model.PropertyColumnQualifier)1 PropertyMetadataColumnQualifier (org.vertexium.accumulo.iterator.model.PropertyMetadataColumnQualifier)1 StreamingPropertyValue (org.vertexium.property.StreamingPropertyValue)1 StreamingPropertyValueRef (org.vertexium.property.StreamingPropertyValueRef)1