Search in sources :

Example 26 with Transaction

use of org.apache.fluo.api.client.Transaction in project incubator-rya by apache.

the class DeleteFluoPcj method deletePcj.

/**
 * Deletes all metadata and {@link BindingSet}s associated with a Rya
 * Precomputed Join Index from the Fluo application that is incrementally
 * updating it.
 *
 * @param client - Connects to the Fluo application that is updating the PCJ
 *            Index. (not null)
 * @param pcjId - The PCJ ID for the query that will removed from the Fluo
 *            application. (not null)
 * @throws UnsupportedQueryException - thrown when Fluo app is unable to read FluoQuery associated
 * with given pcjId.
 */
public void deletePcj(final FluoClient client, final String pcjId) throws UnsupportedQueryException {
    requireNonNull(client);
    requireNonNull(pcjId);
    final Transaction tx = client.newTransaction();
    // Delete the query's metadata. This halts input.
    final List<String> nodeIds = getNodeIds(tx, pcjId);
    deleteMetadata(tx, nodeIds, pcjId);
    // Delete the binding sets associated with the query's nodes.
    for (final String nodeId : nodeIds) {
        deleteData(client, nodeId);
    }
}
Also used : Transaction(org.apache.fluo.api.client.Transaction)

Example 27 with Transaction

use of org.apache.fluo.api.client.Transaction in project incubator-rya by apache.

the class DeleteFluoPcj method deleteMetadata.

/**
 * Deletes metadata for all nodeIds associated with a given queryId in a
 * single transaction. Prevents additional BindingSets from being created as
 * new triples are added.
 *
 * @param tx - Transaction of a given Fluo table. (not null)
 * @param nodeIds - Nodes whose metatdata will be deleted. (not null)
 * @param pcjId - The PCJ ID of the query whose will be deleted. (not null)
 */
private void deleteMetadata(final Transaction tx, final List<String> nodeIds, final String pcjId) {
    requireNonNull(tx);
    requireNonNull(nodeIds);
    requireNonNull(pcjId);
    try (final Transaction typeTx = tx) {
        Set<String> spNodeIds = new HashSet<>();
        // remove metadata associated with each nodeId and store statement pattern nodeIds
        for (final String nodeId : nodeIds) {
            final NodeType type = NodeType.fromNodeId(nodeId).get();
            if (type == NodeType.STATEMENT_PATTERN) {
                spNodeIds.add(nodeId);
            }
            deleteMetadataColumns(typeTx, nodeId, type.getMetaDataColumns());
        }
        // Use stored statement pattern nodeIds to update list of stored statement pattern nodeIds
        // in Fluo table
        StatementPatternIdManager.removeStatementPatternIds(typeTx, spNodeIds);
        typeTx.commit();
    }
}
Also used : Transaction(org.apache.fluo.api.client.Transaction) NodeType(org.apache.rya.indexing.pcj.fluo.app.NodeType) HashSet(java.util.HashSet)

Example 28 with Transaction

use of org.apache.fluo.api.client.Transaction in project incubator-rya by apache.

the class InsertTriples method insert.

/**
 * Insert a batch of RyaStatements into Fluo.
 *
 * @param fluo - A connection to the Fluo table that will be updated. (not null)
 * @param triples - The triples to insert. (not null)
 */
public void insert(final FluoClient fluo, final Collection<RyaStatement> triples) {
    checkNotNull(fluo);
    checkNotNull(triples);
    try (Transaction tx = fluo.newTransaction()) {
        for (final RyaStatement triple : triples) {
            Optional<byte[]> visibility = Optional.fromNullable(triple.getColumnVisibility());
            try {
                tx.set(spoFormat(triple), FluoQueryColumns.TRIPLES, Bytes.of(visibility.or(new byte[0])));
            } catch (final TripleRowResolverException e) {
                log.error("Could not convert a Triple into the SPO format: " + triple);
            }
        }
        tx.commit();
    }
}
Also used : TripleRowResolverException(org.apache.rya.api.resolver.triple.TripleRowResolverException) Transaction(org.apache.fluo.api.client.Transaction) RyaStatement(org.apache.rya.api.domain.RyaStatement)

Aggregations

Transaction (org.apache.fluo.api.client.Transaction)28 Test (org.junit.Test)17 FluoClient (org.apache.fluo.api.client.FluoClient)15 Snapshot (org.apache.fluo.api.client.Snapshot)13 VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)11 NodeType (org.apache.rya.indexing.pcj.fluo.app.NodeType)5 Bytes (org.apache.fluo.api.data.Bytes)4 SpanBatchDeleteInformation (org.apache.rya.indexing.pcj.fluo.app.batch.SpanBatchDeleteInformation)3 HashSet (java.util.HashSet)2 Column (org.apache.fluo.api.data.Column)2 RyaStatement (org.apache.rya.api.domain.RyaStatement)2 AggregationElement (org.apache.rya.api.function.aggregation.AggregationElement)2 TripleRowResolverException (org.apache.rya.api.resolver.triple.TripleRowResolverException)2 FluoQueryMetadataDAO (org.apache.rya.indexing.pcj.fluo.app.query.FluoQueryMetadataDAO)2 ColumnScanner (org.apache.fluo.api.client.scanner.ColumnScanner)1 RowScanner (org.apache.fluo.api.client.scanner.RowScanner)1 ColumnValue (org.apache.fluo.api.data.ColumnValue)1 RyaURI (org.apache.rya.api.domain.RyaURI)1 FluoQueryStringBuilder (org.apache.rya.indexing.pcj.fluo.api.ListFluoQueries.FluoQueryStringBuilder)1 BindingSetRow (org.apache.rya.indexing.pcj.fluo.app.BindingSetRow)1