Search in sources :

Example 21 with MDSKey

use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.

the class MetadataDataset method write.

private void write(NamespacedEntityId targetId, MetadataEntry entry, Set<Indexer> indexers) {
    String key = entry.getKey();
    MDSKey mdsValueKey = MdsKey.getMDSValueKey(targetId, key);
    Put put = new Put(mdsValueKey.getKey());
    // add the metadata value
    put.add(Bytes.toBytes(VALUE_COLUMN), Bytes.toBytes(entry.getValue()));
    indexedTable.put(put);
    storeIndexes(targetId, key, indexers, entry);
    writeHistory(targetId);
}
Also used : MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey) Put(co.cask.cdap.api.dataset.table.Put)

Example 22 with MDSKey

use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.

the class MetadataDataset method getIndexPut.

/**
 * Creates a {@link Put} for the a metadata index
 *
 * @param targetId the {@link NamespacedEntityId} from which the metadata index has to be created
 * @param metadataKey the key of the metadata entry
 * @param index the index for this metadata
 * @param indexColumn the column to store the index in. This column should exist in the
 * {@link IndexedTable#INDEX_COLUMNS_CONF_KEY} property in the dataset's definition
 * @return {@link Put} which is a index row with the value to be indexed in the #indexColumn
 */
private Put getIndexPut(NamespacedEntityId targetId, String metadataKey, String index, String indexColumn) {
    MDSKey mdsIndexKey = MdsKey.getMDSIndexKey(targetId, metadataKey, index.toLowerCase());
    String namespacedIndex = targetId.getNamespace() + KEYVALUE_SEPARATOR + index.toLowerCase();
    Put put = new Put(mdsIndexKey.getKey());
    put.add(Bytes.toBytes(indexColumn), Bytes.toBytes(namespacedIndex));
    return put;
}
Also used : MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey) Put(co.cask.cdap.api.dataset.table.Put)

Example 23 with MDSKey

use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.

the class LineageDataset method parseRow.

private RowKey parseRow(Row row) {
    ProgramId program;
    NamespacedEntityId data;
    RunId runId;
    MDSKey.Splitter splitter = new MDSKey(row.getRow()).split();
    char marker = (char) splitter.getInt();
    LOG.trace("Got marker {}", marker);
    switch(marker) {
        case PROGRAM_MARKER:
            program = (ProgramId) toEntityId(splitter, marker);
            // inverted start time
            splitter.skipLong();
            marker = (char) splitter.getInt();
            // data
            data = toEntityId(splitter, marker);
            runId = RunIds.fromString(splitter.getString());
            return new RowKey(program, data, runId);
        case DATASET_MARKER:
        case STREAM_MARKER:
            data = toEntityId(splitter, marker);
            // inverted start time
            splitter.skipLong();
            marker = (char) splitter.getInt();
            // program
            program = (ProgramId) toEntityId(splitter, marker);
            runId = RunIds.fromString(splitter.getString());
            return new RowKey(program, data, runId);
        default:
            throw new IllegalStateException("Invalid row with marker " + marker);
    }
}
Also used : NamespacedEntityId(co.cask.cdap.proto.id.NamespacedEntityId) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey) ProgramId(co.cask.cdap.proto.id.ProgramId) RunId(org.apache.twill.api.RunId) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId)

Example 24 with MDSKey

use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.

the class OrderedPair method getSecond.

public Set<SECOND> getSecond(Set<MDSKey> mdsKeys) {
    Set<SECOND> secondSet = Sets.newHashSetWithExpectedSize(mdsKeys.size());
    for (MDSKey mdsKey : mdsKeys) {
        MDSKey.Splitter splitter = mdsKey.split();
        // prefix
        splitter.skipString();
        keyMaker1.skipKey(splitter);
        secondSet.add(this.keyMaker2.getElement(splitter));
    }
    return secondSet;
}
Also used : MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey)

Example 25 with MDSKey

use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.

the class AppMetadataStore method getUnfinishedRun.

/**
 * @return run records for runs that do not have start time in mds key for the run record.
 */
private RunRecordMeta getUnfinishedRun(ProgramId programId, String recordType, String runid) {
    MDSKey runningKey = getProgramKeyBuilder(recordType, programId).add(runid).build();
    RunRecordMeta runRecordMeta = get(runningKey, RunRecordMeta.class);
    if (runRecordMeta == null && programId.getVersion().equals(ApplicationId.DEFAULT_VERSION)) {
        runningKey = getVersionLessProgramKeyBuilder(recordType, programId).add(runid).build();
        return get(runningKey, RunRecordMeta.class);
    }
    return runRecordMeta;
}
Also used : RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey)

Aggregations

MDSKey (co.cask.cdap.data2.dataset2.lib.table.MDSKey)66 MDSKey (io.cdap.cdap.data2.dataset2.lib.table.MDSKey)31 GsonBuilder (com.google.gson.GsonBuilder)22 IOException (java.io.IOException)16 Gson (com.google.gson.Gson)14 HashMap (java.util.HashMap)12 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)11 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)9 Row (co.cask.cdap.api.dataset.table.Row)8 ProgramId (co.cask.cdap.proto.id.ProgramId)8 Nullable (javax.annotation.Nullable)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 Test (org.junit.Test)7 Scanner (co.cask.cdap.api.dataset.table.Scanner)6 MetadataStoreDataset (co.cask.cdap.data2.dataset2.lib.table.MetadataStoreDataset)6 ArrayList (java.util.ArrayList)6 WorkflowNodeStateDetail (co.cask.cdap.proto.WorkflowNodeStateDetail)5 ApplicationId (co.cask.cdap.proto.id.ApplicationId)5 Row (io.cdap.cdap.api.dataset.table.Row)5 Scanner (io.cdap.cdap.api.dataset.table.Scanner)5