use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.
the class DefaultSecretStore method get.
@Override
public <T> T get(String namespace, String name, Decoder<T> decoder) throws SecretNotFoundException, IOException {
return TransactionRunners.run(transactionRunner, context -> {
StructuredTable table = context.getTable(StoreDefinition.SecretStore.SECRET_STORE_TABLE);
List<Field<?>> keyFields = ImmutableList.<Field<?>>builder().addAll(getKeyFields(namespace, name)).build();
Optional<StructuredRow> optionalRow = table.read(keyFields);
if (!optionalRow.isPresent()) {
throw new SecretNotFoundException(namespace, name);
}
StructuredRow row = optionalRow.get();
return decoder.decode(row.getBytes(StoreDefinition.SecretStore.SECRET_DATA_FIELD));
}, SecretNotFoundException.class, IOException.class);
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.
the class ConnectionStore method listConnections.
/**
* Get all the connections in the given namespace
*
* @param namespace the namespace to look up
* @return the list of connections in this namespace
*/
public List<Connection> listConnections(NamespaceSummary namespace) {
return TransactionRunners.run(transactionRunner, context -> {
StructuredTable table = context.getTable(TABLE_ID);
Range range = Range.singleton(getNamespaceKeys(namespace));
List<Connection> connections = new ArrayList<>();
try (CloseableIterator<StructuredRow> rowIter = table.scan(range, Integer.MAX_VALUE)) {
rowIter.forEachRemaining(structuredRow -> connections.add(GSON.fromJson(structuredRow.getString(CONNECTION_DATA_FIELD), Connection.class)));
}
return connections;
});
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.
the class DatasetTypeTable method getTypes.
public Collection<DatasetTypeMeta> getTypes(NamespaceId namespaceId) throws IOException {
List<DatasetTypeMeta> types = Lists.newArrayList();
try (CloseableIterator<StructuredRow> iterator = getTypeTable().scan(Range.singleton(getModulePrefix(namespaceId.getEntityName())), Integer.MAX_VALUE)) {
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
String typeName = row.getString(StoreDefinition.DatasetTypeStore.TYPE_NAME_FIELD);
DatasetModuleId moduleId = GSON.fromJson(row.getString(StoreDefinition.DatasetTypeStore.DATASET_METADATA_FIELD), DatasetModuleId.class);
types.add(getTypeMeta(namespaceId, typeName, moduleId));
}
}
return types;
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.
the class FieldLineageTable method getChecksumsWithProgramRunsInRange.
private Map<Long, Set<ProgramRunId>> getChecksumsWithProgramRunsInRange(String direction, EndPoint endPoint, long start, long end) throws IOException {
// time is inverted, hence we need to pass end-time for getting start key
List<Field<?>> scanStartKey = getScanKey(direction, endPoint, end);
// time is inverted, hence we need to pass start-time for getting end key
List<Field<?>> scanEndKey = getScanKey(direction, endPoint, start);
Map<Long, Set<ProgramRunId>> result = new LinkedHashMap<>();
try (CloseableIterator<StructuredRow> iterator = getEndpointChecksumTable().scan(Range.create(scanStartKey, Range.Bound.INCLUSIVE, scanEndKey, Range.Bound.INCLUSIVE), Integer.MAX_VALUE)) {
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
long checksum = row.getLong(StoreDefinition.FieldLineageStore.CHECKSUM_FIELD);
ProgramRunId programRunId = GSON.fromJson(row.getString(StoreDefinition.FieldLineageStore.PROGRAM_RUN_FIELD), ProgramRunId.class);
Set<ProgramRunId> programRuns = result.computeIfAbsent(checksum, k -> new HashSet<>());
programRuns.add(programRunId);
}
}
return result;
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by caskdata.
the class FieldLineageTable method getOperations.
private Set<ProgramRunOperations> getOperations(String direction, EndPoint endPoint, long start, long end) throws IOException {
Map<Long, Set<ProgramRunId>> checksumsWithProgramRunsInRange = getChecksumsWithProgramRunsInRange(direction, endPoint, start, end);
Set<ProgramRunOperations> result = new LinkedHashSet<>();
for (Map.Entry<Long, Set<ProgramRunId>> entry : checksumsWithProgramRunsInRange.entrySet()) {
long checksum = entry.getKey();
List<Field<?>> keys = getOperationsKey(checksum);
Optional<StructuredRow> row = getOperationsTable().read(keys);
if (!row.isPresent()) {
continue;
}
String value = row.get().getString(StoreDefinition.FieldLineageStore.OPERATIONS_FIELD);
Set<Operation> operations;
try {
operations = GSON.fromJson(value, SET_OPERATION_TYPE);
} catch (JsonSyntaxException e) {
LOG.warn(String.format("Failed to parse json from checksum %d'. Ignoring operations.", checksum));
continue;
}
if (operations != null) {
result.add(new ProgramRunOperations(entry.getValue(), operations));
}
}
return result;
}
Aggregations