Search in sources :

Example 6 with VariableOrder

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

the class ConstructQueryResultUpdater method updateConstructQueryResults.

/**
 * Updates the Construct Query results by applying the {@link ConnstructGraph} to
 * create a {@link RyaSubGraph} and then writing the subgraph to {@link FluoQueryColumns#CONSTRUCT_STATEMENTS}.
 * @param tx - transaction used to write the subgraph
 * @param bs - BindingSet that the ConstructProjection expands into a subgraph
 * @param metadata - metadata that the ConstructProjection is extracted from
 */
public void updateConstructQueryResults(TransactionBase tx, VisibilityBindingSet bs, ConstructQueryMetadata metadata) {
    String nodeId = metadata.getNodeId();
    VariableOrder varOrder = metadata.getVariableOrder();
    Column column = FluoQueryColumns.CONSTRUCT_STATEMENTS;
    ConstructGraph graph = metadata.getConstructGraph();
    String parentId = metadata.getParentNodeId();
    // Create the Row Key for the emitted binding set. It does not contain visibilities.
    final Bytes resultRow = makeRowKey(nodeId, varOrder, bs);
    // If this is a new binding set, then emit it.
    if (tx.get(resultRow, column) == null || varOrder.getVariableOrders().size() < bs.size()) {
        Set<RyaStatement> statements = graph.createGraphFromBindingSet(bs);
        RyaSubGraph subgraph = new RyaSubGraph(parentId, statements);
        final Bytes nodeValueBytes = Bytes.of(serializer.toBytes(subgraph));
        log.trace("Transaction ID: " + tx.getStartTimestamp() + "\n" + "New Binding Set: " + subgraph + "\n");
        tx.set(resultRow, column, nodeValueBytes);
    }
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) RyaSubGraph(org.apache.rya.api.domain.RyaSubGraph) Column(org.apache.fluo.api.data.Column) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) RyaStatement(org.apache.rya.api.domain.RyaStatement)

Example 7 with VariableOrder

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

the class PCJKeyToCrossProductBindingSetIterator method getBindingSet.

/**
 * @param key
 *            - Accumulo key obtained from scan
 * @return - BindingSet satisfying any specified constant constraints
 * @throws BindingSetConversionException
 * @throws QueryEvaluationException
 */
private BindingSet getBindingSet(Key key) throws BindingSetConversionException, QueryEvaluationException {
    byte[] row = key.getRow().getBytes();
    String[] varOrder = key.getColumnFamily().toString().split(ExternalTupleSet.VAR_ORDER_DELIM);
    BindingSet bindingSet = converter.convert(row, new VariableOrder(varOrder));
    QueryBindingSet bs = new QueryBindingSet();
    for (String var : bindingSet.getBindingNames()) {
        String mappedVar = null;
        if (pcjVarMap.containsKey(var)) {
            mappedVar = pcjVarMap.get(var);
        } else {
            throw new QueryEvaluationException("PCJ Variable has no mapping to query variable.");
        }
        if (constantConstraintsExist) {
            if (mappedVar.startsWith(ExternalTupleSet.CONST_PREFIX) && constantConstraints.containsKey(mappedVar) && !constantConstraints.get(mappedVar).equals(bindingSet.getValue(var))) {
                return EMPTY_BINDINGSET;
            }
        }
        if (!mappedVar.startsWith(ExternalTupleSet.CONST_PREFIX)) {
            bs.addBinding(mappedVar, bindingSet.getValue(var));
        }
    }
    return bs;
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet)

Example 8 with VariableOrder

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

the class PCJKeyToJoinBindingSetIterator method getBindingSetEntryAndMatchConstants.

/**
 * @param key
 *            - Accumulo key obtained from scan
 * @return - Entry<String,BindingSet> satisfying the constant constraints
 * @throws BindingSetConversionException
 */
