Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve "GRAPH ?g {}" #1642

Merged
merged 5 commits into from Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -188,7 +188,6 @@ protected Iterator<E> getInputIterator(File spillFile) throws FileNotFoundExcept
@Override
public Iterator<E> iterator() {
preMerge();

return iterator(getSpillFiles().size());
}

Expand All @@ -199,7 +198,7 @@ private Iterator<E> iterator(int size) {
int memSize = memory.size();

// Constructing an iterator from this class is not thread-safe (just
// like all the the other methods)
// like all the other methods)
if ( !finishedAdding && memSize > 1 ) {
E[] array = (E[])memory.toArray();
comparator.abortableSort(array); // don't care if we aborted or not
Expand Down
Expand Up @@ -39,20 +39,19 @@
/**
* Sort a query iterator. The sort will happen in-memory unless the size of the
* iterator exceeds a configurable threshold. In that case, a disk sort is used.
*
*
* @see SortedDataBag
*/

public class QueryIterSort extends QueryIterPlainWrapper {
private final QueryIterator embeddedIterator;
final SortedDataBag<Binding> db;
/*package*/ final SortedDataBag<Binding> db;

public QueryIterSort(QueryIterator qIter, List<SortCondition> conditions, ExecutionContext context) {
this(qIter, new BindingComparator(conditions, context), context);
}

public QueryIterSort(final QueryIterator qIter, final Comparator<Binding> comparator,
final ExecutionContext context) {
public QueryIterSort(QueryIterator qIter, Comparator<Binding> comparator, ExecutionContext context) {
super(null, context);
this.embeddedIterator = qIter;
ThresholdPolicy<Binding> policy = ThresholdPolicyFactory.policyFromContext(context.getContext());
Expand Down
Expand Up @@ -630,7 +630,7 @@ private static int compare(NodeValue nv1, NodeValue nv2, boolean sortOrderingCom

// Special case - date/dateTime comparison is affected by timezones and may be
// indeterminate based on the value of the dateTime/date.
// Do this first,
// Do this first, so that indeterminate can drop through to a general ordering.

switch (compType)
{
Expand Down
Expand Up @@ -35,7 +35,8 @@ public enum ValueSpaceClassification {
VSPACE_G_MONTH,
VSPACE_G_DAY,

VSPACE_STRING, VSPACE_LANG, VSPACE_SORTKEY,
VSPACE_STRING, VSPACE_LANG,
VSPACE_SORTKEY,
VSPACE_BOOLEAN,
VSPACE_UNKNOWN,
VSPACE_DIFFERENT
Expand Down
Expand Up @@ -1110,8 +1110,6 @@ public static int compareNumeric(NodeValue nv1, NodeValue nv2) {
}
}

//public static int compareDatetime(NodeValue nv1, NodeValue nv2)

// --------------------------------
// Functions on strings
// http://www.w3.org/TR/xpath-functions/#d1e2222
Expand Down
Expand Up @@ -81,10 +81,7 @@ public class Fuseki {
static private Metadata metadata = initMetadata();

private static Metadata initMetadata() {
Metadata m = new Metadata();
// m.addMetadata(metadataDevLocation);
m.addMetadata(metadataLocation);
return m;
return new Metadata(metadataLocation);
}

/** The name of the Fuseki server.*/
Expand Down
Expand Up @@ -46,10 +46,7 @@
import org.apache.jena.fuseki.system.FusekiNetLib;
import org.apache.jena.graph.Graph;
import org.apache.jena.riot.*;
import org.apache.jena.riot.system.ErrorHandler;
import org.apache.jena.riot.system.ErrorHandlerFactory;
import org.apache.jena.riot.system.StreamRDF;
import org.apache.jena.riot.system.StreamRDFLib;
import org.apache.jena.riot.system.*;
import org.apache.jena.riot.web.HttpNames;
import org.apache.jena.shared.JenaException;
import org.apache.jena.sparql.core.DatasetGraph;
Expand Down Expand Up @@ -320,10 +317,19 @@ public static void graphResponse(HttpAction action, Graph graph, RDFFormat forma
writeResponse(action, (out, fmt) -> RDFDataMgr.write(out, graph, fmt), format, contentType);
}

/** Return the preferred {@link RDFFormat} for a given {@link Lang}. */
/**
* Return the preferred {@link RDFFormat} for a given {@link Lang}.
*
*/
public static RDFFormat getNetworkFormatForLang(Lang lang) {
Objects.requireNonNull(lang);
return ( lang == Lang.RDFXML ) ? RDFFormat.RDFXML_PLAIN : RDFWriterRegistry.defaultSerialization(lang);
if ( lang == Lang.RDFXML )
return RDFFormat.RDFXML_PLAIN;
// Could prefer streaming over non-streaming but historically, output has been "pretty" for e.g. turtle
// RDFFormat fmt = StreamRDFWriter.defaultSerialization(lang);
// if ( fmt != null )
// return fmt;
return RDFWriterRegistry.defaultSerialization(lang);
}

/**
Expand Down
Expand Up @@ -480,8 +480,10 @@ private int portNumber(ArgDecl arg) {
@Override
protected void exec() {
try {
Logger log = Fuseki.serverLog;
FusekiMainInfo.logServerCode(log);
FusekiServer server = buildServer(serverConfig);
infoCmd(server);
infoCmd(server, log);
try {
server.start();
} catch (FusekiException ex) {
Expand Down Expand Up @@ -584,14 +586,10 @@ private static FusekiServer buildServer(FusekiServer.Builder builder, ServerConf
}

/** Information from the command line setup */
private void infoCmd(FusekiServer server) {
private void infoCmd(FusekiServer server, Logger log) {
if ( super.isQuiet() )
return;

Logger log = Fuseki.serverLog;

FusekiMainInfo.logServerCode(log);

if ( serverConfig.empty ) {
FmtLog.info(log, "No SPARQL datasets services");
} else {
Expand Down
Expand Up @@ -143,7 +143,7 @@ static QueryIterator testForGraphName(DatasetGraphTDB ds, Node graphNode, QueryI

/** Find all the graph names in the quads table. */
static QueryIterator graphNames(DatasetGraphTDB ds, Node graphNode, QueryIterator input,
Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
List<Abortable> killList = new ArrayList<>();
Iterator<Tuple<NodeId>> iter1 = ds.getQuadTable().getNodeTupleTable().find(NodeId.NodeIdAny, NodeId.NodeIdAny,
NodeId.NodeIdAny, NodeId.NodeIdAny);
Expand Down
Expand Up @@ -42,6 +42,8 @@
import org.apache.jena.tdb2.store.NodeId;
import org.apache.jena.tdb2.store.nodetable.NodeTable;
import org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable;
import org.apache.jena.tdb2.store.tupletable.TupleIndex;
import org.apache.jena.tdb2.store.tupletable.TupleTable;
import org.apache.jena.tdb2.sys.TDBInternal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -141,20 +143,36 @@ static QueryIterator testForGraphName(DatasetGraphTDB ds, Node graphNode, QueryI
}
}

private static Tuple<NodeId> TupleANY = TupleFactory.create4(NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny);

/** Find all the graph names in the quads table. */
static QueryIterator graphNames(DatasetGraphTDB ds, Node graphNode, QueryIterator input,
Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
List<Abortable> killList = new ArrayList<>();
Iterator<Tuple<NodeId>> iter1 = ds.getQuadTable().getNodeTupleTable().find(NodeId.NodeIdAny, NodeId.NodeIdAny,
NodeId.NodeIdAny, NodeId.NodeIdAny);
NodeTupleTable ntt = ds.getQuadTable().getNodeTupleTable();

TupleIndex idx = findGraphIndex(ntt.getTupleTable(), "G");

boolean needDistinct;
Iterator<Tuple<NodeId>> iter1;

if ( idx == null ) {
iter1 = ntt.findAll();
needDistinct = true;
}
else {
iter1 = idx.find(TupleANY);
needDistinct = false;
}

if ( filter != null )
iter1 = Iter.filter(iter1, filter);

Iterator<NodeId> iter2 = Iter.map(iter1, t -> t.get(0));
// Project is cheap - don't brother wrapping iter1
iter2 = makeAbortable(iter2, killList);

Iterator<NodeId> iter3 = Iter.distinct(iter2);
Iterator<NodeId> iter3 = (needDistinct) ? Iter.distinct(iter2) : Iter.distinctAdjacent(iter2);
iter3 = makeAbortable(iter3, killList);

Iterator<Node> iter4 = NodeLib.nodes(ds.getQuadTable().getNodeTupleTable().getNodeTable(), iter3);
Expand All @@ -164,6 +182,17 @@ static QueryIterator graphNames(DatasetGraphTDB ds, Node graphNode, QueryIterato
return new QueryIterAbortable(iterBinding, killList, input, execCxt);
}

private static TupleIndex findGraphIndex(TupleTable tupleTable, String indexPrefix) {
TupleIndex[] indexes = tupleTable.getIndexes();
for ( int i = 0 ; i < indexes.length ; i++ ) {
TupleIndex idx = indexes[i];
String n = idx.getName();
if ( n.startsWith(indexPrefix) )
return idx;
}
return null;
}

static Set<NodeId> convertToNodeIds(Collection<Node> nodes, DatasetGraphTDB dataset)
{
Set<NodeId> graphIds = new HashSet<>();
Expand Down
Expand Up @@ -90,7 +90,6 @@ private static Iterator<BindingNodeId> access(NodeTupleTable nodeTupleTable, Bin
iterMatches = Iter.distinctAdjacent(iterMatches);
}


Function<Tuple<NodeId>, BindingNodeId> binder = tuple -> tupleToBinding(input, tuple, vars);
return Iter.iter(iterMatches).map(binder).removeNulls();
}
Expand Down