Search in sources :

Example 6 with Column

use of org.apache.fluo.api.data.Column in project incubator-rya by apache.

the class DeleteFluoPcj method deleteMetadataColumns.

/**
 * Deletes all metadata for a Query Node.
 *
 * @param tx - Transaction the deletes will be performed with. (not null)
 * @param nodeId - The Node ID of the query node to delete. (not null)
 * @param columns - The columns that will be deleted. (not null)
 */
private void deleteMetadataColumns(final Transaction tx, final String nodeId, final List<Column> columns) {
    requireNonNull(tx);
    requireNonNull(columns);
    requireNonNull(nodeId);
    final Bytes row = Bytes.of(nodeId);
    for (final Column column : columns) {
        tx.delete(row, column);
    }
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) Column(org.apache.fluo.api.data.Column)

Example 7 with Column

use of org.apache.fluo.api.data.Column in project incubator-rya by apache.

the class JoinResultUpdater method updateJoinResults.

/**
 * Updates the results of a Join node when one of its children has added a
 * new Binding Set to its results.
 *
 * @param tx - The transaction all Fluo queries will use. (not null)
 * @param childNodeId - The Node ID of the child whose results received a new Binding Set. (not null)
 * @param childBindingSet - The Binding Set that was just emitted by child node. (not null)
 * @param joinMetadata - The metadata for the Join that has been notified. (not null)
 * @throws Exception The update could not be successfully performed.
 */
public void updateJoinResults(final TransactionBase tx, final String childNodeId, final VisibilityBindingSet childBindingSet, final JoinMetadata joinMetadata) throws Exception {
    checkNotNull(tx);
    checkNotNull(childNodeId);
    checkNotNull(childBindingSet);
    checkNotNull(joinMetadata);
    log.trace("Transaction ID: " + tx.getStartTimestamp() + "\n" + "Join Node ID: " + joinMetadata.getNodeId() + "\n" + "Child Node ID: " + childNodeId + "\n" + "Child Binding Set:\n" + childBindingSet + "\n");
    // Figure out which join algorithm we are going to use.
    final IterativeJoin joinAlgorithm;
    switch(joinMetadata.getJoinType()) {
        case NATURAL_JOIN:
            joinAlgorithm = new NaturalJoin();
            break;
        case LEFT_OUTER_JOIN:
            joinAlgorithm = new LeftOuterJoin();
            break;
        default:
            throw new RuntimeException("Unsupported JoinType: " + joinMetadata.getJoinType());
    }
    // Figure out which side of the join the new binding set appeared on.
    final Side emittingSide;
    final String siblingId;
    if (childNodeId.equals(joinMetadata.getLeftChildNodeId())) {
        emittingSide = Side.LEFT;
        siblingId = joinMetadata.getRightChildNodeId();
    } else {
        emittingSide = Side.RIGHT;
        siblingId = joinMetadata.getLeftChildNodeId();
    }
    // Iterates over the sibling node's BindingSets that join with the new binding set.
    final Set<VisibilityBindingSet> siblingBindingSets = new HashSet<>();
    final Span siblingSpan = getSpan(tx, childNodeId, childBindingSet, siblingId);
    final Column siblingColumn = getScanColumnFamily(siblingId);
    final Optional<RowColumn> rowColumn = fillSiblingBatch(tx, siblingSpan, siblingColumn, siblingBindingSets, joinMetadata.getJoinBatchSize());
    // Iterates over the resulting BindingSets from the join.
    final Iterator<VisibilityBindingSet> newJoinResults;
    if (emittingSide == Side.LEFT) {
        newJoinResults = joinAlgorithm.newLeftResult(childBindingSet, siblingBindingSets.iterator());
    } else {
        newJoinResults = joinAlgorithm.newRightResult(siblingBindingSets.iterator(), childBindingSet);
    }
    // Insert the new join binding sets to the Fluo table.
    final VariableOrder joinVarOrder = joinMetadata.getVariableOrder();
    while (newJoinResults.hasNext()) {
        final VisibilityBindingSet newJoinResult = newJoinResults.next();
        // Create the Row Key for the emitted binding set. It does not contain visibilities.
        final Bytes resultRow = makeRowKey(joinMetadata.getNodeId(), joinVarOrder, newJoinResult);
        // Only insert the join Binding Set if it is new or BindingSet contains values not used in resultRow.
        if (tx.get(resultRow, FluoQueryColumns.JOIN_BINDING_SET) == null || joinVarOrder.getVariableOrders().size() < newJoinResult.size()) {
            // Create the Node Value. It does contain visibilities.
            final Bytes nodeValueBytes = BS_SERDE.serialize(newJoinResult);
            log.trace("Transaction ID: " + tx.getStartTimestamp() + "\n" + "New Join Result:\n" + newJoinResult + "\n");
            tx.set(resultRow, FluoQueryColumns.JOIN_BINDING_SET, nodeValueBytes);
        }
    }
    // update the span and register updated batch job
    if (rowColumn.isPresent()) {
        final Span newSpan = AbstractBatchBindingSetUpdater.getNewSpan(rowColumn.get(), siblingSpan);
        final JoinBatchInformation joinBatch = JoinBatchInformation.builder().setBatchSize(joinMetadata.getJoinBatchSize()).setBs(childBindingSet).setColumn(siblingColumn).setJoinType(joinMetadata.getJoinType()).setSide(emittingSide).setSpan(newSpan).setTask(Task.Add).build();
        BatchInformationDAO.addBatch(tx, joinMetadata.getNodeId(), joinBatch);
    }
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) RowColumn(org.apache.fluo.api.data.RowColumn) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) IterativeJoin(org.apache.rya.api.function.join.IterativeJoin) JoinBatchInformation(org.apache.rya.indexing.pcj.fluo.app.batch.JoinBatchInformation) Span(org.apache.fluo.api.data.Span) Side(org.apache.rya.api.function.join.LazyJoiningIterator.Side) Bytes(org.apache.fluo.api.data.Bytes) RowColumn(org.apache.fluo.api.data.RowColumn) Column(org.apache.fluo.api.data.Column) NaturalJoin(org.apache.rya.api.function.join.NaturalJoin) LeftOuterJoin(org.apache.rya.api.function.join.LeftOuterJoin) HashSet(java.util.HashSet)

