Skip to content

Commit 20e1bee

Browse files
nck-mlcnvbigerl
andauthored
Add result aggregation for query templates (#283)
* Add QueryData class * Add test * Check for update queries * Move responsibility of QueryData to QueryHandler * Remove unused methods * Add tests * Fix authentication * Cleanup * Fix StringListQueryList * Modify QueryHandler and QueryData * Add executable query count and representative query count to QueryHandler * Update the saving template instances * Fix individual template instances results * Add some comments * Update schema * Change default behavior of query templates * Update tests * Fix configuration * Update documentation * Add some comments (to trigger GitHub actions) * Fix minor bug that caused an infinite loop * Change sparql endpoint for testing * Add javadocs * Refactor attribute name * Refactor method name * Add more javadocs * Update src/main/java/org/aksw/iguana/cc/query/QueryData.java Co-authored-by: Alexander Bigerl <bigerl@mail.upb.de> * Revert "Update src/main/java/org/aksw/iguana/cc/query/QueryData.java" This reverts commit 8489f6e. * Delegate handling of query templates to an extra class * Trying to clarify comments * Add more comments * Change behavior of noOfQueries property in results * Remove unused import * Fix broken tests * Rename TemplateHandler to QueryTemplateHandler * Add javadoc string --------- Co-authored-by: Alexander Bigerl <bigerl@mail.upb.de>
1 parent c1dc6da commit 20e1bee

23 files changed

+555
-194
lines changed

docs/configuration/queries.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,21 @@ The results may look like the following:
130130
### Configuration
131131
The `template` attribute has the following properties:
132132

133-
| property | required | default | description | example |
134-
|----------|----------|---------|---------------------------------------------------------------------|-----------------------------|
135-
| endpoint | yes | | The endpoint to query. | `http://dbpedia.org/sparql` |
136-
| limit | no | `2000` | The maximum number of instances per query template. | `100` |
137-
| save | no | `true` | If set to `true`, query instances will be saved in a separate file. | `false` |
133+
| property | required | default | description | example |
134+
|-------------------|----------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------|
135+
| endpoint | yes | | The endpoint to query. | `http://dbpedia.org/sparql` |
136+
| limit | no | `2000` | The maximum number of instances per query template. | `100` |
137+
| save | no | `true` | If set to `true`, query instances will be saved in a separate file. | `false` |
138+
| individualResults | no | `false` | If set to `true`, the results of each individual template instance will be reported, otherwise if set to `false` their results will be subsumed for the query template. | `true` |
138139

139140
If the `save` attribute is set to `true`,
140141
the instances will be saved in a separate file in the same directory as the query templates.
141142
If the query templates are stored in a folder, the instances will be saved in the parent directory.
142143

144+
If the `individualResults` attribute is set to `false`,
145+
the results of the instances will be subsumed for the query template.
146+
The query template will then be considered as an actual query in the results.
147+
143148
Example of query configuration with query templates:
144149
```yaml
145150
queries:
@@ -149,4 +154,5 @@ queries:
149154
endpoint: "http://dbpedia.org/sparql"
150155
limit: 100
151156
save: true
157+
individualResults: true
152158
```

example-suite.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,11 @@ tasks:
7575
requestType: post query
7676
queries:
7777
path: "./example/query_pattern.txt"
78-
pattern:
78+
template:
7979
endpoint: "https://dbpedia.org/sparql"
8080
limit: 1000
8181
save: false
82+
individualResults: false
8283
timeout: 180s
8384
completionTarget:
8485
duration: 1000s

graalvm/suite.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ connections:
66
- name: "Blazegraph"
77
version: "1.1.1"
88
dataset: "DatasetName"
9-
endpoint: "http://localhost:9999/blazegraph/sparql"
9+
endpoint: "https://query.wikidata.org/"
1010
authentication:
1111
user: "user"
1212
password: "test"
@@ -60,13 +60,14 @@ tasks:
6060
seed: 123
6161
lang: "SPARQL"
6262
template:
63-
endpoint: "http://dbpedia.org/sparql"
63+
endpoint: "https://dbpedia.org/sparql"
6464
limit: 1
6565
save: false
66+
individualResults: false
6667
timeout: 2s
6768
connection: Blazegraph
6869
completionTarget:
69-
duration: 1s
70+
duration: 0.5s
7071
acceptHeader: "application/sparql-results+json"
7172
requestType: get query
7273
parseResults: true
@@ -78,7 +79,7 @@ tasks:
7879
timeout: 3m
7980
connection: Blazegraph
8081
completionTarget:
81-
duration: 1s
82+
duration: 0.5s
8283
requestType: get query
8384
acceptHeader: "application/sparql-results+json"
8485
- number: 1

schema/iguana-schema.json

+3
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@
351351
},
352352
"save": {
353353
"type": "boolean"
354+
},
355+
"individualResults": {
356+
"type": "boolean"
354357
}
355358
},
356359
"required": [

src/main/java/org/aksw/iguana/cc/metrics/impl/AggregatedExecutionStatistics.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public AggregatedExecutionStatistics() {
2929
public Model createMetricModel(List<HttpWorker> workers, List<HttpWorker.ExecutionStats>[][] data, IRES.Factory iresFactory) {
3030
Model m = ModelFactory.createDefaultModel();
3131
for (var worker : workers) {
32-
for (int i = 0; i < worker.config().queries().getQueryCount(); i++) {
32+
for (int i = 0; i < worker.config().queries().getRepresentedQueryCount(); i++) {
3333
Resource queryRes = iresFactory.getWorkerQueryResource(worker, i);
3434
m.add(createAggregatedModel(data[(int) worker.getWorkerID()][i], queryRes));
3535
}

src/main/java/org/aksw/iguana/cc/metrics/impl/EachExecutionStatistic.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public EachExecutionStatistic() {
2626
public Model createMetricModel(List<HttpWorker> workers, List<HttpWorker.ExecutionStats>[][] data, IRES.Factory iresFactory) {
2727
Model m = ModelFactory.createDefaultModel();
2828
for (var worker : workers) {
29-
for (int i = 0; i < worker.config().queries().getQueryCount(); i++) {
29+
for (int i = 0; i < worker.config().queries().getRepresentedQueryCount(); i++) {
3030
Resource workerQueryResource = iresFactory.getWorkerQueryResource(worker, i);
3131
Resource queryRes = IRES.getResource(worker.config().queries().getQueryId(i));
3232
BigInteger run = BigInteger.ONE;

src/main/java/org/aksw/iguana/cc/metrics/impl/QMPH.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public Number calculateTaskMetric(List<HttpWorker> workers, List<HttpWorker.Exec
2828
@Override
2929
public Number calculateWorkerMetric(HttpWorker.Config worker, List<HttpWorker.ExecutionStats>[] data) {
3030
BigDecimal successes = BigDecimal.ZERO;
31-
BigDecimal noq = BigDecimal.valueOf(worker.queries().getQueryCount());
31+
BigDecimal noq = BigDecimal.valueOf(worker.queries().getExecutableQueryCount());
3232
Duration totalTime = Duration.ZERO;
3333
for (List<HttpWorker.ExecutionStats> datum : data) {
3434
for (HttpWorker.ExecutionStats exec : datum) {

src/main/java/org/aksw/iguana/cc/query/QueryData.java

+41-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.apache.jena.update.UpdateFactory;
44

5+
import java.io.IOException;
56
import java.io.InputStream;
67
import java.util.ArrayList;
78
import java.util.Collection;
@@ -12,9 +13,23 @@
1213
* At the moment, it only stores if the query is an update query or not.
1314
*
1415
* @param queryId The id of the query
15-
* @param update If the query is an update query
1616
*/
17-
public record QueryData(int queryId, boolean update) {
17+
public record QueryData(int queryId, QueryType type, Integer templateId) {
18+
public enum QueryType {
19+
DEFAULT,
20+
UPDATE,
21+
TEMPLATE,
22+
TEMPLATE_INSTANCE
23+
}
24+
25+
/**
26+
* Generates a list of QueryData objects for a collection of queries.
27+
* The method uses the Jena library to check if the query is an update query.
28+
* It only checks if the query is an update query or not and sets their index in the order they were given.
29+
*
30+
* @param queries collection of input streams of queries
31+
* @return list of QueryData objects
32+
*/
1833
public static List<QueryData> generate(Collection<InputStream> queries) {
1934
final var queryData = new ArrayList<QueryData>();
2035
int i = 0;
@@ -25,8 +40,31 @@ public static List<QueryData> generate(Collection<InputStream> queries) {
2540
} catch (Exception e) {
2641
update = false;
2742
}
28-
queryData.add(new QueryData(i++, update));
43+
queryData.add(new QueryData(i++, update ? QueryType.UPDATE : QueryType.DEFAULT, null));
44+
try {
45+
query.close();
46+
} catch (IOException ignored) {}
2947
}
3048
return queryData;
3149
}
50+
51+
/**
52+
* Checks if the given query is an update query.
53+
* The method uses the Jena library to check if the query is an update query.
54+
*
55+
* @param query input stream of the query
56+
* @return true if the query is an update query, false otherwise
57+
*/
58+
public static boolean checkIfUpdate(InputStream query) {
59+
try {
60+
UpdateFactory.read(query); // Throws an exception if the query is not an update query
61+
return true;
62+
} catch (Exception e) {
63+
return false;
64+
}
65+
}
66+
67+
public boolean update() {
68+
return type == QueryType.UPDATE;
69+
}
3270
}

0 commit comments

Comments
 (0)