Search in sources :

Example 71 with StructuredRow

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;
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) LinkedHashMap(java.util.LinkedHashMap)

Example 72 with StructuredRow

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ProgramRunOperations(io.cdap.cdap.proto.metadata.lineage.ProgramRunOperations) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) ReadOperation(io.cdap.cdap.api.lineage.field.ReadOperation) Operation(io.cdap.cdap.api.lineage.field.Operation) WriteOperation(io.cdap.cdap.api.lineage.field.WriteOperation) Field(io.cdap.cdap.spi.data.table.field.Field) JsonSyntaxException(com.google.gson.JsonSyntaxException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 73 with StructuredRow

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;
}
Also used : StructuredRow(io.cdap.cdap.spi.data.StructuredRow) DatasetId(io.cdap.cdap.proto.id.DatasetId) HashSet(java.util.HashSet)

Example 74 with StructuredRow

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;
    }
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) ArrayList(java.util.ArrayList) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) Range(io.cdap.cdap.spi.data.table.field.Range)

Example 75 with StructuredRow

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);
}
Also used : StructuredTable(io.cdap.cdap.spi.data.StructuredTable) StructuredRow(io.cdap.cdap.spi.data.StructuredRow)

Aggregations

StructuredRow (io.cdap.cdap.spi.data.StructuredRow)142 StructuredTable (io.cdap.cdap.spi.data.StructuredTable)68 Field (io.cdap.cdap.spi.data.table.field.Field)66 ArrayList (java.util.ArrayList)54 Range (io.cdap.cdap.spi.data.table.field.Range)36 HashSet (java.util.HashSet)28 IOException (java.io.IOException)22 HashMap (java.util.HashMap)22 LinkedHashSet (java.util.LinkedHashSet)22 List (java.util.List)20 LinkedHashMap (java.util.LinkedHashMap)18 Map (java.util.Map)18 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)16 Collection (java.util.Collection)16 Set (java.util.Set)16 Nullable (javax.annotation.Nullable)16 ImmutableList (com.google.common.collect.ImmutableList)14 CloseableIterator (io.cdap.cdap.api.dataset.lib.CloseableIterator)14 TableNotFoundException (io.cdap.cdap.spi.data.TableNotFoundException)14 Fields (io.cdap.cdap.spi.data.table.field.Fields)14