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;
}
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);
}
}
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();
}
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);
}
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();
}
Aggregations