use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class MetadataDataset method writeValue.
private void writeValue(MetadataEntry entry) {
String key = entry.getKey();
MDSKey mdsValueKey = MetadataKey.createValueRowKey(entry.getMetadataEntity(), key);
Put put = new Put(mdsValueKey.getKey());
// add the metadata value
put.add(Bytes.toBytes(VALUE_COLUMN), Bytes.toBytes(entry.getValue()));
indexedTable.put(put);
}
use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class MetadataDataset method storeIndexes.
/**
* Store indexes for a {@link MetadataEntry}
* @param indexers {@link Set<String>} of {@link Indexer indexers} for this {@link MetadataEntry}
* @param metadataEntry {@link MetadataEntry} for which indexes are to be stored
*/
private void storeIndexes(MetadataEntry metadataEntry, Set<Indexer> indexers) {
// Delete existing indexes for metadataEntity-key
deleteIndexes(metadataEntry.getMetadataEntity(), metadataEntry.getKey());
String namespacePrefix = metadataEntry.getMetadataEntity().getValue(MetadataEntity.NAMESPACE) + MetadataConstants.KEYVALUE_SEPARATOR;
for (Indexer indexer : indexers) {
Set<String> indexes = indexer.getIndexes(metadataEntry);
IndexColumn indexColumn = getIndexColumn(metadataEntry.getKey(), indexer.getSortOrder());
for (String index : indexes) {
if (index.isEmpty()) {
continue;
}
// store one value for within namespace search and one for cross namespace search
String lowercaseIndex = index.toLowerCase();
MDSKey mdsIndexKey = MetadataKey.createIndexRowKey(metadataEntry.getMetadataEntity(), metadataEntry.getKey(), lowercaseIndex);
Put put = new Put(mdsIndexKey.getKey());
put.add(Bytes.toBytes(indexColumn.getCrossNamespaceColumn()), Bytes.toBytes(lowercaseIndex));
put.add(Bytes.toBytes(indexColumn.getColumn()), Bytes.toBytes(namespacePrefix + lowercaseIndex));
indexedTable.put(put);
}
}
}
use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class MetadataDataset method getMetadata.
/**
* Retrieves the metadata for the specified {@link MetadataEntity}.
*
* @param metadataEntity the specified {@link MetadataEntity}
* @return {@link Record} representing the metadata for the specified {@link MetadataEntity}
*/
public Record getMetadata(MetadataEntity metadataEntity) {
MDSKey mdsKey = MetadataKey.createValueRowKey(metadataEntity, null);
byte[] startKey = mdsKey.getKey();
byte[] stopKey = Bytes.stopKeyForPrefix(startKey);
Map<String, String> metadata = new HashMap<>();
try (Scanner scan = indexedTable.scan(startKey, stopKey)) {
Row next;
while ((next = scan.next()) != null) {
String key = MetadataKey.extractMetadataKey(next.getRow());
byte[] value = next.get(VALUE_COLUMN);
if (key == null || value == null) {
continue;
}
metadata.put(key, Bytes.toString(value));
}
}
Set<String> tags = splitTags(metadata.get(MetadataConstants.TAGS_KEY));
// safe to remove since splitTags above copies to new HashSet
// now we are only left with properties
metadata.remove(MetadataConstants.TAGS_KEY);
return new Record(metadataEntity, metadata, tags);
}
use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class MetadataDataset method getMetadata.
/**
* Return metadata based on target id, and key.
*
* @param metadataEntity The id of the target
* @param key The metadata key to get
* @return instance of {@link MetadataEntry} for the target type, id, and key
*/
@Nullable
private MetadataEntry getMetadata(MetadataEntity metadataEntity, String key) {
MDSKey mdsKey = MetadataKey.createValueRowKey(metadataEntity, key);
Row row = indexedTable.get(mdsKey.getKey());
if (row.isEmpty()) {
return null;
}
byte[] value = row.get(VALUE_COLUMN);
if (value == null) {
// This can happen when all tags are removed one by one. The row still exists, but the value is null.
return null;
}
return new MetadataEntry(metadataEntity, key, Bytes.toString(value));
}
use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class MetadataKey method extractTargetType.
static String extractTargetType(byte[] rowKey) {
MDSKey.Splitter keySplitter = new MDSKey(rowKey).split();
// skip rowPrefix
keySplitter.skipBytes();
// return targetType
return keySplitter.getString();
}
Aggregations