Skip to content

Commit bd2efd5

Browse files
no invex dependency, capabilities enable invex, indices create or drop
1 parent d0e7e85 commit bd2efd5

6 files changed

Lines changed: 62 additions & 27 deletions

File tree

atic-sqlite/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,6 @@
123123
<version>2.6</version>
124124
</dependency>
125125

126-
<!-- invex -->
127-
<dependency>
128-
<groupId>de.dfki.sds.invex</groupId>
129-
<artifactId>invex</artifactId>
130-
<version>1.0-SNAPSHOT</version>
131-
<optional>true</optional>
132-
</dependency>
133-
134126
</dependencies>
135127

136128
<build>

atic-sqlite/src/main/java/de/dfki/sds/aticsqlite/Capabilities.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ public final class Capabilities {
99

1010
private final boolean rdfStarEnabled;
1111
private final boolean propertyTypeAware;
12+
private final boolean invexEnabled;
1213

1314
private Capabilities(Builder builder) {
1415
this.rdfStarEnabled = builder.rdfStarEnabled;
1516
this.propertyTypeAware = builder.propertyTypeAware;
17+
this.invexEnabled = builder.invexEnabled;
1618
}
1719

1820
public boolean isRdfStarEnabled() {
@@ -23,6 +25,10 @@ public boolean isPropertyTypeAware() {
2325
return propertyTypeAware;
2426
}
2527

28+
public boolean isInvexEnabled() {
29+
return invexEnabled;
30+
}
31+
2632
public static Builder builder() {
2733
return new Builder();
2834
}
@@ -33,6 +39,7 @@ public static final class Builder {
3339

3440
private boolean rdfStarEnabled = true;
3541
private boolean propertyTypeAware = false;
42+
private boolean invexEnabled = false;
3643

3744
private Builder() {
3845
}
@@ -46,6 +53,11 @@ public Builder propertyTypeAware(boolean enabled) {
4653
this.propertyTypeAware = enabled;
4754
return this;
4855
}
56+
57+
public Builder invexEnabled(boolean enabled) {
58+
this.invexEnabled = enabled;
59+
return this;
60+
}
4961

5062
public Capabilities build() {
5163
return new Capabilities(this);

atic-sqlite/src/main/java/de/dfki/sds/aticsqlite/SqliteAticDatasetGraph.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ private void bootstrap() {
219219
});
220220

221221
bootstrapSparqlFunctions();
222+
223+
bootstrapInvex();
222224

223225
this.executeWrite(() -> {
224226
try {
@@ -228,7 +230,7 @@ private void bootstrap() {
228230
}
229231
});
230232

231-
bootstrapInvex();
233+
232234
}
233235

234236
/**
@@ -404,7 +406,12 @@ private void bootstrapIndices() throws SQLException {
404406
// loop through definitions
405407
for (int i = 0; i < arr.length(); i++) {
406408
JSONObject idx = arr.getJSONObject(i);
407-
String sql = idx.getString("sql");
409+
410+
boolean load = !isInvexAvailable() || idx.optBoolean("essential", false);
411+
412+
String key = load ? "create" : "drop";
413+
414+
String sql = idx.getString(key);
408415
db.write(sql);
409416
}
410417
}
@@ -471,6 +478,9 @@ private void bootstrapVirtualGraphs() throws SQLException {
471478
}
472479

473480
private void bootstrapInvex() {
481+
if(!capabilities.isInvexEnabled())
482+
return;
483+
474484
ExternalComponents externalComponents = new ExternalComponents();
475485
externalComponents.setNormalizer(new Normalizer() {
476486
@Override
@@ -497,7 +507,6 @@ public String normalizeText(String text) {
497507
} catch (Throwable e) {
498508
// INVEX is optional; leave invexEmbedded as null.
499509
}
500-
501510
}
502511

503512
/**
@@ -514,13 +523,21 @@ public String normalizeText(String text) {
514523
//invex
515524

516525
public AticQueryResults initializeQuery(QueryOptions options) throws Exception {
526+
if(!isInvexAvailable()) {
527+
throw new IllegalStateException("Invex not loaded");
528+
}
529+
517530
QueryResults queryResults = invexEmbedded.initializeQuery(options);
518531

519532
AticQueryResults aticQueryResults = AticQueryResults.builder(queryResults).build();
520533
return aticQueryResults;
521534
}
522535

523536
public AticQueryResults proceedWithQuery(String queryProcessId) throws Exception {
537+
if(!isInvexAvailable()) {
538+
throw new IllegalStateException("Invex not loaded");
539+
}
540+
524541
QueryResults queryResults = invexEmbedded.proceedWithQuery(queryProcessId);
525542

526543
long[] foundResourceIds = queryResults.getFoundResourceIDs();
@@ -532,7 +549,10 @@ public AticQueryResults proceedWithQuery(String queryProcessId) throws Exception
532549
}
533550

534551
public void rebuildInvex() throws Exception {
535-
552+
if(!isInvexAvailable()) {
553+
throw new IllegalStateException("Invex not loaded");
554+
}
555+
536556
File dbFile = new File(this.db.getOptions().getDbFilePath());
537557

538558
Path tempDir = Files.createTempDirectory("invex-rebuild-");
Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,54 @@
11
[
22
{
33
"name": "idx_resource",
4-
"sql": "CREATE INDEX IF NOT EXISTS idx_resource ON resource_uri(uri, id);"
4+
"create": "CREATE INDEX IF NOT EXISTS idx_resource ON resource_uri(uri, id);",
5+
"drop": "DROP INDEX IF EXISTS idx_resource;",
6+
"essential": true
57
},
68
{
79
"name": "idx_property",
8-
"sql": "CREATE INDEX IF NOT EXISTS idx_property ON property(uri, id);"
10+
"create": "CREATE INDEX IF NOT EXISTS idx_property ON property(uri, id);",
11+
"drop": "DROP INDEX IF EXISTS idx_property;",
12+
"essential": true
913
},
10-
1114
{
1215
"name": "idx_gspo",
13-
"sql": "CREATE INDEX IF NOT EXISTS idx_splg_gspl ON splg(g, p);"
16+
"create": "CREATE INDEX IF NOT EXISTS idx_splg_splg ON splg(g, p);",
17+
"drop": "DROP INDEX IF EXISTS idx_splg_splg;"
1418
},
1519
{
1620
"name": "idx_gpos",
17-
"sql": "CREATE INDEX IF NOT EXISTS idx_splg_gpls ON splg(g, lex);"
21+
"create": "CREATE INDEX IF NOT EXISTS idx_splg_gpls ON splg(g, lex);",
22+
"drop": "DROP INDEX IF EXISTS idx_splg_gpls;"
1823
},
1924
{
2025
"name": "idx_gosp",
21-
"sql": "CREATE INDEX IF NOT EXISTS idx_splg_glsp ON splg(g, s, lex);"
26+
"create": "CREATE INDEX IF NOT EXISTS idx_splg_glsp ON splg(g, s, lex);",
27+
"drop": "DROP INDEX IF EXISTS idx_splg_glsp;"
2228
},
2329
{
24-
"name": "idx_gosp",
25-
"sql": "CREATE INDEX IF NOT EXISTS idx_splg_glsp ON splg(g, p, lex);"
30+
"name": "idx_gosp_gp",
31+
"create": "CREATE INDEX IF NOT EXISTS idx_splg_gp ON splg(g, p, lex);",
32+
"drop": "DROP INDEX IF EXISTS idx_splg_gp;"
2633
},
27-
2834
{
2935
"name": "idx_spog_gp",
30-
"sql": "CREATE INDEX IF NOT EXISTS idx_spog_gp ON spog(g, p);"
36+
"create": "CREATE INDEX IF NOT EXISTS idx_spog_gp ON spog(g, p);",
37+
"drop": "DROP INDEX IF EXISTS idx_spog_gp;"
3138
},
3239
{
3340
"name": "idx_spog_go",
34-
"sql": "CREATE INDEX IF NOT EXISTS idx_spog_go ON spog(g, o);"
41+
"create": "CREATE INDEX IF NOT EXISTS idx_spog_go ON spog(g, o);",
42+
"drop": "DROP INDEX IF EXISTS idx_spog_go;"
3543
},
3644
{
3745
"name": "idx_spog_so",
38-
"sql": "CREATE INDEX IF NOT EXISTS idx_spog_so ON spog(g, s, o);"
46+
"create": "CREATE INDEX IF NOT EXISTS idx_spog_so ON spog(g, s, o);",
47+
"drop": "DROP INDEX IF EXISTS idx_spog_so;"
3948
},
4049
{
4150
"name": "idx_spog_po",
42-
"sql": "CREATE INDEX IF NOT EXISTS idx_spog_po ON spog(g, p, o);"
51+
"create": "CREATE INDEX IF NOT EXISTS idx_spog_po ON spog(g, p, o);",
52+
"drop": "DROP INDEX IF EXISTS idx_spog_po;"
4353
}
4454
]

atic-sqlite/src/test/java/de/dfki/sds/aticsqlite/InvexUnitTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class InvexUnitTest {
2727
@BeforeEach
2828
void setup(@TempDir Path tempDir) throws Exception {
2929
System.out.println(tempDir);
30-
dataset = TL.createDatasetGraph(tempDir);
30+
dataset = TL.createDatasetGraph(tempDir, Capabilities.builder().invexEnabled(true).build());
3131
}
3232

3333
static boolean isInvexOnClasspath() {
@@ -99,6 +99,7 @@ public void testRoundtrip() {
9999
});
100100

101101
assertTrue(results.isQueryAccepted());
102+
assertTrue(results.isSuccess());
102103

103104
assertEquals(2, results.getFoundNodes().size());
104105

atic-sqlite/src/test/java/de/dfki/sds/aticsqlite/PropertyTypeUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class PropertyTypeUnitTest {
2929

3030
@BeforeEach
3131
void setup(@org.junit.jupiter.api.io.TempDir Path tempDir) throws Exception {
32-
System.out.println(tempDir);
32+
//System.out.println(tempDir);
3333

3434
Path enabledPath = tempDir.resolve("enabled");
3535
Files.createDirectories(enabledPath);

0 commit comments

Comments
 (0)