Search in sources :

Example 1 with ParsedQueryRequest

use of org.apache.rya.indexing.pcj.fluo.client.util.ParsedQueryRequest in project incubator-rya by apache.

the class ParsedQueryRequestTest method parseNoVarOrders.

@Test
public void parseNoVarOrders() throws IOException {
    final String requestText = "SELECT * \n" + "WHERE { \n" + "  ?a <http://talksTo> ?b. \n" + "  ?b <http://talksTo> ?c. \n" + "}";
    final ParsedQueryRequest expected = new ParsedQueryRequest("SELECT * \n" + "WHERE { \n" + "  ?a <http://talksTo> ?b. \n" + "  ?b <http://talksTo> ?c. \n" + "}", new HashSet<VariableOrder>());
    final ParsedQueryRequest request = ParsedQueryRequest.parse(requestText);
    assertEquals(expected, request);
}
Also used : ParsedQueryRequest(org.apache.rya.indexing.pcj.fluo.client.util.ParsedQueryRequest) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) Test(org.junit.Test)

Example 2 with ParsedQueryRequest

use of org.apache.rya.indexing.pcj.fluo.client.util.ParsedQueryRequest in project incubator-rya by apache.

the class NewQueryCommand method execute.

@Override
public void execute(final Connector accumulo, final String ryaTablePrefix, final RyaSailRepository rya, final FluoClient fluo, final String[] args) throws ArgumentsException, ExecutionException, UnsupportedQueryException {
    checkNotNull(accumulo);
    checkNotNull(fluo);
    checkNotNull(args);
    log.trace("Executing the New Query Command...");
    // Parse the command line arguments.
    final Parameters params = new Parameters();
    try {
        new JCommander(params, args);
    } catch (final ParameterException e) {
        throw new ArgumentsException("Could not create a new query because of invalid command line parameters.", e);
    }
    // Load the request from the file into memory.
    log.trace("Loading the query found in file '" + params.queryRequestFile + "' into the client app.");
    ParsedQueryRequest request = null;
    try {
        final Path requestFile = Paths.get(params.queryRequestFile);
        final String requestText = IOUtils.toString(Files.newInputStream(requestFile));
        request = ParsedQueryRequest.parse(requestText);
    } catch (final IOException e) {
        throw new ExecutionException("Could not load the query request into memory.", e);
    }
    // Load the query into the Fluo app.
    log.trace("SPARQL Query: " + request.getQuery());
    log.trace("Var Orders: " + request.getVarOrders());
    log.trace("Loading these values into the Fluo app.");
    final CreateFluoPcj createPcj = new CreateFluoPcj();
    try {
        // Create the PCJ in Rya.
        final String sparql = request.getQuery();
        final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(accumulo, ryaTablePrefix);
        final String pcjId = pcjStorage.createPcj(sparql);
        // Tell the Fluo PCJ Updater app to maintain the PCJ.
        createPcj.withRyaIntegration(pcjId, pcjStorage, fluo, accumulo, ryaTablePrefix);
    } catch (MalformedQueryException | PcjException | RyaDAOException e) {
        throw new ExecutionException("Could not create and load historic matches into the the Fluo app for the query.", e);
    }
    log.trace("Finished executing the New Query Command.");
}
Also used : Path(java.nio.file.Path) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) PcjException(org.apache.rya.indexing.pcj.storage.PcjException) CreateFluoPcj(org.apache.rya.indexing.pcj.fluo.api.CreateFluoPcj) IOException(java.io.IOException) ParsedQueryRequest(org.apache.rya.indexing.pcj.fluo.client.util.ParsedQueryRequest) JCommander(com.beust.jcommander.JCommander) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) MalformedQueryException(org.openrdf.query.MalformedQueryException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) ParameterException(com.beust.jcommander.ParameterException)

Example 3 with ParsedQueryRequest

use of org.apache.rya.indexing.pcj.fluo.client.util.ParsedQueryRequest in project incubator-rya by apache.

the class ParsedQueryRequestTest method parseHasVarOrders.

@Test
public void parseHasVarOrders() throws IOException {
    final String requestText = "#prefix a,    b,c\n" + "#prefix b, c, a\n" + "SELECT * \n" + "WHERE { \n" + "  ?a <http://talksTo> ?b. \n" + "  ?b <http://talksTo> ?c. \n" + "}";
    final ParsedQueryRequest expected = new ParsedQueryRequest("SELECT * \n" + "WHERE { \n" + "  ?a <http://talksTo> ?b. \n" + "  ?b <http://talksTo> ?c. \n" + "}", Sets.newHashSet(new VariableOrder("a", "b", "c"), new VariableOrder("b", "c", "a")));
    final ParsedQueryRequest request = ParsedQueryRequest.parse(requestText);
    assertEquals(expected, request);
}
Also used : ParsedQueryRequest(org.apache.rya.indexing.pcj.fluo.client.util.ParsedQueryRequest) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) Test(org.junit.Test)

Aggregations

ParsedQueryRequest (org.apache.rya.indexing.pcj.fluo.client.util.ParsedQueryRequest)3 VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)2 Test (org.junit.Test)2 JCommander (com.beust.jcommander.JCommander)1 ParameterException (com.beust.jcommander.ParameterException)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)1 CreateFluoPcj (org.apache.rya.indexing.pcj.fluo.api.CreateFluoPcj)1 PcjException (org.apache.rya.indexing.pcj.storage.PcjException)1 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)1 AccumuloPcjStorage (org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage)1 MalformedQueryException (org.openrdf.query.MalformedQueryException)1