Search in sources :

Example 21 with VariableOrder

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

the class AccumuloPcjSerializerTest method basicMixUriLiteralBsTest.

@Test
public void basicMixUriLiteralBsTest() throws BindingSetConversionException {
    final QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("X", new LiteralImpl("literal1"));
    bs.addBinding("Y", new LiteralImpl("5", new URIImpl("http://www.w3.org/2001/XMLSchema#integer")));
    bs.addBinding("Z", new LiteralImpl("5.0", new URIImpl("http://www.w3.org/2001/XMLSchema#double")));
    bs.addBinding("W", new LiteralImpl("1000", new URIImpl("http://www.w3.org/2001/XMLSchema#long")));
    bs.addBinding("A", new URIImpl("http://uri1"));
    bs.addBinding("B", new URIImpl("http://uri2"));
    bs.addBinding("C", new URIImpl("http://uri3"));
    final VariableOrder varOrder = new VariableOrder("A", "W", "X", "Y", "Z", "B", "C");
    BindingSetConverter<byte[]> converter = new AccumuloPcjSerializer();
    final byte[] byteVal = converter.convert(bs, varOrder);
    final BindingSet newBs = converter.convert(byteVal, varOrder);
    assertEquals(bs, newBs);
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) MapBindingSet(org.openrdf.query.impl.MapBindingSet) AccumuloPcjSerializer(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjSerializer) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) URIImpl(org.openrdf.model.impl.URIImpl) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Example 22 with VariableOrder

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

the class PcjTablesTest method pcjMetadata_hashCode.

@Test
public void pcjMetadata_hashCode() {
    PcjMetadata meta1 = new PcjMetadata("A SPARQL string.", 5, Sets.newHashSet(new VariableOrder("a", "b", "c"), new VariableOrder("d", "e", "f")));
    PcjMetadata meta2 = new PcjMetadata("A SPARQL string.", 5, Sets.newHashSet(new VariableOrder("a", "b", "c"), new VariableOrder("d", "e", "f")));
    assertEquals(meta1.hashCode(), meta2.hashCode());
}
Also used : VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) Test(org.junit.Test)

Example 23 with VariableOrder

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

the class AccumuloIndexSet method getRange.

private Range getRange(final String commonVarOrder, final BindingSet bs) throws BindingSetConversionException {
    final AccumuloPcjSerializer converter = new AccumuloPcjSerializer();
    byte[] rangePrefix = new byte[0];
    rangePrefix = converter.convert(bs, new VariableOrder(commonVarOrder));
    return Range.prefix(new Text(rangePrefix));
}
Also used : AccumuloPcjSerializer(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjSerializer) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) Text(org.apache.hadoop.io.Text)

Example 24 with VariableOrder

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

the class KafkaExportIT method groupByManyBindings_averages.

