Search in sources :

Example 56 with VariableOrder

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

the class ParsedQueryRequest method parse.

/**
 * Create a {@link ParsedQueryRequest} from formatted text.
 * <p>
 * The file may contain a list of variable orders at the head as comments.
 * The file must contain a SPARQL query to loAd into the application.
 * <p>
 * Example file:
 * <pre>
 *     #prefix a, b, c
 *     #prefix b, c, a
 *     SELECT *
 *     WHERE {
 *         ?a &lt;http://talksTo> ?b.
 *         ?b &lt;http://talksTo> ?c.
 *     }
 * </pre>
 * @throws IOException
 */
public static ParsedQueryRequest parse(final String requestText) throws IOException {
    checkNotNull(requestText);
    // Shift this pointer to the end of each match to find where the SPARQL starts.
    int startOfSparql = 0;
    // Scan for variable orders.
    final Set<VariableOrder> varOrders = new HashSet<>();
    final Matcher matcher = varOrdersPattern.matcher(requestText);
    while (matcher.find()) {
        final String varOrder = matcher.group(1);
        varOrders.add(new VariableOrder(varOrder.split(",\\s*")));
        startOfSparql = matcher.end();
    }
    // Pull the SPARQL out.
    final String sparql = requestText.substring(startOfSparql).trim();
    return new ParsedQueryRequest(sparql, varOrders);
}
Also used : Matcher(java.util.regex.Matcher) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) HashSet(java.util.HashSet)

Example 57 with VariableOrder

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

the class AccumuloPcjStorageIT method addResults.

