Search in sources :

Example 31 with VariableOrder

use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.

the class TripleObserver method process.

@Override
public void process(final TransactionBase tx, final Bytes brow, final Column column) {
    // Get string representation of triple.
    final RyaStatement ryaStatement = IncUpdateDAO.deserializeTriple(brow);
    log.trace("Transaction ID: {}\nRya Statement: {}\n", tx.getStartTimestamp(), ryaStatement);
    log.trace("Beginging to process triple.");
    final String triple = IncUpdateDAO.getTripleString(ryaStatement);
    Set<String> spIDs = SP_ID_CACHE.getStatementPatternIds(tx);
    // see if triple matches conditions of any of the SP
    for (String spID : spIDs) {
        // Fetch its metadata.
        final StatementPatternMetadata spMetadata = QUERY_METADATA_DAO.readStatementPatternMetadata(tx, spID);
        log.trace("Retrieved metadata: {}", spMetadata);
        // Attempt to match the triple against the pattern.
        final String pattern = spMetadata.getStatementPattern();
        final VariableOrder varOrder = spMetadata.getVariableOrder();
        final String bindingSetString = getBindingSet(triple, pattern, varOrder);
        log.trace("Created binding set match string: {}", bindingSetString);
        // Statement matches to a binding set.
        if (bindingSetString.length() != 0) {
            // Fetch the triple's visibility label.
            final String visibility = tx.gets(brow.toString(), FluoQueryColumns.TRIPLES, "");
            // Make BindingSet and sharded row
            final VisibilityBindingSet visBindingSet = VIS_BS_CONVERTER.convert(bindingSetString, varOrder);
            visBindingSet.setVisibility(visibility);
            Bytes row = BindingHashShardingFunction.addShard(spID, varOrder, visBindingSet);
            // If this is a new Binding Set, then emit it.
            if (tx.get(row, FluoQueryColumns.STATEMENT_PATTERN_BINDING_SET) == null) {
                try {
                    final Bytes valueBytes = BS_SERDE.serialize(visBindingSet);
                    log.trace("Transaction ID: {}\nMatched Statement Pattern: {}\nBinding Set: {}\n", tx.getStartTimestamp(), spID, visBindingSet);
                    tx.set(row, FluoQueryColumns.STATEMENT_PATTERN_BINDING_SET, valueBytes);
                } catch (final Exception e) {
                    log.error("Couldn't serialize a Binding Set. This value will be skipped.", e);
                }
            }
        }
    }
    // Once the triple has been handled, it may be deleted.
    tx.delete(brow, column);
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) StatementPatternMetadata(org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) RyaStatement(org.apache.rya.api.domain.RyaStatement)

Example 32 with VariableOrder

use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder 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 33 with VariableOrder

use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder 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 34 with VariableOrder

use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder 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)

Example 35 with VariableOrder

use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.

the class JoinBatchInformationTypeAdapter method deserialize.

@Override
public JoinBatchInformation deserialize(final JsonElement element, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException {
    final JsonObject json = element.getAsJsonObject();
    final int batchSize = json.get("batchSize").getAsInt();
    final Task task = Task.valueOf(json.get("task").getAsString());
    final String[] colArray = json.get("column").getAsString().split("\u0000");
    final Column column = new Column(colArray[0], colArray[1]);
    final String[] rows = json.get("span").getAsString().split("\u0000");
    final boolean startInc = json.get("startInc").getAsBoolean();
    final boolean endInc = json.get("endInc").getAsBoolean();
    final Span span = new Span(new RowColumn(rows[0]), startInc, new RowColumn(rows[1]), endInc);
    final VariableOrder updateVarOrder = new VariableOrder(json.get("updateVarOrder").getAsString());
    final VisibilityBindingSet bs = converter.convert(json.get("bindingSet").getAsString(), updateVarOrder);
    final Side side = Side.valueOf(json.get("side").getAsString());
    final JoinType join = JoinType.valueOf(json.get("joinType").getAsString());
    return JoinBatchInformation.builder().setBatchSize(batchSize).setTask(task).setSpan(span).setColumn(column).setBs(bs).setSide(side).setJoinType(join).build();
}
Also used : Task(org.apache.rya.indexing.pcj.fluo.app.batch.BatchInformation.Task) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) RowColumn(org.apache.fluo.api.data.RowColumn) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) JsonObject(com.google.gson.JsonObject) JoinType(org.apache.rya.indexing.pcj.fluo.app.query.JoinMetadata.JoinType) Span(org.apache.fluo.api.data.Span) Side(org.apache.rya.api.function.join.LazyJoiningIterator.Side) RowColumn(org.apache.fluo.api.data.RowColumn) Column(org.apache.fluo.api.data.Column)

Aggregations

VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)79 Test (org.junit.Test)47 HashSet (java.util.HashSet)18 MapBindingSet (org.openrdf.query.impl.MapBindingSet)18 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)17 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)16 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)15 Bytes (org.apache.fluo.api.data.Bytes)14 BindingSet (org.openrdf.query.BindingSet)14 Column (org.apache.fluo.api.data.Column)13 FluoClient (org.apache.fluo.api.client.FluoClient)12 URIImpl (org.openrdf.model.impl.URIImpl)12 Transaction (org.apache.fluo.api.client.Transaction)11 Snapshot (org.apache.fluo.api.client.Snapshot)10 ShiftVarOrderFactory (org.apache.rya.indexing.pcj.storage.accumulo.ShiftVarOrderFactory)10 AccumuloPcjSerializer (org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjSerializer)9 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)8 Connector (org.apache.accumulo.core.client.Connector)5 AccumuloPcjStorage (org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage)5 RowColumn (org.apache.fluo.api.data.RowColumn)4