Github user meiercaleb commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/198#discussion_r133722022 --- Diff: extras/rya.pcj.fluo/pcj.fluo.integration/src/test/java/org/apache/rya/indexing/pcj/fluo/integration/KafkaExportIT.java --- @@ -425,6 +432,160 @@ public void groupByManyBindings_avaerages() throws Exception { assertEquals(expectedResults, results); } + + @Test + public void nestedGroupByManyBindings_averages() throws Exception { + // A query that groups what is aggregated by two of the keys. + final String sparql = + "SELECT ?type ?location ?averagePrice {" + + "FILTER(?averagePrice > 4) " + + "{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(4.25)), + + 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 = loadData(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("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) ); + + bs = new MapBindingSet(); + bs.addBinding("type", vf.createLiteral("cheese", XMLSchema.STRING)); + bs.addBinding("location", vf.createLiteral("USA", XMLSchema.STRING)); + bs.addBinding("averagePrice", vf.createLiteral("4.75", 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")); + System.out.println(results); --- End diff -- Done.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---