@Test
public void addResults() throws AccumuloException, AccumuloSecurityException, PCJStorageException, MalformedQueryException {
    // Setup the PCJ storage that will be tested against.
    final Connector connector = super.getClusterInstance().getConnector();
    final String ryaInstanceName = super.getRyaInstanceName();
    try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(connector, ryaInstanceName)) {
        // Create a PCJ.
        final String sparql = "SELECT * WHERE { ?a <http://isA> ?b }";
        final String pcjId = pcjStorage.createPcj(sparql);
        // Add some binding sets to it.
        final Set<VisibilityBindingSet> results = new HashSet<>();
        final MapBindingSet aliceBS = new MapBindingSet();
        aliceBS.addBinding("a", new URIImpl("http://Alice"));
        aliceBS.addBinding("b", new URIImpl("http://Person"));
        results.add(new VisibilityBindingSet(aliceBS, ""));
        final MapBindingSet charlieBS = new MapBindingSet();
        charlieBS.addBinding("a", new URIImpl("http://Charlie"));
        charlieBS.addBinding("b", new URIImpl("http://Comedian"));
        results.add(new VisibilityBindingSet(charlieBS, ""));
        pcjStorage.addResults(pcjId, results);
        // Make sure the PCJ metadata was updated.
        final PcjMetadata metadata = pcjStorage.getPcjMetadata(pcjId);
        final Set<VariableOrder> varOrders = new ShiftVarOrderFactory().makeVarOrders(sparql);
        final PcjMetadata expectedMetadata = new PcjMetadata(sparql, 2L, varOrders);
        assertEquals(expectedMetadata, metadata);
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) ShiftVarOrderFactory(org.apache.rya.indexing.pcj.storage.accumulo.ShiftVarOrderFactory) URIImpl(org.openrdf.model.impl.URIImpl) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) MapBindingSet(org.openrdf.query.impl.MapBindingSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 58 with VariableOrder

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

the class AccumuloPcjStorageIT method purge.

@Test
public void purge() throws Exception {
    // Setup the PCJ storage that will be tested against.
    final Connector connector = super.getClusterInstance().getConnector();
    final String ryaInstanceName = super.getRyaInstanceName();
    try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(connector, ryaInstanceName)) {
        // Create a PCJ.
        final String sparql = "SELECT * WHERE { ?a <http://isA> ?b }";
        final String pcjId = pcjStorage.createPcj(sparql);
        // Add some binding sets to it.
        final Set<VisibilityBindingSet> expectedResults = new HashSet<>();
        final MapBindingSet aliceBS = new MapBindingSet();
        aliceBS.addBinding("a", new URIImpl("http://Alice"));
        aliceBS.addBinding("b", new URIImpl("http://Person"));
        expectedResults.add(new VisibilityBindingSet(aliceBS, ""));
        final MapBindingSet charlieBS = new MapBindingSet();
        charlieBS.addBinding("a", new URIImpl("http://Charlie"));
        charlieBS.addBinding("b", new URIImpl("http://Comedian"));
        expectedResults.add(new VisibilityBindingSet(charlieBS, ""));
        pcjStorage.addResults(pcjId, expectedResults);
        // Purge the PCJ.
        pcjStorage.purge(pcjId);
        // List the results that were stored.
        final Set<BindingSet> results = new HashSet<>();
        try (CloseableIterator<BindingSet> resultsIt = pcjStorage.listResults(pcjId)) {
            while (resultsIt.hasNext()) {
                results.add(resultsIt.next());
            }
        }
        assertTrue(results.isEmpty());
        // Make sure the PCJ metadata was updated.
        final PcjMetadata metadata = pcjStorage.getPcjMetadata(pcjId);
        final Set<VariableOrder> varOrders = new ShiftVarOrderFactory().makeVarOrders(sparql);
        final PcjMetadata expectedMetadata = new PcjMetadata(sparql, 0L, varOrders);
        assertEquals(expectedMetadata, metadata);
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) MapBindingSet(org.openrdf.query.impl.MapBindingSet) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BindingSet(org.openrdf.query.BindingSet) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) ShiftVarOrderFactory(org.apache.rya.indexing.pcj.storage.accumulo.ShiftVarOrderFactory) URIImpl(org.openrdf.model.impl.URIImpl) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) MapBindingSet(org.openrdf.query.impl.MapBindingSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 59 with VariableOrder

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

the class AccumuloPcjStorageIT method getPcjMetadata.

@Test
public void getPcjMetadata() throws AccumuloException, AccumuloSecurityException, PCJStorageException, MalformedQueryException {
    // Setup the PCJ storage that will be tested against.
    final Connector connector = super.getClusterInstance().getConnector();
    final String ryaInstanceName = super.getRyaInstanceName();
    try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(connector, ryaInstanceName)) {
        // Create a PCJ.
        final String sparql = "SELECT * WHERE { ?a <http://isA> ?b }";
        final String pcjId = pcjStorage.createPcj(sparql);
        // Fetch the PCJ's metadata.
        final PcjMetadata metadata = pcjStorage.getPcjMetadata(pcjId);
        // Ensure it has the expected values.
        final Set<VariableOrder> varOrders = new ShiftVarOrderFactory().makeVarOrders(sparql);
        final PcjMetadata expectedMetadata = new PcjMetadata(sparql, 0L, varOrders);
        assertEquals(expectedMetadata, metadata);
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) ShiftVarOrderFactory(org.apache.rya.indexing.pcj.storage.accumulo.ShiftVarOrderFactory) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) Test(org.junit.Test)

Example 60 with VariableOrder

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

the class MongoPcjDocumentsTest method pcjToMetadata.

@Test
public void pcjToMetadata() throws Exception {
    final MongoPcjDocuments docConverter = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
    final String sparql = "SELECT * WHERE { ?a <http://isA> ?b }";
    final Document actual = docConverter.makeMetadataDocument("pcjTest", sparql);
    final Document expected = new Document().append(MongoPcjDocuments.CARDINALITY_FIELD, 0).append(MongoPcjDocuments.PCJ_METADATA_ID, "pcjTest_METADATA").append(MongoPcjDocuments.SPARQL_FIELD, sparql).append(MongoPcjDocuments.VAR_ORDER_FIELD, Sets.newHashSet(new VariableOrder("a", "b"), new VariableOrder("b", "a")));
    assertEquals(expected, actual);
}
Also used : VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) Document(org.bson.Document) 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