Skip to content

Commit

Permalink
test quads
Browse files Browse the repository at this point in the history
  • Loading branch information
ate47 committed Feb 1, 2024
1 parent 15e563b commit d51bbe7
Show file tree
Hide file tree
Showing 19 changed files with 728 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ void initializeEndpointStore(boolean finishLoading) throws IOException {
CompiledSailOptions options = new CompiledSailOptions();
options.setPort(port);
options.setEndpointThreshold(threshold);
options.setHdtSpec(hdtSpec);
options.setHdtSpec(HDTOptions.of(hdtSpec));
options.setTimeoutQuery(maxTimeoutCfg);
options.setTimeoutUpdate(maxTimeoutUpdateCfg);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private MultiLayerModBitmapWrapper(ModifiableBitmap handle, long graphs) {

@Override
public void set(long layer, long position, boolean value) {
((ModifiableBitmap) handle).set(graphs * layer + position, value);
((ModifiableBitmap) handle).set(graphs * position + layer, value);
}
}

Expand Down Expand Up @@ -51,13 +51,14 @@ private MultiLayerBitmapWrapper(Bitmap handle, long graphs) {
this.graphs = graphs;
}

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

@Override
public boolean access(long layer, long position) {
return handle.access(graphs * layer + position);
return handle.access(graphs * position + layer);
}

@Override
Expand Down Expand Up @@ -132,7 +133,7 @@ public long getLayersCount() {

@Override
public boolean access(long position) {
return handle.access(position);
return access(0, position);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.the_qa_company.qendpoint.core.iterator.utils;

import com.the_qa_company.qendpoint.core.enums.ResultEstimationType;
import com.the_qa_company.qendpoint.core.enums.TripleComponentOrder;
import com.the_qa_company.qendpoint.core.exceptions.NotImplementedException;
import com.the_qa_company.qendpoint.core.triples.IteratorTripleID;
import com.the_qa_company.qendpoint.core.triples.TripleID;

public class GraphFilteringTripleId implements IteratorTripleID {
private final IteratorTripleID iterator;
private final long[] graphIds;
private TripleID next;

public GraphFilteringTripleId(IteratorTripleID iterator, long[] graphIds) {
this.iterator = iterator;
this.graphIds = graphIds;
}

@Override
public boolean hasPrevious() {
throw new NotImplementedException();
}

@Override
public TripleID previous() {
throw new NotImplementedException();
}

@Override
public void goToStart() {
throw new NotImplementedException();
}

@Override
public boolean canGoTo() {
return false;
}

@Override
public void goTo(long pos) {
throw new NotImplementedException();
}

@Override
public long estimatedNumResults() {
return iterator.estimatedNumResults();
}

@Override
public ResultEstimationType numResultEstimation() {
return iterator.numResultEstimation();
}

@Override
public TripleComponentOrder getOrder() {
return iterator.getOrder();
}

@Override
public long getLastTriplePosition() {
return iterator.getLastTriplePosition();
}

@Override
public boolean isLastTriplePositionBoundToOrder() {
return iterator.isLastTriplePositionBoundToOrder();
}

@Override
public boolean hasNext() {
if (next != null) {
return true;
}
while (iterator.hasNext()) {
TripleID val = iterator.next();

long g = val.getGraph();
for (long graphId : graphIds) {
if (graphId == g) {
next = val;
return true;
}
}
// can't find valid graph
}
return false;
}

@Override
public TripleID next() {
if (!hasNext()) {
return null;
}
TripleID newVal = next;
next = null;
return newVal;
}

@Override
public void remove() {
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
Expand Down Expand Up @@ -92,7 +91,7 @@ static HDTOptions empty() {
*/
static HDTOptions of(HDTOptions other) {
HDTOptions opt = of();
other.getKeys().forEach(key -> opt.set(String.valueOf(key), other.get(String.valueOf(key))));
opt.setOptions(other);
return opt;
}

Expand Down Expand Up @@ -154,6 +153,18 @@ static HDTOptions of(Object... data) {
return opt;
}

/**
* create modifiable options with a string config
* @param cfg config
* @return options
*/
static HDTOptions of(String cfg) {
Objects.requireNonNull(cfg, "cfg can't be null!");
HDTOptions opt = of();
opt.setOptions(cfg);
return opt;
}

/**
* get options or {@link #EMPTY}
*
Expand Down Expand Up @@ -248,13 +259,27 @@ default Path getPath(String key, Supplier<Path> defaultValue) {

/**
* @return the keys of the options
* @throws NotImplementedException if the implemented class do not implement
* @throws NotImplementedException if the implementation does not implement
* this method (backward compatibility)
*/
default Set<?> getKeys() {
throw new NotImplementedException("getKeys");
}

/**
* @return the options to be used with {@link #setOptions(String)}
*/
default String getOptions() {
StringBuilder bld = new StringBuilder();

for (Object k : getKeys()) {
String keyStr = String.valueOf(k);
bld.append(keyStr).append("=").append(get(keyStr)).append(";");
}

return bld.toString();
}

/**
* get a value
*
Expand Down Expand Up @@ -480,8 +505,7 @@ default void load(String filename) throws IOException {
void set(String key, String value);

/**
* set a value, same as using {@link String#valueOf(Object)} with
* {@link #set(String, String)}
* set a value, check the type of the value to serialize it.
*
* @param key key
* @param value value
Expand All @@ -495,6 +519,11 @@ default void set(String key, Object value) {
set(key, p);
} else if (value instanceof File f) {
set(key, f.getAbsolutePath());
} else if (value instanceof HDTOptions opt) {
for (Object optKey : opt.getKeys()) {
String optKeyStr = String.valueOf(optKey);
set(key + "." + optKeyStr, opt.get(optKeyStr));
}
} else {
set(key, String.valueOf(value));
}
Expand Down Expand Up @@ -556,6 +585,14 @@ default void setOptions(Map<?, ?> options) {
options.forEach((k, v) -> set(String.valueOf(k), v));
}

/**
* add options from another set
* @param other other set
*/
default void setOptions(HDTOptions other) {
other.getKeys().forEach(key -> set(String.valueOf(key), other.get(String.valueOf(key))));
}

/**
* add options, each param should be in the format (key, value)*
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected TripleID getNext() {
return id;
}
// search another
tid = null;
continue;
}

Expand Down Expand Up @@ -105,6 +106,11 @@ public TripleComponentOrder getOrder() {
return tidIt.getOrder();
}

@Override
public boolean isLastTriplePositionBoundToOrder() {
return tidIt.isLastTriplePositionBoundToOrder();
}

@Override
public long getLastTriplePosition() {
return posZ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,28 +218,6 @@ public void save(OutputStream output, ControlInfo ci, ProgressListener listener)
graphs.save(output, iListener);
}

@Override
public SuppliableIteratorTripleID search(TripleID pattern) {
if (isClosed) {
throw new IllegalStateException("Cannot search on BitmapTriples if it's already closed");
}

if (getNumberOfElements() == 0 || pattern.isNoMatch()) {
return new EmptyTriplesIterator(order);
}

TripleID reorderedPat = new TripleID(pattern);
TripleOrderConvert.swapComponentOrder(reorderedPat, TripleComponentOrder.SPO, order);
String patternString = reorderedPat.getPatternString();

if (hasFOQIndex() && patternString.equals("???G")) {
return new BitmapTriplesIteratorGraphG(this, pattern);
}

return new BitmapTriplesIteratorGraph(this, super.search(pattern.copyNoGraph()),
pattern.isQuad() ? pattern.getGraph() : 0);
}

@Override
public SuppliableIteratorTripleID search(TripleID pattern, int searchMask) {
if (isClosed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public static class CompiledSailCompiler {
private NotifyingSail sourceSail;
private EndpointFiles endpointFiles;
private HDTOptions spec;
private String hdtSpec;
private HDTOptions hdtSpec;
private final Map<String, String> stringConfig = new HashMap<>();
private final List<Object> stringObject = new ArrayList<>();
private CompiledSailOptions options;
Expand Down Expand Up @@ -518,6 +518,21 @@ public CompiledSailCompiler withEndpointFiles(EndpointFiles endpointFiles) {
* @throws java.lang.NullPointerException a parameter is null
*/
public CompiledSailCompiler withHDTSpec(String hdtSpec) {
HDTOptions spec = HDTOptions.of();
spec.setOptions(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
*
* @param hdtSpec the spec
* @return this
* @throws java.lang.NullPointerException a parameter is null
*/
public CompiledSailCompiler withHDTSpec(HDTOptions hdtSpec) {
this.hdtSpec = Objects.requireNonNull(hdtSpec, "hdtSpec can't be null!");
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class CompiledSailOptions {
private int rdf4jSplitUpdate;
private int endpointThreshold;
private int port;
private String hdtSpec;
private HDTOptions hdtSpec;
private int timeoutUpdate;
private int timeoutQuery;
private Map<String, String> hdtOptions;
Expand Down Expand Up @@ -74,7 +74,7 @@ public CompiledSailOptions() {
rdf4jSplitUpdate = SailCompilerSchema.RDF_STORE_SPLIT_STORAGE.getHandler().defaultValue();
endpointThreshold = SailCompilerSchema.ENDPOINT_THRESHOLD.getHandler().defaultValue();
port = SailCompilerSchema.SERVER_PORT.getHandler().defaultValue();
hdtSpec = "";
hdtSpec = HDTOptions.empty();
timeoutUpdate = SailCompilerSchema.TIMEOUT_UPDATE.getHandler().defaultValue();
timeoutQuery = SailCompilerSchema.TIMEOUT_QUERY.getHandler().defaultValue();
hdtOptions = Map.of();
Expand All @@ -96,7 +96,7 @@ 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 = 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 Expand Up @@ -224,7 +224,7 @@ public void setPort(int port) {
this.port = port;
}

public String getHdtSpec() {
public HDTOptions getHdtSpec() {
return hdtSpec;
}

Expand All @@ -238,10 +238,7 @@ public void setDumpLocation(Path dumpLocation) {
* @return HDTOptions
*/
public HDTOptions createSpecHDTOptions() {
HDTOptions opt = new HDTOptionsBase();

// set hdtspec config
opt.setOptions(getHdtSpec());
HDTOptions opt = HDTOptions.of(getHdtSpec());

// set model config
getHdtOptions().forEach(opt::set);
Expand Down Expand Up @@ -277,7 +274,7 @@ public HDTOptions createHDTOptions(Path endHDT, Path workLocation) {
return opt;
}

public void setHdtSpec(String hdtSpec) {
public void setHdtSpec(HDTOptions hdtSpec) {
this.hdtSpec = hdtSpec;
}

Expand Down
Loading

0 comments on commit d51bbe7

Please sign in to comment.