private Map.Entry<String, BindingSet> getBindingSetEntryAndMatchConstants(Key key) throws BindingSetConversionException {
    byte[] row = key.getRow().getBytes();
    String[] varOrder = key.getColumnFamily().toString().split(ExternalTupleSet.VAR_ORDER_DELIM);
    BindingSet bindingSet = converter.convert(row, new VariableOrder(varOrder));
    QueryBindingSet bs = new QueryBindingSet();
    for (String var : bindingSet.getBindingNames()) {
        String mappedVar = pcjVarMap.get(var);
        if (mappedVar.startsWith(ExternalTupleSet.CONST_PREFIX) && constantConstraints.containsKey(mappedVar) && !constantConstraints.get(mappedVar).equals(bindingSet.getValue(var))) {
            return EMPTY_ENTRY;
        } else {
            bs.addBinding(mappedVar, bindingSet.getValue(var));
        }
    }
    String orderedValueString = bindingSet.getValue(varOrder[0]).toString();
    for (int i = 1; i < maxPrefixLen; i++) {
        Value value = bindingSet.getValue(varOrder[i]);
        if (value != null) {
            orderedValueString = orderedValueString + ExternalTupleSet.VALUE_DELIM + value.toString();
        }
    }
    return new RdfCloudTripleStoreUtils.CustomEntry<String, BindingSet>(orderedValueString, bs);
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) Value(org.openrdf.model.Value) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet)

Example 9 with VariableOrder

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

the class MongoPcjDocumentsTest method metadataExists.

@Test
public void metadataExists() throws Exception {
    final List<VariableOrder> varOrders = Lists.newArrayList(new VariableOrder("b", "a"), new VariableOrder("a", "b"));
    final MongoPcjDocuments docConverter = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
    final String sparql = "SELECT * WHERE { ?a <http://isA> ?b }";
    docConverter.createPcj("pcjTest", sparql);
    PcjMetadata actual = docConverter.getPcjMetadata("pcjTest");
    PcjMetadata expected = new PcjMetadata(sparql, 0, varOrders);
    assertEquals(expected, actual);
    // Setup the binding set that will be converted.
    final MapBindingSet originalBindingSet1 = new MapBindingSet();
    originalBindingSet1.addBinding("x", new URIImpl("http://a"));
    originalBindingSet1.addBinding("y", new URIImpl("http://b"));
    originalBindingSet1.addBinding("z", new URIImpl("http://c"));
    final VisibilityBindingSet results1 = new VisibilityBindingSet(originalBindingSet1, "A&B&C");
    // Setup the binding set that will be converted.
    final MapBindingSet originalBindingSet2 = new MapBindingSet();
    originalBindingSet2.addBinding("x", new URIImpl("http://1"));
    originalBindingSet2.addBinding("y", new URIImpl("http://2"));
    originalBindingSet2.addBinding("z", new URIImpl("http://3"));
    final VisibilityBindingSet results2 = new VisibilityBindingSet(originalBindingSet2, "A&B&C");
    final List<VisibilityBindingSet> bindingSets = new ArrayList<>();
    bindingSets.add(results1);
    bindingSets.add(results2);
    docConverter.addResults("pcjTest", bindingSets);
    actual = docConverter.getPcjMetadata("pcjTest");
    expected = new PcjMetadata(sparql, 2, varOrders);
    assertEquals(expected, actual);
    docConverter.purgePcjs("pcjTest");
    actual = docConverter.getPcjMetadata("pcjTest");
    expected = new PcjMetadata(sparql, 0, varOrders);
    assertEquals(expected, actual);
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) ArrayList(java.util.ArrayList) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) URIImpl(org.openrdf.model.impl.URIImpl) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Test(org.junit.Test)

Example 10 with VariableOrder

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

the class PcjDocumentsIntegrationTest method dropPcj.

@Test(expected = PCJStorageException.class)
public void dropPcj() throws Exception {
    // Create a PCJ index.
    final String pcjTableName = "testPcj";
    final String sparql = "SELECT x WHERE ?x <http://isA> <http://Food>";
    final MongoPcjDocuments pcjs = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
    pcjs.createPcj(pcjTableName, sparql);
    // Fetch its metadata to show that it has actually been created.
    final PcjMetadata expectedMetadata = new PcjMetadata(sparql, 0L, new ArrayList<VariableOrder>());
    PcjMetadata metadata = pcjs.getPcjMetadata(pcjTableName);
    assertEquals(expectedMetadata, metadata);
    // Drop it.
    pcjs.dropPcj(pcjTableName);
    // Show the metadata is no longer present.
    metadata = pcjs.getPcjMetadata(pcjTableName);
}
Also used : VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) Test(org.junit.Test)

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