use of io.cdap.cdap.data2.metadata.dataset.MetadataDataset in project cdap by caskdata.
the class DatasetMetadataStorage method removeInScope.
private MetadataDataset.Change removeInScope(MetadataDatasetContext context, MetadataScope scope, MetadataEntity entity, Set<String> tagsToRemove, Set<String> propertiesToRemove) {
MetadataDataset dataset = context.getDataset(scope);
MetadataDataset.Record before = null;
MetadataDataset.Record after = null;
if (tagsToRemove.isEmpty() && propertiesToRemove.isEmpty()) {
before = dataset.getMetadata(entity);
after = before;
} else {
if (!tagsToRemove.isEmpty()) {
MetadataDataset.Change change = dataset.removeTags(entity, tagsToRemove);
before = change.getExisting();
after = change.getLatest();
}
if (!propertiesToRemove.isEmpty()) {
MetadataDataset.Change change = dataset.removeProperties(entity, propertiesToRemove);
before = before != null ? before : change.getExisting();
after = change.getLatest();
}
}
return new MetadataDataset.Change(before, after);
}
use of io.cdap.cdap.data2.metadata.dataset.MetadataDataset in project cdap by cdapio.
the class DatasetMetadataStorage method readScope.
private MetadataDataset.Record readScope(MetadataDatasetContext context, MetadataScope scope, Read read) {
MetadataEntity entity = read.getEntity();
if (read.getSelection() == null && (!read.getScopes().contains(scope) || read.getKinds().isEmpty())) {
return new MetadataDataset.Record(entity);
}
Set<ScopedNameOfKind> selectionForScope = null;
if (read.getSelection() != null) {
// noinspection ConstantConditions
selectionForScope = Sets.filter(read.getSelection(), entry -> entry.getScope() == scope);
if (selectionForScope.isEmpty()) {
return new MetadataDataset.Record(entity);
}
}
// now we know we must read from the dataset
MetadataDataset dataset = context.getDataset(scope);
if (selectionForScope != null) {
// request is for a specific set of tags and properties
Set<String> tagsToRead = selectionForScope.stream().filter(entry -> TAG == entry.getKind()).map(ScopedName::getName).collect(Collectors.toSet());
Set<String> propertiesToRead = selectionForScope.stream().filter(entry -> PROPERTY == entry.getKind()).map(ScopedName::getName).collect(Collectors.toSet());
Set<String> tags = tagsToRead.isEmpty() ? Collections.emptySet() : Sets.intersection(tagsToRead, dataset.getTags(entity));
Map<String, String> properties = propertiesToRead.isEmpty() ? Collections.emptyMap() : Maps.filterKeys(dataset.getProperties(entity), propertiesToRead::contains);
return new MetadataDataset.Record(entity, properties, tags);
}
if (MetadataKind.ALL.equals(read.getKinds())) {
// all metadata kinds requested
return dataset.getMetadata(entity);
}
// exactly one kind is requested
MetadataKind requestKind = read.getKinds().iterator().next();
if (requestKind == TAG) {
return new MetadataDataset.Record(entity, Collections.emptyMap(), dataset.getTags(entity));
}
if (requestKind == PROPERTY) {
return new MetadataDataset.Record(entity, dataset.getProperties(entity), Collections.emptySet());
}
throw new IllegalStateException("Encountered metadata read request for unknown kind " + requestKind);
}
Aggregations