use of org.apache.jena.tdb.store.NodeId in project jena by apache.
the class dumpbpt method exec.
@Override
protected void exec() {
List<String> tripleIndexes = Arrays.asList(Names.tripleIndexes);
List<String> quadIndexes = Arrays.asList(Names.quadIndexes);
Location loc = modLocation.getLocation();
// The name is the order.
for (String indexName : super.getPositional()) {
String primary;
if (indexName.length() == 3) {
primary = Names.primaryIndexTriples;
} else if (indexName.length() == 4) {
primary = Names.primaryIndexQuads;
} else {
cmdError("Wrong length: " + indexName);
primary = null;
}
int keySubLen = SystemTDB.SizeOfNodeId;
int keyUnitLen = indexName.length();
int keyLength = keySubLen * keyUnitLen;
int valueLength = 0;
RecordFactory rf = new RecordFactory(keyLength, valueLength);
RangeIndex rIndex = IndexFactory.buildRangeIndex(loc, indexName, rf);
BPlusTree bpt = (BPlusTree) rIndex;
if (false) {
System.out.println("---- Index structure");
bpt.dump();
}
if (true) {
System.out.println("---- Index contents");
Iterator<Record> iter = bpt.iterator();
if (!iter.hasNext())
System.out.println("<<Empty>>");
for (; iter.hasNext(); ) {
Record r = iter.next();
printRecord("", System.out, r, keyUnitLen);
}
}
// Check.
Iterator<Record> iterCheck = bpt.iterator();
Record r1 = null;
int i = 0;
for (; iterCheck.hasNext(); ) {
Record r2 = iterCheck.next();
i++;
if (r1 != null) {
if (!Record.keyLT(r1, r2)) {
System.err.println("key error@ " + i);
printRecord(" ", System.err, r1, keyUnitLen);
printRecord(" ", System.err, r2, keyUnitLen);
}
}
r1 = r2;
}
if (false) {
// Dump in tuple order.
TupleIndex tupleIndex = new TupleIndexRecord(primary.length(), new ColumnMap(primary, indexName), indexName, rIndex.getRecordFactory(), rIndex);
if (true) {
System.out.println("---- Tuple contents");
Iterator<Tuple<NodeId>> iter2 = tupleIndex.all();
if (!iter2.hasNext())
System.out.println("<<Empty>>");
for (; iter2.hasNext(); ) {
Tuple<NodeId> row = iter2.next();
System.out.println(row);
}
}
}
}
}
use of org.apache.jena.tdb.store.NodeId in project jena by apache.
the class dumpnodetable method dump.
public static void dump(OutputStream w, NodeTable nodeTable) {
// Better to hack the indexes?
Iterator<Pair<NodeId, Node>> iter = nodeTable.all();
long count = 0;
try (IndentedWriter iw = new IndentedWriter(w)) {
for (; iter.hasNext(); ) {
Pair<NodeId, Node> pair = iter.next();
iw.print(pair.car().toString());
iw.print(" : ");
// iw.print(pair.cdr()) ;
Node n = pair.cdr();
String $ = stringForNode(n);
iw.print($);
iw.println();
count++;
}
iw.println();
iw.printf("Total: " + count);
iw.println();
iw.flush();
}
}
use of org.apache.jena.tdb.store.NodeId in project jena by apache.
the class tdbgenindex method main.
public static void main(String... argv) {
// Usage: srcLocation indexName dstLocation indexName
if (argv.length != 4) {
System.err.println("Usage: " + Lib.classShortName(tdbgenindex.class) + " srcLocation srcIndex dstLocation dstIndex");
System.exit(1);
}
Location srcLoc = Location.create(argv[0]);
String srcIndexName = argv[1];
Location dstLoc = Location.create(argv[2]);
String dstIndexName = argv[3];
int readCacheSize = 0;
int writeCacheSize = -1;
if (srcIndexName.length() != dstIndexName.length()) {
System.err.println("srcIndexName.length() != dstIndexName.length() " + srcIndexName + " :: " + dstIndexName);
System.exit(1);
}
String primary;
int dftKeyLength;
int dftValueLength;
if (srcIndexName.length() == 3) {
primary = Names.primaryIndexTriples;
dftKeyLength = SystemTDB.LenIndexTripleRecord;
dftValueLength = 0;
} else if (srcIndexName.length() == 4) {
primary = Names.primaryIndexQuads;
dftKeyLength = SystemTDB.LenIndexQuadRecord;
dftValueLength = 0;
} else {
System.err.println("indexlength != 3 or 4");
System.exit(1);
primary = null;
dftKeyLength = 0;
dftValueLength = 0;
}
TupleIndex srcIdx = SetupTDB.makeTupleIndex(srcLoc, primary, srcIndexName, srcIndexName, dftKeyLength);
TupleIndex dstIdx = SetupTDB.makeTupleIndex(dstLoc, primary, dstIndexName, dstIndexName, dftKeyLength);
Iterator<Tuple<NodeId>> iter = srcIdx.all();
for (; iter.hasNext(); ) {
Tuple<NodeId> tuple = iter.next();
dstIdx.add(tuple);
}
srcIdx.close();
dstIdx.close();
}
use of org.apache.jena.tdb.store.NodeId in project jena by apache.
the class SolverLib method convert.
/** Binding ==> BindingNodeId, given a NodeTable */
public static BindingNodeId convert(Binding binding, NodeTable nodeTable) {
if (binding instanceof BindingTDB)
return ((BindingTDB) binding).getBindingId();
BindingNodeId b = new BindingNodeId(binding);
// and copy over, getting NodeIds.
Iterator<Var> vars = binding.vars();
for (; vars.hasNext(); ) {
Var v = vars.next();
Node n = binding.get(v);
if (n == null)
// Can occur with BindingProject
continue;
// Rely on the node table cache for efficency - we will likely be
// repeatedly looking up the same node in different bindings.
NodeId id = nodeTable.getNodeIdForNode(n);
// Even put in "does not exist" for a node now known not to be in the DB.
b.put(v, id);
}
return b;
}
use of org.apache.jena.tdb.store.NodeId in project jena by apache.
the class StageMatchTuple method prepare.
/** Prepare a pattern (tuple of nodes), and an existing binding of NodeId, into NodeIds and Variables.
* A variable in the pattern is replaced by its binding or null in the Nodeids.
* A variable that is not bound by the binding is placed in the var array.
* Return false if preparation detechs the pattern can not match.
*/
public static boolean prepare(NodeTable nodeTable, Tuple<Node> patternTuple, BindingNodeId input, NodeId[] ids, Var[] var) {
// we wish to abort if an unknown node is seen.
for (int i = 0; i < patternTuple.len(); i++) {
Node n = patternTuple.get(i);
// Substitution and turning into NodeIds
// Variables unsubstituted are null NodeIds
NodeId nId = idFor(nodeTable, input, n);
if (NodeId.isDoesNotExist(nId))
return false;
ids[i] = nId;
if (nId == null)
var[i] = asVar(n);
}
return true;
}
Aggregations