Search in sources :

Example 21 with StructuredRow

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

Example 22 with StructuredRow

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

Example 23 with StructuredRow

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

Example 24 with StructuredRow

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;
}
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 25 with StructuredRow

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

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