Skip to content

Commit

Permalink
Merge pull request #141 from koopjs/feature/117
Browse files Browse the repository at this point in the history
Added support for data source joins in aggregations. Issue #117
  • Loading branch information
jkerr5 authored Dec 13, 2018
2 parents 2c25a93 + 7214c35 commit 1fccea2
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/main/ml-modules/services/KoopProvider.sjs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ function query(req) {
type : 'FeatureCollection',
metadata : {
name: req.params.id,
maxRecordCount: MAX_RECORD_COUNT
},
filtersApplied: {
geometry: true, // true if a geometric filter has already been applied to the data
Expand All @@ -344,7 +345,7 @@ function query(req) {
};

if (req.query.returnCountOnly) {
console.log("getting count");
console.debug("getting count");

req.query.outStatistics = [
{ outStatisticFieldName : "count", statisticType : "count" }
Expand All @@ -358,16 +359,16 @@ function query(req) {
}
} else if (req.query.outStatistics != null) {

console.log("running aggregation");
console.debug("running aggregation");
geojson.statistics = Array.from(aggregate(req));

} else {

console.log("getting objects");
console.debug("getting objects");
const objects = getObjects(req);
geojson.features = objects.result;

console.log("limitExceeded flag :" +objects.limitExceeded);
console.debug("limitExceeded flag :" + objects.limitExceeded);

// we should only get this once in the process but do this for now to test
const serviceId = req.params.id;
Expand Down Expand Up @@ -832,7 +833,7 @@ function getObjects(req) {
const opticResult = Array.from(pipeline.result(null, bindParams))
const opticResultCount = opticResult.length

if(opticResultCount >= (limit+1) ){
if(opticResultCount >= (limit + 1) ){
opticResult.pop();
return {
result : opticResult,
Expand Down Expand Up @@ -926,7 +927,29 @@ function aggregate(req) {
"limit" : limit
};

let pipeline = op.fromView(layerModel.schema, layerModel.view)
let pipeline;
if (layerModel.dataSources === undefined) {
const schema = layerModel.schema;
const view = layerModel.view;

let viewPlan = op.fromView(schema, view, null, "DocId");

pipeline = initializePipeline(viewPlan, boundingQuery, layerModel)
} else {
const primaryDataSource = layerModel.dataSources[0];
if (primaryDataSource.source === "view") {
const schema = primaryDataSource.schema;
const view = primaryDataSource.view;

let viewPlan = op.fromView(schema, view, null, "DocId");
pipeline = initializePipeline(viewPlan, boundingQuery, layerModel)
} else if (primaryDataSource.source === "sparql") {
let viewPlan = getPlanForDataSource(primaryDataSource);
pipeline = initializePipeline(viewPlan, boundingQuery, layerModel)
}
}

pipeline = pipeline
.where(boundingQuery)
.where(whereQuery)
.groupBy(
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/ServiceDescriptorArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,34 @@ public void testDataSourceWithSparqlAsRootAndViewJoinWithoutFieldsElement() {
.body("features[0].attributes.geores", is(3))
;
}

@Test
public void testDataSourceWithSparqlAsRootAndViewJoinWithoutFieldsElementStats() {
String path = request2path("DataSourceArraySparqlPlusViewJoinWithoutFieldsElementStats.json");

RestAssured
.given()
.when()
.log().uri()
.get(path)

.then()
.log().ifError()
.statusCode(200)
.log().ifValidationFails()

.body("features.size()", is(2))
.body(
"features.attributes.find { it.domain == '4-traders.com' }.objectid_count",
is(8)
)
.body(
"features.attributes.find { it.domain == 'bendigoadvertiser.com.au' }.objectid_count",
is(1)
)
;
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"params" : {
"id" : "DataSourceArrayExample",
"layer" : 11,
"method" : "query"
},
"query" : {
"groupByFieldsForStatistics": "domain",
"outStatistics": "[ {\"statisticType\":\"count\",\"onStatisticField\":\"OBJECTID\",\"outStatisticFieldName\":\"objectid_count\"} ]"
}
}

0 comments on commit 1fccea2

Please sign in to comment.