Skip to content

Commit

Permalink
GH-4819 Merge Join (#4822)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmottestad authored Dec 20, 2023
2 parents c3df0af + 1e5c78c commit a6ec965
Show file tree
Hide file tree
Showing 195 changed files with 4,436 additions and 375 deletions.
6 changes: 6 additions & 0 deletions compliance/sparql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
<artifactId>jetty-webapp</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rdf4j-sail-extensible-store</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public void testVariableNameHandling() throws Exception {
assertTrue(tqr.hasNext());

List<BindingSet> result = QueryResults.asList(tqr);
assertTrue(result.size() > 0);
assertTrue(!result.isEmpty());
for (BindingSet bs : result) {
assertTrue(bs.hasBinding("val"));
assertTrue(bs.hasBinding("s"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2023 Eclipse RDF4J contributors.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
******************************************************************************/

package org.eclipse.rdf4j.sail.extensiblestore;

import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.dataset.DatasetRepository;
import org.eclipse.rdf4j.repository.sail.SailRepository;
import org.eclipse.rdf4j.sail.extensiblestore.impl.ExtensibleStoreOrderedImplForTests;
import org.eclipse.rdf4j.testsuite.query.parser.sparql.manifest.SPARQL11QueryComplianceTest;

public class ExtensibleStoreSPARQL11QueryComplianceTest extends SPARQL11QueryComplianceTest {

@Override
protected Repository newRepository() {
return new DatasetRepository(new SailRepository(new ExtensibleStoreOrderedImplForTests()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2023 Eclipse RDF4J contributors.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
******************************************************************************/

package org.eclipse.rdf4j.sail.extensiblestore;

import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.sail.SailRepository;
import org.eclipse.rdf4j.sail.extensiblestore.impl.ExtensibleStoreOrderedImplForTests;
import org.eclipse.rdf4j.testsuite.query.parser.sparql.manifest.SPARQL11UpdateComplianceTest;

/**
* Test SPARQL 1.1 Update functionality on an in-memory store.
*/
public class ExtensibleStoreSPARQL11UpdateComplianceTest extends SPARQL11UpdateComplianceTest {

@Override
protected Repository newRepository() {
return new SailRepository(new ExtensibleStoreOrderedImplForTests());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2023 Eclipse RDF4J contributors.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
******************************************************************************/

package org.eclipse.rdf4j.sail.extensiblestore.impl;

import org.eclipse.rdf4j.sail.extensiblestore.ExtensibleStoreConnection;

class ExtensibleStoreConnectionOrderedImplForTests
extends ExtensibleStoreConnection<ExtensibleStoreOrderedImplForTests> {
protected ExtensibleStoreConnectionOrderedImplForTests(ExtensibleStoreOrderedImplForTests sail) {
super(sail);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright (c) 2023 Eclipse RDF4J contributors.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
******************************************************************************/

package org.eclipse.rdf4j.sail.extensiblestore.impl;

import org.eclipse.rdf4j.common.annotation.InternalUseOnly;
import org.eclipse.rdf4j.query.algebra.evaluation.impl.EvaluationStatistics;
import org.eclipse.rdf4j.sail.NotifyingSailConnection;
import org.eclipse.rdf4j.sail.SailException;
import org.eclipse.rdf4j.sail.extensiblestore.ExtensibleStore;
import org.eclipse.rdf4j.sail.extensiblestore.SimpleMemoryNamespaceStore;

@InternalUseOnly
public class ExtensibleStoreOrderedImplForTests
extends ExtensibleStore<OrderedDataStructure, SimpleMemoryNamespaceStore> {

public ExtensibleStoreOrderedImplForTests() {
super(Cache.NONE);
}

public ExtensibleStoreOrderedImplForTests(Cache cache) {
super(cache);
}

@Override
protected synchronized void initializeInternal() throws SailException {
namespaceStore = new SimpleMemoryNamespaceStore();
dataStructure = new OrderedDataStructure();
super.initializeInternal();
}

@Override
protected NotifyingSailConnection getConnectionInternal() throws SailException {
return new ExtensibleStoreConnectionOrderedImplForTests(this);
}

@Override
public boolean isWritable() throws SailException {
return true;
}

public EvaluationStatistics getEvalStats() {
return sailStore.getEvaluationStatistics();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*******************************************************************************
* Copyright (c) 2023 Eclipse RDF4J contributors.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
******************************************************************************/

package org.eclipse.rdf4j.sail.extensiblestore.impl;

import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.eclipse.rdf4j.common.iteration.CloseableIteration;
import org.eclipse.rdf4j.common.iteration.CloseableIteratorIteration;
import org.eclipse.rdf4j.common.iteration.EmptyIteration;
import org.eclipse.rdf4j.common.order.StatementOrder;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.sail.extensiblestore.DataStructureInterface;
import org.eclipse.rdf4j.sail.extensiblestore.FilteringIteration;
import org.eclipse.rdf4j.sail.extensiblestore.SortedIteration;
import org.eclipse.rdf4j.sail.extensiblestore.valuefactory.ExtensibleStatement;

class OrderedDataStructure implements DataStructureInterface {

private static final EmptyIteration<ExtensibleStatement> EMPTY_ITERATION = new EmptyIteration<>();

Set<ExtensibleStatement> statements = Collections.newSetFromMap(new ConcurrentHashMap<>());

@Override
synchronized public void addStatement(ExtensibleStatement statement) {
statements.add(statement);
}

@Override
synchronized public void removeStatement(ExtensibleStatement statement) {
statements.remove(statement);

}

@Override
synchronized public CloseableIteration<? extends ExtensibleStatement> getStatements(Resource subject,
IRI predicate,
Value object, boolean inferred, Resource... context) {
return new FilteringIteration<>(
new CloseableIteratorIteration<>(statements.iterator()), subject, predicate, object, inferred, context);
}

@Override
public CloseableIteration<? extends ExtensibleStatement> getStatements(StatementOrder statementOrder,
Resource subject, IRI predicate, Value object, boolean inferred, Resource... contexts) {
if (statements.isEmpty()) {
return EMPTY_ITERATION;
}
if (inferred) {
boolean containsInferred = statements.stream().anyMatch(ExtensibleStatement::isInferred);
if (!containsInferred)
return EMPTY_ITERATION;
}
return new SortedIteration<>(new FilteringIteration<>(new CloseableIteratorIteration<>(statements.iterator()),
subject, predicate, object, inferred, contexts), statementOrder);
}

@Override
public void flushForReading() {

}

@Override
public void init() {

}

@Override
public void flushForCommit() {

}

@Override
public long getEstimatedSize() {
return statements.size();
}

@Override
public Set<StatementOrder> getSupportedOrders(Resource subj, IRI pred, Value obj, boolean inferred,
Resource... contexts) {
return EnumSet.of(StatementOrder.S, StatementOrder.P, StatementOrder.O, StatementOrder.C);
}

@Override
public Comparator<Value> getComparator() {
return Comparator.comparing(Value::stringValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

package org.eclipse.rdf4j.common.lang;

import java.util.Objects;

/**
* Generic utility methods related to objects.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public String toASCIIString() {
appendAscii(sb, userInfo);
sb.append('@');
}
if (host.length() > 0) {
if (!host.isEmpty()) {
sb.append(IDN.toASCII(host, IDN.ALLOW_UNASSIGNED));
}
if (port >= 0) {
Expand Down Expand Up @@ -516,7 +516,7 @@ public ParsedIRI normalize() {
boolean localhost = isScheme("file") && userInfo == null && -1 == port
&& ("".equals(host) || "localhost".equals(host));
String _host = localhost ? null
: host == null || host.length() == 0 ? host
: host == null || host.isEmpty() ? host
: IDN.toUnicode(pctEncodingNormalization(toLowerCase(host)),
IDN.USE_STD3_ASCII_RULES | IDN.ALLOW_UNASSIGNED);
String _path = _scheme != null && path == null ? "" : normalizePath(path);
Expand Down Expand Up @@ -581,14 +581,14 @@ public ParsedIRI resolve(ParsedIRI relative) {
// relURI._scheme == null

// RFC, step 2:
if (relative.getHost() == null && relative.getQuery() == null && relative.getPath().length() == 0) {
if (relative.getHost() == null && relative.getQuery() == null && relative.getPath().isEmpty()) {

// Inherit any fragment identifier from relURI
String fragment = relative.getFragment();

return new ParsedIRI(this.getScheme(), this.getUserInfo(), this.getHost(), this.getPort(), this.getPath(),
this.getQuery(), fragment);
} else if (relative.getHost() == null && relative.getPath().length() == 0) {
} else if (relative.getHost() == null && relative.getPath().isEmpty()) {

// Inherit any query or fragment from relURI
String query = relative.getQuery();
Expand Down Expand Up @@ -636,7 +636,7 @@ public ParsedIRI resolve(ParsedIRI relative) {
path = path.substring(0, lastSlashIdx + 1);
}

if (path.length() == 0) {
if (path.isEmpty()) {
// No path means: start at root.
path = "/";
}
Expand Down Expand Up @@ -782,7 +782,7 @@ private void parse() throws URISyntaxException {
if (':' == peek()) {
advance(1);
String p = parseMember(DIGIT, '/');
if (p.length() > 0) {
if (!p.isEmpty()) {
port = Integer.parseInt(p);
} else {
port = -1;
Expand Down Expand Up @@ -1101,7 +1101,7 @@ && isMember(ALPHA, path.codePointAt(1))) {
}

private String pctEncodingNormalization(String path) {
if (path == null || path.length() == 0 || path.indexOf('%') < 0) {
if (path == null || path.isEmpty() || path.indexOf('%') < 0) {
return path; // no pct encodings
}
String[] encodings = listPctEncodings(path);
Expand Down
5 changes: 5 additions & 0 deletions core/common/iterator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<artifactId>rdf4j-model-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rdf4j-common-order</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;

/**
* An Iteration that can convert an {@link Iterator} to a {@link CloseableIteration}.
Expand Down
Loading

0 comments on commit a6ec965

Please sign in to comment.