Search in sources :

Example 26 with MDSKey

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

the class AppMetadataStore method getCompletedRun.

private RunRecordMeta getCompletedRun(ProgramId programId, final String runid) {
    MDSKey completedKey = getProgramKeyBuilder(TYPE_RUN_RECORD_COMPLETED, programId).build();
    RunRecordMeta runRecordMeta = getCompletedRun(completedKey, runid);
    if (runRecordMeta == null && programId.getVersion().equals(ApplicationId.DEFAULT_VERSION)) {
        completedKey = getVersionLessProgramKeyBuilder(TYPE_RUN_RECORD_COMPLETED, programId).build();
        return getCompletedRun(completedKey, runid);
    }
    return runRecordMeta;
}
Also used : RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey)

Example 27 with MDSKey

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

the class AppMetadataStore method getCompletedRun.

private RunRecordMeta getCompletedRun(MDSKey completedKey, final String runid) {
    // Get start time from RunId
    long programStartSecs = RunIds.getTime(RunIds.fromString(runid), TimeUnit.SECONDS);
    if (programStartSecs > -1) {
        // If start time is found, run a get
        MDSKey key = new MDSKey.Builder(completedKey).add(getInvertedTsKeyPart(programStartSecs)).add(runid).build();
        return get(key, RunRecordMeta.class);
    } else {
        // If start time is not found, scan the table (backwards compatibility when run ids were random UUIDs)
        MDSKey startKey = new MDSKey.Builder(completedKey).add(getInvertedTsScanKeyPart(Long.MAX_VALUE)).build();
        MDSKey stopKey = new MDSKey.Builder(completedKey).add(getInvertedTsScanKeyPart(0)).build();
        List<RunRecordMeta> runRecords = list(// Should have only one record for this runid
        startKey, // Should have only one record for this runid
        stopKey, // Should have only one record for this runid
        RunRecordMeta.class, // Should have only one record for this runid
        1, input -> input.getPid().equals(runid));
        return Iterables.getFirst(runRecords, null);
    }
}
Also used : RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey)

Example 28 with MDSKey

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

the class DefaultOwnerStore method createRowKey.

private static byte[] createRowKey(NamespacedEntityId targetId) {
    String targetType = EntityIdKeyHelper.getTargetType(targetId);
    MDSKey.Builder builder = new MDSKey.Builder();
    builder.add(OWNER_PREFIX);
    builder.add(targetType);
    EntityIdKeyHelper.addTargetIdToKey(builder, targetId);
    MDSKey build = builder.build();
    return build.getKey();
}
Also used : MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey)

Example 29 with MDSKey

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

the class MDSViewStore method delete.

@Override
public void delete(final StreamViewId viewId) throws NotFoundException {
    Transactionals.execute(transactional, context -> {
        ViewMetadataStoreDataset mds = getViewDataset(context);
        MDSKey key = getKey(viewId);
        if (!mds.exists(key)) {
            throw new NotFoundException(viewId);
        }
        mds.deleteAll(key);
    }, NotFoundException.class);
}
Also used : MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey) NotFoundException(co.cask.cdap.common.NotFoundException)

Example 30 with MDSKey

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

the class NoSqlStructuredRow method extractKeys.

private Map<String, Object> extractKeys() {
    ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
    MDSKey.Splitter splitter = new MDSKey(row.getRow()).split();
    // extract the first part since we always have the table name as the prefix
    splitter.getString();
    for (String key : tableSchema.getPrimaryKeys()) {
        // the NullPointerException should never be thrown since the primary keys must always have a type
        FieldType.Type type = tableSchema.getType(key);
        switch(Objects.requireNonNull(type)) {
            case INTEGER:
                int intVal = splitter.getInt();
                builder.put(key, intVal);
                keys.add(Fields.intField(key, intVal));
                break;
            case LONG:
                long longVal = splitter.getLong();
                builder.put(key, longVal);
                keys.add(Fields.longField(key, longVal));
                break;
            case STRING:
                String stringVal = splitter.getString();
                keys.add(Fields.stringField(key, stringVal));
                builder.put(key, stringVal);
                break;
            case BYTES:
                byte[] bytesVal = splitter.getBytes();
                keys.add(Fields.bytesField(key, bytesVal));
                builder.put(key, bytesVal);
                break;
            default:
                // this should never happen since all the keys are from the table schema and should never contain other types
                throw new IllegalStateException(String.format("The type %s of the primary key %s is not a valid key type", type, key));
        }
    }
    return builder.build();
}
Also used : MDSKey(io.cdap.cdap.data2.dataset2.lib.table.MDSKey) ImmutableMap(com.google.common.collect.ImmutableMap) FieldType(io.cdap.cdap.spi.data.table.field.FieldType)

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