@Test
public void groupByManyBindings_averages() throws Exception {
    // A query that groups what is aggregated by two of the keys.
    final String sparql = "SELECT ?type ?location (avg(?price) as ?averagePrice) {" + "?id <urn:type> ?type . " + "?id <urn:location> ?location ." + "?id <urn:price> ?price ." + "} " + "GROUP BY ?type ?location";
    // Create the Statements that will be loaded into Rya.
    final ValueFactory vf = new ValueFactoryImpl();
    final Collection<Statement> statements = Sets.newHashSet(// American items that will be averaged.
    vf.createStatement(vf.createURI("urn:1"), vf.createURI("urn:type"), vf.createLiteral("apple")), vf.createStatement(vf.createURI("urn:1"), vf.createURI("urn:location"), vf.createLiteral("USA")), vf.createStatement(vf.createURI("urn:1"), vf.createURI("urn:price"), vf.createLiteral(2.50)), vf.createStatement(vf.createURI("urn:2"), vf.createURI("urn:type"), vf.createLiteral("cheese")), vf.createStatement(vf.createURI("urn:2"), vf.createURI("urn:location"), vf.createLiteral("USA")), vf.createStatement(vf.createURI("urn:2"), vf.createURI("urn:price"), vf.createLiteral(.99)), vf.createStatement(vf.createURI("urn:3"), vf.createURI("urn:type"), vf.createLiteral("cheese")), vf.createStatement(vf.createURI("urn:3"), vf.createURI("urn:location"), vf.createLiteral("USA")), vf.createStatement(vf.createURI("urn:3"), vf.createURI("urn:price"), vf.createLiteral(5.25)), // French items that will be averaged.
    vf.createStatement(vf.createURI("urn:4"), vf.createURI("urn:type"), vf.createLiteral("cheese")), vf.createStatement(vf.createURI("urn:4"), vf.createURI("urn:location"), vf.createLiteral("France")), vf.createStatement(vf.createURI("urn:4"), vf.createURI("urn:price"), vf.createLiteral(8.5)), vf.createStatement(vf.createURI("urn:5"), vf.createURI("urn:type"), vf.createLiteral("cigarettes")), vf.createStatement(vf.createURI("urn:5"), vf.createURI("urn:location"), vf.createLiteral("France")), vf.createStatement(vf.createURI("urn:5"), vf.createURI("urn:price"), vf.createLiteral(3.99)), vf.createStatement(vf.createURI("urn:6"), vf.createURI("urn:type"), vf.createLiteral("cigarettes")), vf.createStatement(vf.createURI("urn:6"), vf.createURI("urn:location"), vf.createLiteral("France")), vf.createStatement(vf.createURI("urn:6"), vf.createURI("urn:price"), vf.createLiteral(4.99)));
    // Create the PCJ in Fluo and load the statements into Rya.
    final String pcjId = loadDataAndCreateQuery(sparql, statements);
    // Create the expected results of the SPARQL query once the PCJ has been computed.
    final Set<VisibilityBindingSet> expectedResults = new HashSet<>();
    MapBindingSet bs = new MapBindingSet();
    bs.addBinding("type", vf.createLiteral("apple", XMLSchema.STRING));
    bs.addBinding("location", vf.createLiteral("USA", XMLSchema.STRING));
    bs.addBinding("averagePrice", vf.createLiteral("2.5", XMLSchema.DECIMAL));
    expectedResults.add(new VisibilityBindingSet(bs));
    bs = new MapBindingSet();
    bs.addBinding("type", vf.createLiteral("cheese", XMLSchema.STRING));
    bs.addBinding("location", vf.createLiteral("USA", XMLSchema.STRING));
    bs.addBinding("averagePrice", vf.createLiteral("3.12", XMLSchema.DECIMAL));
    expectedResults.add(new VisibilityBindingSet(bs));
    bs = new MapBindingSet();
    bs.addBinding("type", vf.createLiteral("cheese", XMLSchema.STRING));
    bs.addBinding("location", vf.createLiteral("France", XMLSchema.STRING));
    bs.addBinding("averagePrice", vf.createLiteral("8.5", XMLSchema.DECIMAL));
    expectedResults.add(new VisibilityBindingSet(bs));
    bs = new MapBindingSet();
    bs.addBinding("type", vf.createLiteral("cigarettes", XMLSchema.STRING));
    bs.addBinding("location", vf.createLiteral("France", XMLSchema.STRING));
    bs.addBinding("averagePrice", vf.createLiteral("4.49", XMLSchema.DECIMAL));
    expectedResults.add(new VisibilityBindingSet(bs));
    // Verify the end results of the query match the expected results.
    final Set<VisibilityBindingSet> results = readGroupedResults(pcjId, new VariableOrder("type", "location"));
    assertEquals(expectedResults, results);
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) Statement(org.openrdf.model.Statement) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with VariableOrder

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

the class KafkaExportIT method groupBySingleBinding.

@Test
public void groupBySingleBinding() throws Exception {
    // A query that groups what is aggregated by one of the keys.
    final String sparql = "SELECT ?item (avg(?price) as ?averagePrice) {" + "?item <urn:price> ?price . " + "} " + "GROUP BY ?item";
    // Create the Statements that will be loaded into Rya.
    final ValueFactory vf = new ValueFactoryImpl();
    final Collection<Statement> statements = Sets.newHashSet(vf.createStatement(vf.createURI("urn:apple"), vf.createURI("urn:price"), vf.createLiteral(5.25)), vf.createStatement(vf.createURI("urn:apple"), vf.createURI("urn:price"), vf.createLiteral(7)), vf.createStatement(vf.createURI("urn:apple"), vf.createURI("urn:price"), vf.createLiteral(2.75)), vf.createStatement(vf.createURI("urn:banana"), vf.createURI("urn:price"), vf.createLiteral(2.75)), vf.createStatement(vf.createURI("urn:banana"), vf.createURI("urn:price"), vf.createLiteral(1.99)));
    // Create the PCJ in Fluo and load the statements into Rya.
    final String pcjId = loadDataAndCreateQuery(sparql, statements);
    // Create the expected results of the SPARQL query once the PCJ has been computed.
    final Set<VisibilityBindingSet> expectedResults = new HashSet<>();
    MapBindingSet bs = new MapBindingSet();
    bs.addBinding("item", vf.createURI("urn:apple"));
    bs.addBinding("averagePrice", vf.createLiteral("5.0", XMLSchema.DECIMAL));
    expectedResults.add(new VisibilityBindingSet(bs));
    bs = new MapBindingSet();
    bs.addBinding("item", vf.createURI("urn:banana"));
    bs.addBinding("averagePrice", vf.createLiteral("2.37", XMLSchema.DECIMAL));
    expectedResults.add(new VisibilityBindingSet(bs));
    // Verify the end results of the query match the expected results.
    final Set<VisibilityBindingSet> results = readGroupedResults(pcjId, new VariableOrder("item"));
    assertEquals(expectedResults, results);
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) Statement(org.openrdf.model.Statement) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) HashSet(java.util.HashSet) 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