Smalyshev has uploaded a new change for review.
https://gerrit.wikimedia.org/r/264850
Change subject: updates for Blazegraph 2.0
......................................................................
updates for Blazegraph 2.0
Change-Id: I4015692f70ef553f19614ca70156663cf5e0e19f
---
M blazegraph/pom.xml
M
blazegraph/src/main/java/com/bigdata/rdf/internal/NormalizingInlineUriHandler.java
M
blazegraph/src/main/java/com/bigdata/rdf/internal/TrailingSlashRemovingInlineUriHandler.java
M
blazegraph/src/main/java/org/wikidata/query/rdf/blazegraph/WikibaseExtensionFactory.java
M
blazegraph/src/main/java/org/wikidata/query/rdf/blazegraph/WikibaseInlineUriFactory.java
M
blazegraph/src/main/java/org/wikidata/query/rdf/blazegraph/inline/literal/WikibaseDateExtension.java
M
blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/AbstractRandomizedBlazegraphStorageTestCase.java
M
blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/AbstractRandomizedBlazegraphTestBase.java
A
blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/WikibaseDateUnitTest.java
M
blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/WikibaseVocabularyUnitTest.java
M common/pom.xml
M dist/pom.xml
M pom.xml
M testTools/pom.xml
M tools/pom.xml
M war/pom.xml
M war/src/assembly/dist.xml
17 files changed, 101 insertions(+), 62 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/rdf
refs/changes/50/264850/1
diff --git a/blazegraph/pom.xml b/blazegraph/pom.xml
index a415711..24272e7 100644
--- a/blazegraph/pom.xml
+++ b/blazegraph/pom.xml
@@ -4,7 +4,7 @@
<parent>
<groupId>org.wikidata.query.rdf</groupId>
<artifactId>parent</artifactId>
- <version>0.1.2-SNAPSHOT</version>
+ <version>0.2.0-SNAPSHOT</version>
</parent>
<artifactId>blazegraph</artifactId>
<packaging>jar</packaging>
@@ -20,8 +20,8 @@
<dependencies>
<dependency>
- <groupId>com.bigdata</groupId>
- <artifactId>bigdata</artifactId>
+ <groupId>com.blazegraph</groupId>
+ <artifactId>bigdata-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
diff --git
a/blazegraph/src/main/java/com/bigdata/rdf/internal/NormalizingInlineUriHandler.java
b/blazegraph/src/main/java/com/bigdata/rdf/internal/NormalizingInlineUriHandler.java
index e617225..3aae2ac 100644
---
a/blazegraph/src/main/java/com/bigdata/rdf/internal/NormalizingInlineUriHandler.java
+++
b/blazegraph/src/main/java/com/bigdata/rdf/internal/NormalizingInlineUriHandler.java
@@ -1,8 +1,5 @@
package com.bigdata.rdf.internal;
-import java.util.Arrays;
-import java.util.List;
-
import org.openrdf.model.URI;
import com.bigdata.rdf.internal.impl.literal.AbstractLiteralIV;
@@ -19,50 +16,36 @@
* The wrapped handler to which everything is delegated once normalized.
*/
private final InlineURIHandler next;
- /**
- * Prefixes that should be recognized as valid prefixes for this uri but
are
- * not its canonical form.
- */
- private final List<String> normalizedPrefixes;
/**
* Build the handler.
*
* @param next the handler to which to send all normalized localNames
- * @param normalizedPrefixes prefixes that should be recognized as valid
- * prefixes for this uri but are not its canonical form.
+ * @param normalizedPrefix prefix that should be recognized as valid
+ * prefix for this uri but is not its canonical form.
*/
- public NormalizingInlineUriHandler(InlineURIHandler next, String...
normalizedPrefixes) {
- this(next, Arrays.asList(normalizedPrefixes));
- }
-
- public NormalizingInlineUriHandler(InlineURIHandler next, List<String>
normalizedPrefixes) {
- super(next.getNamespace());
+ public NormalizingInlineUriHandler(InlineURIHandler next, String
normalizedPrefix) {
+ super(normalizedPrefix);
this.next = next;
- this.normalizedPrefixes = normalizedPrefixes;
}
@Override
public void init(Vocabulary vocab) {
- super.init(vocab);
+ // Skip init() since we have no vocab entry for our namespace
+// super.init(vocab);
next.init(vocab);
}
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
protected URIExtensionIV createInlineIV(URI uri) {
- if (namespaceIV == null) {
- // Can't do anything without a namespace.
- return null;
- }
- for (String prefix : normalizedPrefixes) {
- if (uri.stringValue().startsWith(prefix)) {
- AbstractLiteralIV localNameIv =
next.createInlineIV(uri.stringValue().substring(prefix.length()));
- if (localNameIv == null) {
- return null;
- }
- return new URIExtensionIV(localNameIv, namespaceIV);
+ String prefix = getNamespace();
+ if (uri.stringValue().startsWith(prefix)) {
+ AbstractLiteralIV localNameIv =
next.createInlineIV(uri.stringValue().substring(prefix.length()));
+ if (localNameIv == null) {
+ return null;
}
+ return new URIExtensionIV(localNameIv, next.namespaceIV);
}
return next.createInlineIV(uri);
}
diff --git
a/blazegraph/src/main/java/com/bigdata/rdf/internal/TrailingSlashRemovingInlineUriHandler.java
b/blazegraph/src/main/java/com/bigdata/rdf/internal/TrailingSlashRemovingInlineUriHandler.java
index 71f881f..02bf938 100644
---
a/blazegraph/src/main/java/com/bigdata/rdf/internal/TrailingSlashRemovingInlineUriHandler.java
+++
b/blazegraph/src/main/java/com/bigdata/rdf/internal/TrailingSlashRemovingInlineUriHandler.java
@@ -14,7 +14,7 @@
private final InlineURIHandler next;
public TrailingSlashRemovingInlineUriHandler(InlineURIHandler next) {
- super(next.namespace);
+ super(next.getNamespace());
this.next = next;
}
diff --git
a/blazegraph/src/main/java/org/wikidata/query/rdf/blazegraph/WikibaseExtensionFactory.java
b/blazegraph/src/main/java/org/wikidata/query/rdf/blazegraph/WikibaseExtensionFactory.java
index b727906..41ce5c3 100644
---
a/blazegraph/src/main/java/org/wikidata/query/rdf/blazegraph/WikibaseExtensionFactory.java
+++
b/blazegraph/src/main/java/org/wikidata/query/rdf/blazegraph/WikibaseExtensionFactory.java
@@ -3,6 +3,8 @@
import java.util.Collection;
import java.util.Iterator;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
import org.wikidata.query.rdf.blazegraph.inline.literal.WikibaseDateExtension;
import com.bigdata.rdf.internal.DefaultExtensionFactory;
@@ -17,6 +19,8 @@
* Setup inline value extensions to Blazegraph for Wikidata.
*/
public class WikibaseExtensionFactory extends DefaultExtensionFactory {
+ // private static final Logger log =
LoggerFactory.getLogger(WikibaseExtensionFactory.class);
+
@Override
@SuppressWarnings("rawtypes")
protected void _init(IDatatypeURIResolver resolver,
ILexiconConfiguration<BigdataValue> config,
@@ -29,6 +33,7 @@
}
}
extensions.add(new
WikibaseDateExtension<BigdataLiteral>(resolver));
+ // log.warn("Installed Wikidata date extensions");
}
}
}
diff --git
a/blazegraph/src/main/java/org/wikidata/query/rdf/blazegraph/WikibaseInlineUriFactory.java
b/blazegraph/src/main/java/org/wikidata/query/rdf/blazegraph/WikibaseInlineUriFactory.java
index a9298db..cb65723 100644
---
a/blazegraph/src/main/java/org/wikidata/query/rdf/blazegraph/WikibaseInlineUriFactory.java
+++
b/blazegraph/src/main/java/org/wikidata/query/rdf/blazegraph/WikibaseInlineUriFactory.java
@@ -6,6 +6,7 @@
import org.wikidata.query.rdf.common.uri.WikibaseUris.PropertyType;
import com.bigdata.rdf.internal.InlineURIFactory;
+import com.bigdata.rdf.internal.InlineURIHandler;
import com.bigdata.rdf.internal.InlineUnsignedIntegerURIHandler;
import com.bigdata.rdf.internal.NormalizingInlineUriHandler;
import com.bigdata.rdf.internal.TrailingSlashRemovingInlineUriHandler;
@@ -45,8 +46,11 @@
addHandler(new InlineUnsignedIntegerURIHandler(uris.entity() + "Q"));
// These aren't part of wikibase but are common in wikidata
- addHandler(new NormalizingInlineUriHandler(new
TrailingSlashRemovingInlineUriHandler(
- new InlineUnsignedIntegerURIHandler(CommonValues.VIAF)),
CommonValues.VIAF_HTTP));
+ // TODO: add more prefixes?
+ InlineURIHandler viaf = new TrailingSlashRemovingInlineUriHandler(
+ new InlineUnsignedIntegerURIHandler(CommonValues.VIAF));
+ addHandler(viaf);
+ addHandler(new NormalizingInlineUriHandler(viaf,
CommonValues.VIAF_HTTP));
/*
* Value nodes are inlined even though they are pretty big (uuids). It
diff --git
a/blazegraph/src/main/java/org/wikidata/query/rdf/blazegraph/inline/literal/WikibaseDateExtension.java
b/blazegraph/src/main/java/org/wikidata/query/rdf/blazegraph/inline/literal/WikibaseDateExtension.java
index e3385b8..b836999 100644
---
a/blazegraph/src/main/java/org/wikidata/query/rdf/blazegraph/inline/literal/WikibaseDateExtension.java
+++
b/blazegraph/src/main/java/org/wikidata/query/rdf/blazegraph/inline/literal/WikibaseDateExtension.java
@@ -138,6 +138,21 @@
return false;
}
+ /**
+ * Normalize IV - convert to LiteralExtension.
+ * @param l Original literal, will be parsed if IV is not inlined.
+ * @param iv Original IV
+ * @return Normalized IV, parsed through Wikidata if needed
+ */
+ @SuppressWarnings({"rawtypes", "checkstyle:cyclomaticcomplexity"})
+ private LiteralExtensionIV normalizeIV(Literal l, IV iv) {
+ if (iv instanceof LiteralExtensionIV) {
+ return (LiteralExtensionIV)iv;
+ } else {
+ return createIV(l);
+ }
+ }
+
@SuppressWarnings({"rawtypes", "checkstyle:cyclomaticcomplexity"})
@Override
public IV doMathOp(
@@ -156,28 +171,23 @@
throw new SparqlTypeErrorException();
}
- if (d1 && !(iv1 instanceof LiteralExtensionIV)) {
- throw new IllegalArgumentException("Non-extended data passed to
extension");
- }
-
- if (d2 && !(iv2 instanceof LiteralExtensionIV)) {
- throw new IllegalArgumentException("Non-extended data passed to
extension");
- }
+ LiteralExtensionIV liv1 = d1 ? normalizeIV(l1, iv1) : null;
+ LiteralExtensionIV liv2 = d2 ? normalizeIV(l2, iv2) : null;
if (d1 && d2) {
- return handleTwoDates((LiteralExtensionIV)iv1,
(LiteralExtensionIV)iv2, op, vf);
+ return handleTwoDates(liv1, liv2, op, vf);
}
// Now we have one date and one duration
if (op == MathOp.PLUS) {
- LiteralExtensionIV iv = d1 ? (LiteralExtensionIV)iv1 :
(LiteralExtensionIV)iv2;
+ LiteralExtensionIV iv = d1 ? liv1 : liv2;
Literal lduration = d1 ? l2 : l1;
return datePlusDuration(iv,
DATATYPE_FACTORY.newDuration(lduration.getLabel()));
}
if (op == MathOp.MINUS) {
- return datePlusDuration((LiteralExtensionIV)iv1,
+ return datePlusDuration(liv1,
DATATYPE_FACTORY.newDuration(l2.getLabel()).negate());
}
diff --git
a/blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/AbstractRandomizedBlazegraphStorageTestCase.java
b/blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/AbstractRandomizedBlazegraphStorageTestCase.java
index 567e536..f261b4d 100644
---
a/blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/AbstractRandomizedBlazegraphStorageTestCase.java
+++
b/blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/AbstractRandomizedBlazegraphStorageTestCase.java
@@ -78,6 +78,8 @@
WikibaseVocabulary.V001.class.getName());
properties.setProperty("com.bigdata.rdf.store.AbstractTripleStore.inlineURIFactory",
WikibaseInlineUriFactory.class.getName());
+
properties.setProperty("com.bigdata.rdf.store.AbstractTripleStore.extensionFactoryClass",
+ WikibaseExtensionFactory.class.getName());
store = new TempTripleStore(temporaryStore(), properties, null);
return store;
}
@@ -93,7 +95,7 @@
}
ExecutorService executorService = temporaryStore.getExecutorService();
temporaryStore.close();
- QueryEngine queryEngine =
QueryEngineFactory.getExistingQueryController(temporaryStore);
+ QueryEngine queryEngine =
QueryEngineFactory.getInstance().getExistingQueryController(temporaryStore);
if (queryEngine != null) {
queryEngine.shutdownNow();
}
diff --git
a/blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/AbstractRandomizedBlazegraphTestBase.java
b/blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/AbstractRandomizedBlazegraphTestBase.java
index 18b7a4a..00debf1 100644
---
a/blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/AbstractRandomizedBlazegraphTestBase.java
+++
b/blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/AbstractRandomizedBlazegraphTestBase.java
@@ -44,9 +44,9 @@
*/
protected TupleQueryResult query(String query) {
try {
- ASTContainer astContainer = new
Bigdata2ASTSPARQLParser(store()).parseQuery2(query, null);
+ ASTContainer astContainer = new
Bigdata2ASTSPARQLParser().parseQuery2(query, null);
- return ASTEvalHelper.evaluateTupleQuery(store(), astContainer, new
QueryBindingSet());
+ return ASTEvalHelper.evaluateTupleQuery(store(), astContainer, new
QueryBindingSet(), null);
} catch (MalformedQueryException | QueryEvaluationException e) {
throw new RuntimeException(e);
}
diff --git
a/blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/WikibaseDateUnitTest.java
b/blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/WikibaseDateUnitTest.java
new file mode 100644
index 0000000..43090e5
--- /dev/null
+++
b/blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/WikibaseDateUnitTest.java
@@ -0,0 +1,34 @@
+package org.wikidata.query.rdf.blazegraph;
+
+import static org.hamcrest.Matchers.instanceOf;
+import static org.wikidata.query.rdf.test.Matchers.binds;
+
+import org.junit.Test;
+import org.openrdf.model.impl.LiteralImpl;
+import org.openrdf.model.vocabulary.XMLSchema;
+import org.openrdf.query.BindingSet;
+import org.openrdf.query.QueryEvaluationException;
+import org.openrdf.query.TupleQueryResult;
+import org.wikidata.query.rdf.common.uri.Ontology;
+
+import com.bigdata.rdf.internal.impl.literal.LiteralExtensionIV;
+import com.bigdata.rdf.model.BigdataStatement;
+
+public class WikibaseDateUnitTest extends AbstractRandomizedBlazegraphTestBase
{
+
+ @Test
+ public void dateExtension() {
+ BigdataStatement statement = roundTrip(Ontology.Time.VALUE,
Ontology.Time.VALUE,
+ new LiteralImpl("-0101-01-01T00:00:00", XMLSchema.DATE));
+ assertThat(statement.getObject().getIV(),
instanceOf(LiteralExtensionIV.class));
+ }
+
+ @Test
+ public void dateExtentsionQuery() throws QueryEvaluationException {
+ TupleQueryResult results = query("SELECT * WHERE {BIND (
\"0001-01-01T00:00:00\"^^xsd:dateTime - \"-0001-01-01T00:00:00\"^^xsd:dateTime
AS ?date)}");
+ BindingSet result = results.next();
+ // 731 days or 2 years since XML 1.1 has year 0 (which is 1BCE)
+ assertThat(result, binds("date", new LiteralImpl("731.0",
XMLSchema.DOUBLE)));
+ }
+
+}
diff --git
a/blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/WikibaseVocabularyUnitTest.java
b/blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/WikibaseVocabularyUnitTest.java
index c8f08a9..3210fc2 100644
---
a/blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/WikibaseVocabularyUnitTest.java
+++
b/blazegraph/src/test/java/org/wikidata/query/rdf/blazegraph/WikibaseVocabularyUnitTest.java
@@ -134,4 +134,5 @@
assertThat(statement.getPredicate().getIV(),
instanceOf(VocabURIByteIV.class));
assertThat(statement.getObject().getIV(),
instanceOf(VocabURIByteIV.class));
}
+
}
diff --git a/common/pom.xml b/common/pom.xml
index 427c0da..604f8c7 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -4,7 +4,7 @@
<parent>
<groupId>org.wikidata.query.rdf</groupId>
<artifactId>parent</artifactId>
- <version>0.1.2-SNAPSHOT</version>
+ <version>0.2.0-SNAPSHOT</version>
</parent>
<artifactId>common</artifactId>
<packaging>jar</packaging>
diff --git a/dist/pom.xml b/dist/pom.xml
index 412a4da..478a777 100644
--- a/dist/pom.xml
+++ b/dist/pom.xml
@@ -4,7 +4,7 @@
<parent>
<groupId>org.wikidata.query.rdf</groupId>
<artifactId>parent</artifactId>
- <version>0.1.2-SNAPSHOT</version>
+ <version>0.2.0-SNAPSHOT</version>
</parent>
<artifactId>service</artifactId>
<packaging>pom</packaging>
diff --git a/pom.xml b/pom.xml
index b287635..1dd345c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
</parent>
<groupId>org.wikidata.query.rdf</groupId>
<artifactId>parent</artifactId>
- <version>0.1.2-SNAPSHOT</version>
+ <version>0.2.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
@@ -57,7 +57,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <blazegraph.version>1.5.3</blazegraph.version>
+ <blazegraph.version>2.0.0-RC1</blazegraph.version>
<!-- This Blazegraph version has backports onto the 1.5.1 branch and is
hosted at WMF. Documentation on how to do that
is in the backport_blazegraph.txt file. -->
<sesame.version>2.8.1</sesame.version>
@@ -378,8 +378,8 @@
<version>${sesame.version}</version>
</dependency>
<dependency>
- <groupId>com.bigdata</groupId>
- <artifactId>bigdata</artifactId>
+ <groupId>com.blazegraph</groupId>
+ <artifactId>bigdata-core</artifactId>
<version>${blazegraph.version}</version>
</dependency>
<dependency>
diff --git a/testTools/pom.xml b/testTools/pom.xml
index ce693ba..0f337ba 100644
--- a/testTools/pom.xml
+++ b/testTools/pom.xml
@@ -4,7 +4,7 @@
<parent>
<groupId>org.wikidata.query.rdf</groupId>
<artifactId>parent</artifactId>
- <version>0.1.2-SNAPSHOT</version>
+ <version>0.2.0-SNAPSHOT</version>
</parent>
<artifactId>testTools</artifactId>
<packaging>jar</packaging>
diff --git a/tools/pom.xml b/tools/pom.xml
index 477fbd8..4740435 100644
--- a/tools/pom.xml
+++ b/tools/pom.xml
@@ -4,7 +4,7 @@
<parent>
<groupId>org.wikidata.query.rdf</groupId>
<artifactId>parent</artifactId>
- <version>0.1.2-SNAPSHOT</version>
+ <version>0.2.0-SNAPSHOT</version>
</parent>
<artifactId>tools</artifactId>
<packaging>jar</packaging>
@@ -133,8 +133,8 @@
<configuration>
<artifactItems>
<artifactItem>
- <groupId>com.bigdata</groupId>
- <artifactId>bigdata</artifactId>
+ <groupId>com.blazegraph</groupId>
+ <artifactId>bigdata-war</artifactId>
<version>${blazegraph.version}</version>
<type>war</type>
</artifactItem>
diff --git a/war/pom.xml b/war/pom.xml
index f172c61..e254075 100644
--- a/war/pom.xml
+++ b/war/pom.xml
@@ -4,7 +4,7 @@
<parent>
<groupId>org.wikidata.query.rdf</groupId>
<artifactId>parent</artifactId>
- <version>0.1.2-SNAPSHOT</version>
+ <version>0.2.0-SNAPSHOT</version>
</parent>
<artifactId>blazegraph-service</artifactId>
<packaging>pom</packaging>
@@ -21,8 +21,8 @@
<dependencies>
<dependency>
- <groupId>com.bigdata</groupId>
- <artifactId>bigdata</artifactId>
+ <groupId>com.blazegraph</groupId>
+ <artifactId>bigdata-war</artifactId>
<version>${blazegraph.version}</version>
<type>war</type>
</dependency>
diff --git a/war/src/assembly/dist.xml b/war/src/assembly/dist.xml
index 22177c6..50a7288 100644
--- a/war/src/assembly/dist.xml
+++ b/war/src/assembly/dist.xml
@@ -26,7 +26,7 @@
<outputDirectory></outputDirectory>
<unpack>true</unpack>
<includes>
- <include>com.bigdata:bigdata:war</include>
+ <include>com.blazegraph:bigdata-war:war</include>
</includes>
<unpackOptions>
<excludes>
--
To view, visit https://gerrit.wikimedia.org/r/264850
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4015692f70ef553f19614ca70156663cf5e0e19f
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/query/rdf
Gerrit-Branch: master
Gerrit-Owner: Smalyshev <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits