use of io.cdap.cdap.spi.data.StructuredRow in project cdap by cdapio.
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 cdapio.
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;
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by cdapio.
the class UsageTable method getDatasetsFromPrefix.
private Set<DatasetId> getDatasetsFromPrefix(List<Field<?>> prefix) throws IOException {
Set<DatasetId> datasets = new HashSet<>();
try (CloseableIterator<StructuredRow> iterator = table.scan(Range.singleton(prefix), Integer.MAX_VALUE)) {
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
datasets.add(GSON.fromJson(row.getString(StoreDefinition.UsageStore.DATASET_FIELD), DatasetKey.class).getDataset());
}
}
return datasets;
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by cdapio.
the class ConfigTable method list.
public List<Config> list(String namespace, String type) throws IOException {
List<Field<?>> scanStart = new ArrayList<>(2);
scanStart.add(Fields.stringField(StoreDefinition.ConfigStore.NAMESPACE_FIELD, namespace));
scanStart.add(Fields.stringField(StoreDefinition.ConfigStore.TYPE_FIELD, type));
Range range = Range.singleton(scanStart);
try (CloseableIterator<StructuredRow> iter = table.scan(range, Integer.MAX_VALUE)) {
List<Config> result = new ArrayList<>();
while (iter.hasNext()) {
StructuredRow row = iter.next();
result.add(fromRow(row));
}
return result;
}
}
use of io.cdap.cdap.spi.data.StructuredRow in project cdap by cdapio.
the class TetheringStore method getPeer.
/**
* Get information about a peer
*
* @return information about status of a peer
* @throws IOException if reading from the database fails
* @throws PeerNotFoundException if the peer is not found
*/
public PeerInfo getPeer(String peerName) throws IOException, PeerNotFoundException {
return TransactionRunners.run(transactionRunner, context -> {
StructuredTable tetheringTable = context.getTable(StoreDefinition.TetheringStore.TETHERING);
Optional<StructuredRow> row = getPeer(tetheringTable, peerName);
return getPeerInfo(row.get());
}, PeerNotFoundException.class, IOException.class);
}
Aggregations