Example 8 with Column

use of org.apache.fluo.api.data.Column in project incubator-rya by apache.

the class FluoQueryMetadataDAO method readAggregationMetadataBuilder.

private AggregationMetadata.Builder readAggregationMetadataBuilder(final SnapshotBase sx, final String nodeId) {
    requireNonNull(sx);
    requireNonNull(nodeId);
    // Fetch the values from the Fluo table.
    final String rowId = nodeId;
    final Map<Column, String> values = sx.gets(rowId, FluoQueryColumns.AGGREGATION_VARIABLE_ORDER, FluoQueryColumns.AGGREGATION_PARENT_NODE_ID, FluoQueryColumns.AGGREGATION_CHILD_NODE_ID, FluoQueryColumns.AGGREGATION_GROUP_BY_BINDING_NAMES);
    // Return an object holding them.
    final String varOrderString = values.get(FluoQueryColumns.AGGREGATION_VARIABLE_ORDER);
    final VariableOrder varOrder = new VariableOrder(varOrderString);
    final String parentNodeId = values.get(FluoQueryColumns.AGGREGATION_PARENT_NODE_ID);
    final String childNodeId = values.get(FluoQueryColumns.AGGREGATION_CHILD_NODE_ID);
    // Read the Group By variable order if one was present.
    final String groupByString = values.get(FluoQueryColumns.AGGREGATION_GROUP_BY_BINDING_NAMES);
    final VariableOrder groupByVars = groupByString.isEmpty() ? new VariableOrder() : new VariableOrder(groupByString.split(";"));
    // Deserialize the collection of AggregationElements.
    final Bytes aggBytes = sx.get(Bytes.of(nodeId.getBytes(Charsets.UTF_8)), FluoQueryColumns.AGGREGATION_AGGREGATIONS);
    final Collection<AggregationElement> aggregations;
    try (final ValidatingObjectInputStream vois = new ValidatingObjectInputStream(aggBytes.toInputStream())) // // this is how you find classes that you missed in the vois.accept() list, below.
    // { @Override protected void invalidClassNameFound(String className) throws java.io.InvalidClassException {
    // System.out.println("vois.accept(" + className + ".class, ");};};
    {
        // These classes are allowed to be deserialized. Others throw InvalidClassException.
        vois.accept(java.util.ArrayList.class, java.lang.Enum.class, AggregationElement.class, AggregationType.class);
        final Object object = vois.readObject();
        if (!(object instanceof Collection<?>)) {
            throw new InvalidClassException("Object read was not of type Collection. It was: " + object.getClass());
        }
        aggregations = (Collection<AggregationElement>) object;
    } catch (final IOException | ClassNotFoundException e) {
        throw new RuntimeException("Problem encountered while reading AggregationMetadata from the Fluo table. Unable " + "to deserialize the AggregationElements from a byte[].", e);
    }
    final AggregationMetadata.Builder builder = AggregationMetadata.builder(nodeId).setVarOrder(varOrder).setParentNodeId(parentNodeId).setChildNodeId(childNodeId).setGroupByVariableOrder(groupByVars);
    for (final AggregationElement aggregation : aggregations) {
        builder.addAggregation(aggregation);
    }
    return builder;
}
Also used : AggregationElement(org.apache.rya.api.function.aggregation.AggregationElement) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) InvalidClassException(java.io.InvalidClassException) ValidatingObjectInputStream(org.apache.commons.io.serialization.ValidatingObjectInputStream) IOException(java.io.IOException) Bytes(org.apache.fluo.api.data.Bytes) Column(org.apache.fluo.api.data.Column) Collection(java.util.Collection)

