Search in sources :

Example 1 with PcjMetadataRenderer

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

the class ListQueriesCommand method execute.

@Override
public void execute(final Connector accumulo, final String ryaTablePrefix, final RyaSailRepository rya, final FluoClient fluo, final String[] args) throws ArgumentsException, ExecutionException {
    checkNotNull(accumulo);
    checkNotNull(fluo);
    checkNotNull(args);
    log.trace("Executing the List Queries 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 list the queries because of invalid command line parameters.", e);
    }
    // Fetch the PCJ metadata that will be included in the report.
    final GetPcjMetadata getPcjMetadata = new GetPcjMetadata();
    final Map<String, PcjMetadata> metadata = new HashMap<String, PcjMetadata>();
    try {
        final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(accumulo, ryaTablePrefix);
        if (params.queryId != null) {
            log.trace("Fetch the PCJ Metadata from Accumulo for Query ID '" + params.queryId + "'.");
            metadata.put(params.queryId, getPcjMetadata.getMetadata(pcjStorage, fluo, params.queryId));
        } else {
            log.trace("Fetch the PCJ Metadata from Accumulo for all queries that are being updated by Fluo.");
            metadata.putAll(getPcjMetadata.getMetadata(pcjStorage, fluo));
        }
    } catch (NotInFluoException | NotInAccumuloException e) {
        throw new ExecutionException("Could not fetch some of the metadata required to build the report.", e);
    }
    // Write the metadata to the console.
    log.trace("Rendering the queries report...");
    if (metadata.isEmpty()) {
        System.out.println("No queries are being tracked by Fluo.");
    } else {
        final PcjMetadataRenderer renderer = new PcjMetadataRenderer();
        try {
            final String report = renderer.render(metadata);
            System.out.println("The number of Queries that are being tracked by Fluo: " + metadata.size());
            System.out.println(report);
        } catch (final Exception e) {
            throw new ExecutionException("Unable to render the query metadata report for output.", e);
        }
    }
    log.trace("Finished executing the List Queries Command.");
}
Also used : NotInFluoException(org.apache.rya.indexing.pcj.fluo.api.GetPcjMetadata.NotInFluoException) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) NotInAccumuloException(org.apache.rya.indexing.pcj.fluo.api.GetPcjMetadata.NotInAccumuloException) HashMap(java.util.HashMap) ParameterException(com.beust.jcommander.ParameterException) NotInFluoException(org.apache.rya.indexing.pcj.fluo.api.GetPcjMetadata.NotInFluoException) NotInAccumuloException(org.apache.rya.indexing.pcj.fluo.api.GetPcjMetadata.NotInAccumuloException) JCommander(com.beust.jcommander.JCommander) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) PcjMetadataRenderer(org.apache.rya.indexing.pcj.fluo.client.util.PcjMetadataRenderer) ParameterException(com.beust.jcommander.ParameterException) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) GetPcjMetadata(org.apache.rya.indexing.pcj.fluo.api.GetPcjMetadata) GetPcjMetadata(org.apache.rya.indexing.pcj.fluo.api.GetPcjMetadata)

Example 2 with PcjMetadataRenderer

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

the class PcjMetadataRendererTest method formatSingleMetadata.

@Test
public void formatSingleMetadata() throws Exception {
    // Create the PcjMetadata that will be formatted as a report.
    final PcjMetadata metadata = new PcjMetadata("SELECT ?x ?y " + "WHERE { " + "?x <http://talksTo> <http://Eve>. " + "?y <http://worksAt> <http://Chipotle>." + "}", 12233423L, Sets.<VariableOrder>newHashSet(new VariableOrder("x", "y"), new VariableOrder("y", "x")));
    // Run the test.
    final String expected = "---------------------------------------------------------------------\n" + "| Query ID               | query1                                   |\n" + "| Cardinality            | 12,233,423                               |\n" + "| Export Variable Orders | y;x                                      |\n" + "|                        | x;y                                      |\n" + "| SPARQL                 | select ?x ?y                             |\n" + "|                        | where {                                  |\n" + "|                        |   ?x <http://talksTo> <http://Eve>.      |\n" + "|                        |   ?y <http://worksAt> <http://Chipotle>. |\n" + "|                        | }                                        |\n" + "---------------------------------------------------------------------\n";
    final PcjMetadataRenderer formatter = new PcjMetadataRenderer();
    assertEquals(expected, formatter.render("query1", metadata));
}
Also used : VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) PcjMetadataRenderer(org.apache.rya.indexing.pcj.fluo.client.util.PcjMetadataRenderer) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) Test(org.junit.Test)

Example 3 with PcjMetadataRenderer

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

the class PcjMetadataRendererTest method formatManyMetdata.

@Test
public void formatManyMetdata() throws Exception {
    // Create the PcjMetadata that will be formatted as a report.
    final PcjMetadata metadata1 = new PcjMetadata("SELECT ?x ?y " + "WHERE { " + "?x <http://talksTo> <http://Eve>. " + "?y <http://worksAt> <http://Chipotle>." + "}", 12233423L, Sets.<VariableOrder>newHashSet(new VariableOrder("x", "y"), new VariableOrder("y", "x")));
    final PcjMetadata metadata2 = new PcjMetadata("SELECT ?x " + "WHERE { " + "?x <http://likes> <http://cookies>" + "}", 2342L, Sets.<VariableOrder>newHashSet(new VariableOrder("x")));
    final Map<String, PcjMetadata> metadata = new LinkedHashMap<>();
    metadata.put("query1", metadata1);
    metadata.put("query2", metadata2);
    // Run the test.
    final String expected = "---------------------------------------------------------------------\n" + "| Query ID               | query1                                   |\n" + "| Cardinality            | 12,233,423                               |\n" + "| Export Variable Orders | y;x                                      |\n" + "|                        | x;y                                      |\n" + "| SPARQL                 | select ?x ?y                             |\n" + "|                        | where {                                  |\n" + "|                        |   ?x <http://talksTo> <http://Eve>.      |\n" + "|                        |   ?y <http://worksAt> <http://Chipotle>. |\n" + "|                        | }                                        |\n" + "---------------------------------------------------------------------\n" + "\n" + "------------------------------------------------------------------\n" + "| Query ID               | query2                                |\n" + "| Cardinality            | 2,342                                 |\n" + "| Export Variable Orders | x                                     |\n" + "| SPARQL                 | select ?x                             |\n" + "|                        | where {                               |\n" + "|                        |   ?x <http://likes> <http://cookies>. |\n" + "|                        | }                                     |\n" + "------------------------------------------------------------------\n" + "\n";
    final PcjMetadataRenderer formatter = new PcjMetadataRenderer();
    assertEquals(expected, formatter.render(metadata));
}
Also used : VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) PcjMetadataRenderer(org.apache.rya.indexing.pcj.fluo.client.util.PcjMetadataRenderer) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

PcjMetadataRenderer (org.apache.rya.indexing.pcj.fluo.client.util.PcjMetadataRenderer)3 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)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 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 GetPcjMetadata (org.apache.rya.indexing.pcj.fluo.api.GetPcjMetadata)1 NotInAccumuloException (org.apache.rya.indexing.pcj.fluo.api.GetPcjMetadata.NotInAccumuloException)1 NotInFluoException (org.apache.rya.indexing.pcj.fluo.api.GetPcjMetadata.NotInFluoException)1 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)1 AccumuloPcjStorage (org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage)1