diff options
Diffstat (limited to 'subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/FunctionalQueryTest.java')
-rw-r--r-- | subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/FunctionalQueryTest.java | 69 |
1 files changed, 28 insertions, 41 deletions
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/FunctionalQueryTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/FunctionalQueryTest.java index 723e9180..258127e7 100644 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/FunctionalQueryTest.java +++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/FunctionalQueryTest.java | |||
@@ -9,7 +9,6 @@ import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | |||
9 | import tools.refinery.store.map.Cursor; | 9 | import tools.refinery.store.map.Cursor; |
10 | import tools.refinery.store.model.ModelStore; | 10 | import tools.refinery.store.model.ModelStore; |
11 | import tools.refinery.store.query.ModelQueryAdapter; | 11 | import tools.refinery.store.query.ModelQueryAdapter; |
12 | import tools.refinery.store.query.dnf.Dnf; | ||
13 | import tools.refinery.store.query.dnf.Query; | 12 | import tools.refinery.store.query.dnf.Query; |
14 | import tools.refinery.store.query.term.Variable; | 13 | import tools.refinery.store.query.term.Variable; |
15 | import tools.refinery.store.query.viatra.tests.QueryEngineTest; | 14 | import tools.refinery.store.query.viatra.tests.QueryEngineTest; |
@@ -40,7 +39,7 @@ class FunctionalQueryTest { | |||
40 | private static final Symbol<Integer> age = Symbol.of("age", 1, Integer.class); | 39 | private static final Symbol<Integer> age = Symbol.of("age", 1, Integer.class); |
41 | private static final Symbol<TruthValue> friend = Symbol.of("friend", 2, TruthValue.class, TruthValue.FALSE); | 40 | private static final Symbol<TruthValue> friend = Symbol.of("friend", 2, TruthValue.class, TruthValue.FALSE); |
42 | private static final AnySymbolView personView = new KeyOnlyView<>(person); | 41 | private static final AnySymbolView personView = new KeyOnlyView<>(person); |
43 | private static final AnySymbolView ageView = new FunctionView<>(age); | 42 | private static final FunctionView<Integer> ageView = new FunctionView<>(age); |
44 | private static final AnySymbolView friendMustView = new FilteredView<>(friend, "must", TruthValue::must); | 43 | private static final AnySymbolView friendMustView = new FilteredView<>(friend, "must", TruthValue::must); |
45 | 44 | ||
46 | @QueryEngineTest | 45 | @QueryEngineTest |
@@ -80,17 +79,13 @@ class FunctionalQueryTest { | |||
80 | 79 | ||
81 | @QueryEngineTest | 80 | @QueryEngineTest |
82 | void predicateTest(QueryEvaluationHint hint) { | 81 | void predicateTest(QueryEvaluationHint hint) { |
83 | var subQuery = Dnf.of("SubQuery", builder -> { | 82 | var subQuery = Query.of("SubQuery", Integer.class, (builder, p1, x) -> builder.clause( |
84 | var p1 = builder.parameter("p1"); | 83 | personView.call(p1), |
85 | var x = builder.parameter("x", Integer.class); | 84 | ageView.call(p1, x) |
86 | builder.clause( | 85 | )); |
87 | personView.call(p1), | ||
88 | ageView.call(p1, x) | ||
89 | ); | ||
90 | }); | ||
91 | var query = Query.of("Predicate", Integer.class, (builder, p1, output) -> builder.clause( | 86 | var query = Query.of("Predicate", Integer.class, (builder, p1, output) -> builder.clause( |
92 | personView.call(p1), | 87 | personView.call(p1), |
93 | subQuery.call(p1, output) | 88 | output.assign(subQuery.call(p1)) |
94 | )); | 89 | )); |
95 | 90 | ||
96 | var store = ModelStore.builder() | 91 | var store = ModelStore.builder() |
@@ -198,15 +193,11 @@ class FunctionalQueryTest { | |||
198 | 193 | ||
199 | @QueryEngineTest | 194 | @QueryEngineTest |
200 | void predicateCountTest(QueryEvaluationHint hint) { | 195 | void predicateCountTest(QueryEvaluationHint hint) { |
201 | var subQuery = Dnf.of("SubQuery", builder -> { | 196 | var subQuery = Query.of("SubQuery", (builder, p1, p2) -> builder.clause( |
202 | var p1 = builder.parameter("p1"); | ||
203 | var p2 = builder.parameter("p2"); | ||
204 | builder.clause( | ||
205 | personView.call(p1), | 197 | personView.call(p1), |
206 | personView.call(p2), | 198 | personView.call(p2), |
207 | friendMustView.call(p1, p2) | 199 | friendMustView.call(p1, p2) |
208 | ); | 200 | )); |
209 | }); | ||
210 | var query = Query.of("Count", Integer.class, (builder, p1, output) -> builder.clause( | 201 | var query = Query.of("Count", Integer.class, (builder, p1, output) -> builder.clause( |
211 | personView.call(p1), | 202 | personView.call(p1), |
212 | output.assign(subQuery.count(p1, Variable.of())) | 203 | output.assign(subQuery.count(p1, Variable.of())) |
@@ -244,8 +235,9 @@ class FunctionalQueryTest { | |||
244 | 235 | ||
245 | @QueryEngineTest | 236 | @QueryEngineTest |
246 | void inputKeyAggregationTest(QueryEvaluationHint hint) { | 237 | void inputKeyAggregationTest(QueryEvaluationHint hint) { |
247 | var query = Query.of("Aggregate", Integer.class, (builder, output) -> builder.clause(Integer.class, | 238 | var query = Query.of("Aggregate", Integer.class, (builder, output) -> builder.clause( |
248 | (y) -> List.of(output.assign(ageView.aggregate(y, INT_SUM, Variable.of(), y))))); | 239 | output.assign(ageView.aggregate(INT_SUM, Variable.of())) |
240 | )); | ||
249 | 241 | ||
250 | var store = ModelStore.builder() | 242 | var store = ModelStore.builder() |
251 | .symbols(age) | 243 | .symbols(age) |
@@ -268,16 +260,13 @@ class FunctionalQueryTest { | |||
268 | 260 | ||
269 | @QueryEngineTest | 261 | @QueryEngineTest |
270 | void predicateAggregationTest(QueryEvaluationHint hint) { | 262 | void predicateAggregationTest(QueryEvaluationHint hint) { |
271 | var subQuery = Dnf.of("SubQuery", builder -> { | 263 | var subQuery = Query.of("SubQuery", Integer.class, (builder, p1, x) -> builder.clause( |
272 | var p1 = builder.parameter("p1"); | 264 | personView.call(p1), |
273 | var x = builder.parameter("x", Integer.class); | 265 | ageView.call(p1, x) |
274 | builder.clause( | 266 | )); |
275 | personView.call(p1), | 267 | var query = Query.of("Aggregate", Integer.class, (builder, output) -> builder.clause( |
276 | ageView.call(p1, x) | 268 | output.assign(subQuery.aggregate(INT_SUM, Variable.of())) |
277 | ); | 269 | )); |
278 | }); | ||
279 | var query = Query.of("Aggregate", Integer.class, (builder, output) -> builder.clause(Integer.class, | ||
280 | (y) -> List.of(output.assign(subQuery.aggregate(y, INT_SUM, Variable.of(), y))))); | ||
281 | 270 | ||
282 | var store = ModelStore.builder() | 271 | var store = ModelStore.builder() |
283 | .symbols(person, age) | 272 | .symbols(person, age) |
@@ -304,18 +293,16 @@ class FunctionalQueryTest { | |||
304 | 293 | ||
305 | @QueryEngineTest | 294 | @QueryEngineTest |
306 | void extremeValueTest(QueryEvaluationHint hint) { | 295 | void extremeValueTest(QueryEvaluationHint hint) { |
307 | var subQuery = Dnf.of("SubQuery", builder -> { | 296 | var subQuery = Query.of("SubQuery", Integer.class, (builder, p1, x) -> builder.clause( |
308 | var p1 = builder.parameter("p1"); | 297 | personView.call(p1), |
309 | var x = builder.parameter("x", Integer.class); | 298 | x.assign(friendMustView.count(p1, Variable.of())) |
310 | builder.clause( | 299 | )); |
311 | personView.call(p1), | 300 | var minQuery = Query.of("Min", Integer.class, (builder, output) -> builder.clause( |
312 | x.assign(friendMustView.count(p1, Variable.of())) | 301 | output.assign(subQuery.aggregate(INT_MIN, Variable.of())) |
313 | ); | 302 | )); |
314 | }); | 303 | var maxQuery = Query.of("Max", Integer.class, (builder, output) -> builder.clause( |
315 | var minQuery = Query.of("Min", Integer.class, (builder, output) -> builder.clause(Integer.class, | 304 | output.assign(subQuery.aggregate(INT_MAX, Variable.of())) |
316 | (y) -> List.of(output.assign(subQuery.aggregate(y, INT_MIN, Variable.of(), y))))); | 305 | )); |
317 | var maxQuery = Query.of("Max", Integer.class, (builder, output) -> builder.clause(Integer.class, | ||
318 | (y) -> List.of(output.assign(subQuery.aggregate(y, INT_MAX, Variable.of(), y))))); | ||
319 | 306 | ||
320 | var store = ModelStore.builder() | 307 | var store = ModelStore.builder() |
321 | .symbols(person, friend) | 308 | .symbols(person, friend) |