Skip to content

Commit

Permalink
run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
ate47 committed Feb 2, 2024
1 parent b0c04a9 commit 9e30bdf
Show file tree
Hide file tree
Showing 17 changed files with 345 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private MultiLayerBitmapWrapper(Bitmap handle, long graphs) {

@SuppressWarnings("unchecked")
public <T extends Bitmap> T getHandle() {
return (T)handle;
return (T) handle;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ static HDTOptions of(Object... data) {

/**
* create modifiable options with a string config
*
* @param cfg config
* @return options
*/
Expand Down Expand Up @@ -587,6 +588,7 @@ default void setOptions(Map<?, ?> options) {

/**
* add options from another set
*
* @param other other set
*/
default void setOptions(HDTOptions other) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public static Path getIndexPath(Path hdt, TripleComponentOrder order) {

/**
* Compute triples signature
*
* @param triples triples
* @return signature
*/
Expand All @@ -76,7 +77,7 @@ public static long signature(BitmapTriples triples) {
*
* @param file file
* @param channel channel
* @param triples triples
* @param triples triples
* @return index
* @throws IOException io
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ public static class CompiledSailCompiler {
private Model configModel;
private NotifyingSail sourceSail;
private EndpointFiles endpointFiles;
private HDTOptions spec;
private HDTOptions hdtSpec;
private final Map<String, String> stringConfig = new HashMap<>();
private final List<Object> stringObject = new ArrayList<>();
Expand Down Expand Up @@ -523,7 +522,6 @@ public CompiledSailCompiler withHDTSpec(String hdtSpec) {
return withHDTSpec(spec);
}


/**
* set the hdt spec for the endpoint store, won't be used if the source
* is defined or if the generated source isn't an endpoint store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ void readOptions(SailCompiler.SailCompilerReader reader) {
endpointThreshold = reader.searchPropertyValue(SailCompilerSchema.MAIN, SailCompilerSchema.ENDPOINT_THRESHOLD);
hdtReadMode = reader.searchPropertyValue(SailCompilerSchema.MAIN, SailCompilerSchema.HDT_READ_MODE_PROPERTY);
port = reader.searchPropertyValue(SailCompilerSchema.MAIN, SailCompilerSchema.SERVER_PORT);
hdtSpec = HDTOptions.of(reader.searchPropertyValue(SailCompilerSchema.MAIN, SailCompilerSchema.HDT_SPEC_PROPERTY));
hdtSpec = HDTOptions
.of(reader.searchPropertyValue(SailCompilerSchema.MAIN, SailCompilerSchema.HDT_SPEC_PROPERTY));
timeoutUpdate = reader.searchPropertyValue(SailCompilerSchema.MAIN, SailCompilerSchema.TIMEOUT_UPDATE);
timeoutQuery = reader.searchPropertyValue(SailCompilerSchema.MAIN, SailCompilerSchema.TIMEOUT_QUERY);
hdtOptions = reader.search(SailCompilerSchema.MAIN, SailCompilerSchema.GEN_HDT_OPTION_PARAM).stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,16 +443,21 @@ public void setFreezedStoreStore(AbstractNotifyingSail sail) {
}

/**
* force access to the store via reflection, the library does not allow directly since the method is protected
* force access to the store via reflection, the library does not allow
* directly since the method is protected
*
* @return sailstore
* @deprecated use {@link #getCurrentSailStore()} instead
*/
@Deprecated
public SailStore getCurrentSaliStore() {
return getCurrentSailStore();
}

/**
* force access to the store via reflection, the library does not allow directly since the method is protected
* force access to the store via reflection, the library does not allow
* directly since the method is protected
*
* @return sailstore
*/
public SailStore getCurrentSailStore() {
Expand Down Expand Up @@ -684,7 +689,8 @@ public void initTempDump(boolean isRestarting) {
Files.createFile(file.toPath());
}
OutputStream rdfWriterTempTriplesOut = new BufferedOutputStream(new FileOutputStream(file, isRestarting));
this.rdfWriterTempTriples = graph ? new NQuadsWriter(rdfWriterTempTriplesOut) : new NTriplesWriter(rdfWriterTempTriplesOut);
this.rdfWriterTempTriples = graph ? new NQuadsWriter(rdfWriterTempTriplesOut)
: new NTriplesWriter(rdfWriterTempTriplesOut);
this.rdfWriterTempTriples.startRDF();
} catch (IOException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,17 @@ public void addStatement(UpdateContext op, Resource subj, IRI pred, Value obj, R
}

if (!this.endpoint.getHdt().getDictionary().supportGraphs()) {
// note that in the native store we insert a mix of native IRIs and HDT
// note that in the native store we insert a mix of native IRIs and
// HDT
// IRIs, depending if the resource is in
// HDT or not
TripleID tripleID = new TripleID(subjectID, predicateID, objectID);
if (tripleDoesntExistInHDT(tripleID)) {
// check if we need to search over the other native connection
if (endpoint.isMerging()) {
if (endpoint.shouldSearchOverRDF4J(subjectID, predicateID, objectID)) {
try (CloseableIteration<? extends Statement> other = getOtherConnectionRead().getStatements(newSubj,
newPred, newObj, false)) {
try (CloseableIteration<? extends Statement> other = getOtherConnectionRead()
.getStatements(newSubj, newPred, newObj, false)) {
if (other.hasNext()) {
return;
}
Expand Down Expand Up @@ -305,17 +306,15 @@ public void addStatement(UpdateContext op, Resource subj, IRI pred, Value obj, R
if (graphID == -1) {
newGraph = contexts;
} else {
newGraph = new Resource[] {
this.endpoint.getHdtConverter().graphIdToIRI(graphID)
};
newGraph = new Resource[] { this.endpoint.getHdtConverter().graphIdToIRI(graphID) };
}
TripleID tripleID = new TripleID(subjectID, predicateID, objectID, graphID);
if (quadDoesntExistInHDT(tripleID)) {
// check if we need to search over the other native connection
if (endpoint.isMerging()) {
if (endpoint.shouldSearchOverRDF4J(subjectID, predicateID, objectID)) {
try (CloseableIteration<? extends Statement> other = getOtherConnectionRead().getStatements(newSubj,
newPred, newObj, false, newGraph)) {
try (CloseableIteration<? extends Statement> other = getOtherConnectionRead()
.getStatements(newSubj, newPred, newObj, false, newGraph)) {
if (other.hasNext()) {
return;
}
Expand All @@ -331,9 +330,7 @@ public void addStatement(UpdateContext op, Resource subj, IRI pred, Value obj, R
this.endpoint.triplesCount++;
}
} else {
Resource[] newGraph = new Resource[] {
null
};
Resource[] newGraph = new Resource[] { null };
for (Resource context : contexts) {
long graphID;
if (context != null) {
Expand All @@ -349,11 +346,12 @@ public void addStatement(UpdateContext op, Resource subj, IRI pred, Value obj, R
}
TripleID tripleID = new TripleID(subjectID, predicateID, objectID, graphID);
if (quadDoesntExistInHDT(tripleID)) {
// check if we need to search over the other native connection
// check if we need to search over the other native
// connection
if (endpoint.isMerging()) {
if (endpoint.shouldSearchOverRDF4J(subjectID, predicateID, objectID)) {
try (CloseableIteration<? extends Statement> other = getOtherConnectionRead().getStatements(newSubj,
newPred, newObj, false, newGraph)) {
try (CloseableIteration<? extends Statement> other = getOtherConnectionRead()
.getStatements(newSubj, newPred, newObj, false, newGraph)) {
if (other.hasNext()) {
continue;
}
Expand Down Expand Up @@ -591,10 +589,13 @@ private boolean tripleDoesntExistInHDT(TripleID tripleID) {
return this.endpoint
.getDeleteBitMap(
iter.isLastTriplePositionBoundToOrder() ? iter.getOrder() : TripleComponentOrder.SPO)
.access(endpoint.getHdt().getDictionary().supportGraphs() ? (tid.isQuad() ? tid.getGraph() : endpoint.getHdtProps().getDefaultGraph()) - 1 : 0, index);
.access(endpoint.getHdt().getDictionary().supportGraphs()
? (tid.isQuad() ? tid.getGraph() : endpoint.getHdtProps().getDefaultGraph()) - 1
: 0, index);
}
return true;
}

private boolean quadDoesntExistInHDT(TripleID tripleID) {
IteratorTripleID iter = endpoint.getHdt().getTriples().search(tripleID);
// if iterator is empty then the given triple 't' doesn't exist in HDT
Expand All @@ -604,12 +605,13 @@ private boolean quadDoesntExistInHDT(TripleID tripleID) {
return this.endpoint
.getDeleteBitMap(
iter.isLastTriplePositionBoundToOrder() ? iter.getOrder() : TripleComponentOrder.SPO)
.access((tid.isQuad() ? tid.getGraph() : endpoint.getHdtProps().getDefaultGraph()) - 1, index);
.access((tid.isQuad() ? tid.getGraph() : endpoint.getHdtProps().getDefaultGraph()) - 1, index);
}
return true;
}

private void assignBitMapDeletes(TripleID tid, Resource subj, IRI pred, Value obj, Resource[] contexts, long[] contextIds) throws SailException {
private void assignBitMapDeletes(TripleID tid, Resource subj, IRI pred, Value obj, Resource[] contexts,
long[] contextIds) throws SailException {
long s = tid.getSubject();
long p = tid.getPredicate();
long o = tid.getObject();
Expand Down Expand Up @@ -646,7 +648,8 @@ private void assignBitMapDeletes(TripleID tid, Resource subj, IRI pred, Value ob
this.endpoint.getTempDeleteBitMap(sorder).set(layer, index, true);
}
if (order == TripleComponentOrder.SPO) {
notifyStatementRemoved(this.endpoint.getValueFactory().createStatement(subj, pred, obj));
notifyStatementRemoved(
this.endpoint.getValueFactory().createStatement(subj, pred, obj));
}
}
}
Expand All @@ -668,14 +671,15 @@ private void assignBitMapDeletes(TripleID tid, Resource subj, IRI pred, Value ob
assert iter.isLastTriplePositionBoundToOrder();
TripleComponentOrder sorder = iter.getOrder();


if (!this.endpoint.getDeleteBitMap(sorder).access(removedId.getGraph() - 1, index)) {
this.endpoint.getDeleteBitMap(sorder).set(removedId.getGraph() - 1, index, true);
if (this.endpoint.isMerging()) {
this.endpoint.getTempDeleteBitMap(sorder).set(removedId.getGraph() - 1, index, true);
this.endpoint.getTempDeleteBitMap(sorder).set(removedId.getGraph() - 1, index,
true);
}
if (order == TripleComponentOrder.SPO) {
notifyStatementRemoved(this.endpoint.getValueFactory().createStatement(subj, pred, obj, context));
notifyStatementRemoved(
this.endpoint.getValueFactory().createStatement(subj, pred, obj, context));
}
}
}
Expand All @@ -695,7 +699,8 @@ private void assignBitMapDeletes(TripleID tid, Resource subj, IRI pred, Value ob
writer.handleStatement(this.endpoint.getValueFactory().createStatement(subj, pred, obj));
} else {
for (Resource ctx : contexts) {
writer.handleStatement(this.endpoint.getValueFactory().createStatement(subj, pred, obj, ctx));
writer.handleStatement(
this.endpoint.getValueFactory().createStatement(subj, pred, obj, ctx));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.query.QueryEvaluationException;
import org.eclipse.rdf4j.query.QueryInterruptedException;
import org.eclipse.rdf4j.sail.SailException;
import com.the_qa_company.qendpoint.core.triples.IteratorTripleID;
import com.the_qa_company.qendpoint.core.triples.TripleID;
import org.slf4j.Logger;
Expand Down Expand Up @@ -65,7 +63,9 @@ public boolean hasNext() {
logger.trace("From HDT {} {} {} ", subject, predicate, object);
}
if (supportGraphs) {
Resource ctx = tripleID.isQuad() ? endpoint.getHdtConverter().idToGraphHDTResource(tripleID.getGraph()) : null;
Resource ctx = tripleID.isQuad()
? endpoint.getHdtConverter().idToGraphHDTResource(tripleID.getGraph())
: null;
next = endpointTripleSource.getValueFactory().createStatement(subject, predicate, object, ctx);
} else {
next = endpointTripleSource.getValueFactory().createStatement(subject, predicate, object);
Expand All @@ -81,8 +81,7 @@ public boolean hasNext() {
Value newObject = endpoint.getHdtConverter().rdf4jToHdtIDobject(stm.getObject());
Resource newContext = endpoint.getHdtConverter().rdf4jToHdtIDcontext(stm.getContext());

next = endpointTripleSource.getValueFactory().createStatement(newSubj, newPred, newObject,
newContext);
next = endpointTripleSource.getValueFactory().createStatement(newSubj, newPred, newObject, newContext);
if (logger.isTraceEnabled()) {
logger.trace("From RDF4j {} {} {}", next.getSubject(), next.getPredicate(), next.getObject());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public CloseableIteration<? extends Statement> getStatements(StatementOrder stat
newContextes = contexts;
}

//logger.debug("SEARCH {} {} {}", newSubj, newPred, newObj);
// logger.debug("SEARCH {} {} {}", newSubj, newPred, newObj);

// check if we need to search over the delta and if yes, search
CloseableIteration<? extends Statement> repositoryResult;
Expand Down Expand Up @@ -161,18 +161,22 @@ public CloseableIteration<? extends Statement> getStatements(StatementOrder stat
// iterate over the HDT file
IteratorTripleID iterator;
if (subjectID != -1 && predicateID != -1 && objectID != -1) {
//logger.debug("Searching over HDT {} {} {}", subjectID, predicateID, objectID);
// logger.debug("Searching over HDT {} {} {}", subjectID,
// predicateID, objectID);
TripleID t = new TripleID(subjectID, predicateID, objectID);

if (graph && contexts.length > 1) {
if (statementOrder != null) {
int indexMaskMatchingStatementOrder = getIndexMaskMatchingStatementOrder(statementOrder, subj, pred,
obj, t);

// search with the ID to check if the triples has been deleted
iterator = new GraphFilteringTripleId(this.endpoint.getHdt().getTriples().search(t, indexMaskMatchingStatementOrder), graphID);
// search with the ID to check if the triples has been
// deleted
iterator = new GraphFilteringTripleId(
this.endpoint.getHdt().getTriples().search(t, indexMaskMatchingStatementOrder), graphID);
} else {
// search with the ID to check if the triples has been deleted
// search with the ID to check if the triples has been
// deleted
iterator = new GraphFilteringTripleId(this.endpoint.getHdt().getTriples().search(t), graphID);
}
} else {
Expand All @@ -183,10 +187,12 @@ public CloseableIteration<? extends Statement> getStatements(StatementOrder stat
int indexMaskMatchingStatementOrder = getIndexMaskMatchingStatementOrder(statementOrder, subj, pred,
obj, t);

// search with the ID to check if the triples has been deleted
// search with the ID to check if the triples has been
// deleted
iterator = this.endpoint.getHdt().getTriples().search(t, indexMaskMatchingStatementOrder);
} else {
// search with the ID to check if the triples has been deleted
// search with the ID to check if the triples has been
// deleted
iterator = this.endpoint.getHdt().getTriples().search(t);
}
}
Expand Down Expand Up @@ -277,8 +283,7 @@ private int getIndexMaskMatchingStatementOrder(StatementOrder statementOrder, Re
throw new AssertionError(
"Statement order " + statementOrder + " not supported for triple pattern " + t.getPatternString());
}
int indexMaskMatchingStatementOrder = first.get().mask;
return indexMaskMatchingStatementOrder;
return first.get().mask;
}

public static Set<StatementOrder> getStatementOrder(TripleComponentOrder tripleComponentOrder, boolean subject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.the_qa_company.qendpoint.core.dictionary.Dictionary;
import com.the_qa_company.qendpoint.core.enums.RDFNodeType;
import com.the_qa_company.qendpoint.core.enums.TripleComponentRole;
import com.the_qa_company.qendpoint.core.exceptions.NotImplementedException;
import com.the_qa_company.qendpoint.core.hdt.HDT;
import com.the_qa_company.qendpoint.model.HDTValue;
import com.the_qa_company.qendpoint.model.SimpleBNodeHDT;
Expand All @@ -17,9 +16,6 @@
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;

import java.util.Arrays;
import java.util.Objects;

// there are 4 types of resources:
// resources coming from outside,
// HDT IDs
Expand Down Expand Up @@ -49,11 +45,11 @@ public long subjectToID(Resource subj) {

long id = hdtval.getHDTId();
return switch (hdtval.getHDTPosition()) {
case SimpleIRIHDT.SUBJECT_POS, SimpleIRIHDT.SHARED_POS -> id;
case SimpleIRIHDT.PREDICATE_POS, SimpleIRIHDT.GRAPH_POS ->
hdt.getDictionary().stringToId(subj.toString(), TripleComponentRole.SUBJECT);
case SimpleIRIHDT.OBJECT_POS -> -1; // not shared
default -> throw new IllegalArgumentException("Invalid HDT position: " + hdtval.getHDTPosition());
case SimpleIRIHDT.SUBJECT_POS, SimpleIRIHDT.SHARED_POS -> id;
case SimpleIRIHDT.PREDICATE_POS, SimpleIRIHDT.GRAPH_POS ->
hdt.getDictionary().stringToId(subj.toString(), TripleComponentRole.SUBJECT);
case SimpleIRIHDT.OBJECT_POS -> -1; // not shared
default -> throw new IllegalArgumentException("Invalid HDT position: " + hdtval.getHDTPosition());
};
}

Expand All @@ -79,11 +75,11 @@ public long objectToID(Value obj) {

long id = hdtval.getHDTId();
return switch (hdtval.getHDTPosition()) {
case SimpleIRIHDT.OBJECT_POS, SimpleIRIHDT.SHARED_POS -> id;
case SimpleIRIHDT.PREDICATE_POS, SimpleIRIHDT.GRAPH_POS ->
hdt.getDictionary().stringToId(obj.toString(), TripleComponentRole.OBJECT);
case SimpleIRIHDT.SUBJECT_POS -> -1; // not shared
default -> throw new IllegalArgumentException("Invalid HDT position: " + hdtval.getHDTPosition());
case SimpleIRIHDT.OBJECT_POS, SimpleIRIHDT.SHARED_POS -> id;
case SimpleIRIHDT.PREDICATE_POS, SimpleIRIHDT.GRAPH_POS ->
hdt.getDictionary().stringToId(obj.toString(), TripleComponentRole.OBJECT);
case SimpleIRIHDT.SUBJECT_POS -> -1; // not shared
default -> throw new IllegalArgumentException("Invalid HDT position: " + hdtval.getHDTPosition());
};
}

Expand Down
Loading

0 comments on commit 9e30bdf

Please sign in to comment.