use of org.vertexium.accumulo.iterator.model.PropertyColumnQualifier 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();
}
}
Aggregations