Example 9 with Column

use of org.apache.fluo.api.data.Column in project incubator-rya by apache.

the class FluoQueryMetadataDAO method readQueryMetadataBuilder.

private QueryMetadata.Builder readQueryMetadataBuilder(final SnapshotBase sx, final String nodeId) {
    requireNonNull(sx);
    requireNonNull(nodeId);
    // Fetch the values from the Fluo table.
    final String rowId = nodeId;
    final Map<Column, String> values = sx.gets(rowId, FluoQueryColumns.QUERY_VARIABLE_ORDER, FluoQueryColumns.QUERY_SPARQL, FluoQueryColumns.QUERY_TYPE, FluoQueryColumns.QUERY_EXPORT_STRATEGIES, FluoQueryColumns.QUERY_CHILD_NODE_ID);
    // Return an object holding them.
    final String varOrderString = values.get(FluoQueryColumns.QUERY_VARIABLE_ORDER);
    final VariableOrder varOrder = new VariableOrder(varOrderString);
    final String sparql = values.get(FluoQueryColumns.QUERY_SPARQL);
    final String childNodeId = values.get(FluoQueryColumns.QUERY_CHILD_NODE_ID);
    final String queryType = values.get(FluoQueryColumns.QUERY_TYPE);
    final String[] exportStrategies = values.get(FluoQueryColumns.QUERY_EXPORT_STRATEGIES).split(IncrementalUpdateConstants.VAR_DELIM);
    final Set<ExportStrategy> strategies = new HashSet<>();
    for (final String strategy : exportStrategies) {
        if (!strategy.isEmpty()) {
            strategies.add(ExportStrategy.valueOf(strategy));
        }
    }
    return QueryMetadata.builder(nodeId).setVarOrder(varOrder).setSparql(sparql).setExportStrategies(strategies).setQueryType(QueryType.valueOf(queryType)).setChildNodeId(childNodeId);
}
Also used : ExportStrategy(org.apache.rya.api.client.CreatePCJ.ExportStrategy) Column(org.apache.fluo.api.data.Column) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) HashSet(java.util.HashSet)

Example 10 with Column

use of org.apache.fluo.api.data.Column in project incubator-rya by apache.

the class FluoQueryMetadataDAO method readFilterMetadataBuilder.

private FilterMetadata.Builder readFilterMetadataBuilder(final SnapshotBase sx, final String nodeId) {
    requireNonNull(sx);
    requireNonNull(nodeId);
    // Fetch the values from the Fluo table.
    final String rowId = nodeId;
    final Map<Column, String> values = sx.gets(rowId, FluoQueryColumns.FILTER_VARIABLE_ORDER, FluoQueryColumns.FILTER_SPARQL, FluoQueryColumns.FILTER_PARENT_NODE_ID, FluoQueryColumns.FILTER_CHILD_NODE_ID);
    // Return an object holding them.
    final String varOrderString = values.get(FluoQueryColumns.FILTER_VARIABLE_ORDER);
    final VariableOrder varOrder = new VariableOrder(varOrderString);
    final String originalSparql = values.get(FluoQueryColumns.FILTER_SPARQL);
    final String parentNodeId = values.get(FluoQueryColumns.FILTER_PARENT_NODE_ID);
    final String childNodeId = values.get(FluoQueryColumns.FILTER_CHILD_NODE_ID);
    return FilterMetadata.builder(nodeId).setVarOrder(varOrder).setFilterSparql(originalSparql).setParentNodeId(parentNodeId).setChildNodeId(childNodeId);
}
Also used : Column(org.apache.fluo.api.data.Column) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)

Aggregations

Column (org.apache.fluo.api.data.Column)22 VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)13 Bytes (org.apache.fluo.api.data.Bytes)9 RowColumn (org.apache.fluo.api.data.RowColumn)9 Span (org.apache.fluo.api.data.Span)8 JsonObject (com.google.gson.JsonObject)4 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)4 HashSet (java.util.HashSet)3 Task (org.apache.rya.indexing.pcj.fluo.app.batch.BatchInformation.Task)3 JsonPrimitive (com.google.gson.JsonPrimitive)2 Transaction (org.apache.fluo.api.client.Transaction)2 IterativeJoin (org.apache.rya.api.function.join.IterativeJoin)2 Side (org.apache.rya.api.function.join.LazyJoiningIterator.Side)2 LeftOuterJoin (org.apache.rya.api.function.join.LeftOuterJoin)2 NaturalJoin (org.apache.rya.api.function.join.NaturalJoin)2 NodeType (org.apache.rya.indexing.pcj.fluo.app.NodeType)2 SpanBatchDeleteInformation (org.apache.rya.indexing.pcj.fluo.app.batch.SpanBatchDeleteInformation)2 JoinType (org.apache.rya.indexing.pcj.fluo.app.query.JoinMetadata.JoinType)2 IOException (java.io.IOException)1 InvalidClassException (java.io.InvalidClassException)1