This repository was archived by the owner on Mar 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 185
Expand file tree
/
Copy pathTestSPOAccessPath.java
More file actions
408 lines (304 loc) · 14.6 KB
/
TestSPOAccessPath.java
File metadata and controls
408 lines (304 loc) · 14.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
/**
Copyright (C) SYSTAP, LLC 2006-2015. All rights reserved.
Contact:
SYSTAP, LLC
2501 Calvert ST NW #106
Washington, DC 20008
licenses@systap.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Created on Oct 25, 2007
*/
package com.bigdata.rdf.spo;
import org.openrdf.model.Statement;
import com.bigdata.bop.BOp;
import com.bigdata.bop.Constant;
import com.bigdata.bop.IPredicate;
import com.bigdata.bop.NV;
import com.bigdata.bop.Var;
import com.bigdata.rdf.internal.IV;
import com.bigdata.rdf.internal.MockTermIdFactory;
import com.bigdata.rdf.internal.VTE;
import com.bigdata.rdf.model.BigdataURI;
import com.bigdata.rdf.model.BigdataValueFactory;
import com.bigdata.rdf.model.StatementEnum;
import com.bigdata.rdf.rio.StatementBuffer;
import com.bigdata.rdf.store.AbstractTripleStore;
import com.bigdata.rdf.store.AbstractTripleStoreTestCase;
import com.bigdata.rdf.store.TestTripleStore;
import com.bigdata.relation.accesspath.AccessPath;
import com.bigdata.relation.accesspath.IAccessPath;
/**
* Test suite for {@link SPOAccessPath}.
* <p>
* See also {@link TestTripleStore} which tests some of this stuff.
*
* FIXME write tests for SLICE with non-zero offset and non-zero LIMIT.
*
* FIXME write tests for SLICE where the maximum fully buffered limit is
* exceeded so we are forced to use the asynchronous iterator on
* {@link AccessPath}.
*
* @author <a href="mailto:thompsonbry@users.sourceforge.net">Bryan Thompson</a>
* @version $Id$
*/
public class TestSPOAccessPath extends AbstractTripleStoreTestCase {
/**
*
*/
public TestSPOAccessPath() {
super();
}
/**
* @param name
*/
public TestSPOAccessPath(String name) {
super(name);
}
private MockTermIdFactory factory;
protected void setUp() throws Exception {
super.setUp();
factory = new MockTermIdFactory();
}
protected void tearDown() throws Exception {
super.tearDown();
factory = null;
}
/**
* There are 8 distinct triple pattern bindings for a triple store that
* select among 3 distinct access paths.
*/
public void test_getAccessPath() {
final AbstractTripleStore store = getStore();
// constants used for s,p,o,c when bound. 0L used when unbound.
final IV<?,?> S = factory.newTermId(VTE.URI, 1);
final IV<?,?> P = factory.newTermId(VTE.URI, 2);
final IV<?,?> O = factory.newTermId(VTE.URI, 3);
final IV<?,?> C = factory.newTermId(VTE.URI, 4);
final IV<?,?> _ = factory.newTermId(VTE.URI, 0);
try {
final SPORelation r = store.getSPORelation();
if (store.isQuads()) {
/*
* For a quad store there are 16 distinct binding patterns that
* select among 6 distinct access paths. there are some quad
* patterns which could be mapped onto more than one access
* path, but the code here checks the expected mapping. These
* mappings are similar to those in YARS2, but are the mappings
* generated by the "Magic" tuple logic.
*/
// SPOC
assertEquals(SPOKeyOrder.SPOC, r.getAccessPath(_, _, _, _).getKeyOrder());
assertEquals(SPOKeyOrder.SPOC, r.getAccessPath(S, _, _, _).getKeyOrder());
assertEquals(SPOKeyOrder.SPOC, r.getAccessPath(S, P, _, _).getKeyOrder());
assertEquals(SPOKeyOrder.SPOC, r.getAccessPath(S, P, O, _).getKeyOrder());
assertEquals(SPOKeyOrder.SPOC, r.getAccessPath(S, P, O, C).getKeyOrder());
// POCS
assertEquals(SPOKeyOrder.POCS, r.getAccessPath(_, P, _, _).getKeyOrder());
assertEquals(SPOKeyOrder.POCS, r.getAccessPath(_, P, O, _).getKeyOrder());
assertEquals(SPOKeyOrder.POCS, r.getAccessPath(_, P, O, C).getKeyOrder());
// OCSP
assertEquals(SPOKeyOrder.OCSP, r.getAccessPath(_, _, O, _).getKeyOrder());
assertEquals(SPOKeyOrder.OCSP, r.getAccessPath(_, _, O, C).getKeyOrder());
assertEquals(SPOKeyOrder.OCSP, r.getAccessPath(S, _, O, C).getKeyOrder());
// CSPO
assertEquals(SPOKeyOrder.CSPO, r.getAccessPath(_, _, _, C).getKeyOrder());
assertEquals(SPOKeyOrder.CSPO, r.getAccessPath(S, _, _, C).getKeyOrder());
assertEquals(SPOKeyOrder.CSPO, r.getAccessPath(S, P, _, C).getKeyOrder());
// PCSO
assertEquals(SPOKeyOrder.PCSO, r.getAccessPath(_, P, _, C).getKeyOrder());
// SOPC
assertEquals(SPOKeyOrder.SOPC, r.getAccessPath(S, _, O, _).getKeyOrder());
} else {
assertEquals(SPOKeyOrder.SPO, r.getAccessPath(NULL, NULL, NULL,
NULL).getKeyOrder());
assertEquals(SPOKeyOrder.SPO, r.getAccessPath(S, NULL, NULL,
NULL).getKeyOrder());
assertEquals(SPOKeyOrder.SPO, r.getAccessPath(S, S, NULL, NULL)
.getKeyOrder());
assertEquals(SPOKeyOrder.SPO, r.getAccessPath(S, S, S, NULL)
.getKeyOrder());
assertEquals(SPOKeyOrder.POS, r.getAccessPath(NULL, S, NULL,
NULL).getKeyOrder());
assertEquals(SPOKeyOrder.POS, r.getAccessPath(NULL, S, S, NULL)
.getKeyOrder());
assertEquals(SPOKeyOrder.OSP, r.getAccessPath(NULL, NULL, S,
NULL).getKeyOrder());
assertEquals(SPOKeyOrder.OSP, r.getAccessPath(S, NULL, S, NULL)
.getKeyOrder());
}
} finally {
store.__tearDownUnitTest();
}
}
/**
* Unit test for predicate patterns in which the same variable appears in
* more than one position of a triple pattern. The access path should
* enforce a constraint to ensure that only elements having the same value
* in each position for the same variable are visited by its iterator.
* <p>
* Note: This test applies to the triple store, provenance, and quad store
* modes.
*/
public void test_sameVariableConstraint_triples() {
final AbstractTripleStore store = getStore();
try {
final BigdataValueFactory f = store.getValueFactory();
final BigdataURI s1 = f.createURI("http://www.bigdata.com/rdf#s1");
final BigdataURI s2 = f.createURI("http://www.bigdata.com/rdf#s2");
final BigdataURI p1 = f.createURI("http://www.bigdata.com/rdf#p1");
final BigdataURI o1 = f.createURI("http://www.bigdata.com/rdf#o1");
final BigdataURI p2 = f.createURI("http://www.bigdata.com/rdf#p2");
final BigdataURI o2 = f.createURI("http://www.bigdata.com/rdf#o2");
{
final StatementBuffer<Statement> buffer = new StatementBuffer<Statement>(
store, 10);
buffer.add(s1, p1, o1);
buffer.add(s1, s1, o1);
buffer.add(s2, p2, o2);
buffer.add(s1, p2, o2);
buffer.flush();
}
// no shared variable (?g, ?h, o1)
{
final SPOPredicate predicate = new SPOPredicate(//
store.getSPORelation().getNamespace(),//
Var.var("g"), // s
Var.var("h"), // p
new Constant<IV>(o1.getIV()) // o
);
final IAccessPath<ISPO> accessPath = store.getSPORelation()
.getAccessPath(predicate);
assertSameSPOs(new ISPO[] { // FIXME TERMS REFACTOR FAILS HERE
new SPO(s1.getIV(), p1.getIV(), o1
.getIV(), StatementEnum.Explicit),//
new SPO(s1.getIV(), s1.getIV(), o1
.getIV(), StatementEnum.Explicit),//
}, accessPath.iterator());
}
// shared 'g' variable (?g, ?g, o1)
{
final SPOPredicate predicate = new SPOPredicate(//
store.getSPORelation().getNamespace(),//
Var.var("g"), // s
Var.var("g"), // s
new Constant<IV>(o1.getIV()) // o
);
final IAccessPath<ISPO> accessPath = store.getSPORelation()
.getAccessPath(predicate);
assertSameSPOs(new ISPO[] { //
new SPO(s1.getIV(), s1.getIV(), o1.getIV(),
StatementEnum.Explicit),//
}, accessPath.iterator());
}
} finally {
store.__tearDownUnitTest();
}
}
/**
* Unit test for predicate patterns in which the same variable appears in
* more than one position of a quad pattern. The access path should enforce
* a constraint to ensure that only elements having the same value in each
* position for the same variable are visited by its iterator.
* <p>
* Note: This test only applies to the quad store mode.
* <p>
* Note: In the provenance mode, it is impossible for a statement to use its
* own statement identifier in any position other than the quad position.
* Therefore any access path which was constrained such that s, p, or o used
* shared a variable with c would result in an empty access path in the
* data.
*/
public void test_sameVariableConstraint_quads() {
final AbstractTripleStore store = getStore();
try {
if(!store.isQuads()) {
/*
* @todo modify test to work for triple store also? This is easy
* enough to do with an (s,p,o) predicate in which s and o are
* or s and p bound to the same variable.
*/
log.warn("Unit test requires quads.");
return;
}
final BigdataValueFactory f = store.getValueFactory();
final BigdataURI graphA = f.createURI("http://www.bigdata.com/graphA");
final BigdataURI graphB = f.createURI("http://www.bigdata.com/graphB");
final BigdataURI s = f.createURI("http://www.bigdata.com/rdf#s");
final BigdataURI p1 = f.createURI("http://www.bigdata.com/rdf#p1");
final BigdataURI o1 = f.createURI("http://www.bigdata.com/rdf#o1");
final BigdataURI p2 = f.createURI("http://www.bigdata.com/rdf#p2");
final BigdataURI o2 = f.createURI("http://www.bigdata.com/rdf#o2");
{
final StatementBuffer<Statement> buffer = new StatementBuffer<Statement>(
store, 10);
buffer.add(graphA, p1, o1, graphA);
buffer.add(graphA, p2, o2, graphA);
buffer.add(s, p1, o1, graphA);
buffer.add(s, p2, o2, graphB);
buffer.flush();
}
// no shared variable (?g, p1, o1, ?h)
{
final SPOPredicate predicate = new SPOPredicate(//
new BOp[] { Var.var("g"), // s
new Constant<IV>(p1.getIV()), // p
new Constant<IV>(o1.getIV()), // o
Var.var("h") // c
}, new NV(IPredicate.Annotations.RELATION_NAME,
new String[] { store.getSPORelation()
.getNamespace() //
}));
final IAccessPath<ISPO> accessPath = store.getSPORelation()
.getAccessPath(predicate);
assertSameSPOs(new ISPO[] { //
new SPO(graphA.getIV(), p1.getIV(), o1
.getIV(), graphA.getIV(),
StatementEnum.Explicit),//
new SPO(s.getIV(), p1.getIV(), o1
.getIV(), graphA.getIV(),
StatementEnum.Explicit),//
}, accessPath.iterator());
}
// shared 'g' variable (?g, p1, o1, ?g)
{
final SPOPredicate predicate = new SPOPredicate(//
new BOp[] { Var.var("g"), // s
new Constant<IV>(p1.getIV()), // p
new Constant<IV>(o1.getIV()), // o
Var.var("g") // c
}, new NV(IPredicate.Annotations.RELATION_NAME,
new String[] { store.getSPORelation()
.getNamespace() }));
final IAccessPath<ISPO> accessPath = store.getSPORelation()
.getAccessPath(predicate);
assertSameSPOs(new ISPO[] { //
new SPO(graphA.getIV(), p1.getIV(), o1
.getIV(), graphA.getIV(),
StatementEnum.Explicit),//
}, accessPath.iterator());
}
} finally {
store.__tearDownUnitTest();
}
}
/**
* @todo write tests of slice where offset=0, offset>0. test with limit at
* fence posts (0,1) and with limit GT the maximum that can be fully
* buffered. verify stable result sets by using a slice to page
* through the results.
*/
public void test_slice() {
// fail("write tests");
}
}