use of org.apache.jena.tdb.lib.ColumnMap in project jena by apache.
the class TestColumnMap method map1.
@Test
public void map1() {
ColumnMap cmap = new ColumnMap("GSPO", "OSPG");
Tuple<String> tuple = tuple("G", "S", "P", "O");
Tuple<String> mapped = cmap.map(tuple);
Tuple<String> expected = tuple("O", "S", "P", "G");
assertEquals(expected, mapped);
Tuple<String> unmapped = cmap.unmap(mapped);
assertEquals(tuple("G", "S", "P", "O"), unmapped);
}
use of org.apache.jena.tdb.lib.ColumnMap in project jena by apache.
the class ProcIndexBuild method exec.
public static void exec(String locationStr, String indexName, String dataFile) {
// Argument processing
Location location = Location.create(locationStr);
//InputStream input = System.in ;
InputStream input = IO.openFile(dataFile);
int keyLength = SystemTDB.SizeOfNodeId * indexName.length();
int valueLength = 0;
// The name is the order.
String primary = indexName;
// Scope for optimization:
// Null column map => no churn.
// Do record -> record copy, not Tuple, Tuple copy.
String primaryOrder;
int dftKeyLength;
int dftValueLength;
int tupleLength = indexName.length();
if (tupleLength == 3) {
primaryOrder = Names.primaryIndexTriples;
dftKeyLength = SystemTDB.LenIndexTripleRecord;
dftValueLength = 0;
} else if (tupleLength == 4) {
primaryOrder = Names.primaryIndexQuads;
dftKeyLength = SystemTDB.LenIndexQuadRecord;
dftValueLength = 0;
} else {
throw new AtlasException("Index name: " + indexName);
}
ColumnMap colMap = new ColumnMap(primaryOrder, indexName);
// -1? Write only.
// Also flush cache every so often => block writes (but not sequential so boring).
int readCacheSize = 10;
int writeCacheSize = 100;
int blockSize = SystemTDB.BlockSize;
RecordFactory recordFactory = new RecordFactory(dftKeyLength, dftValueLength);
int order = BPlusTreeParams.calcOrder(blockSize, recordFactory);
BPlusTreeParams bptParams = new BPlusTreeParams(order, recordFactory);
int blockSizeNodes = blockSize;
int blockSizeRecords = blockSize;
FileSet destination = new FileSet(location, indexName);
BlockMgr blkMgrNodes = BlockMgrFactory.create(destination, Names.bptExtTree, blockSizeNodes, readCacheSize, writeCacheSize);
BlockMgr blkMgrRecords = BlockMgrFactory.create(destination, Names.bptExtRecords, blockSizeRecords, readCacheSize, writeCacheSize);
int rowBlock = 1000;
Iterator<Record> iter = new RecordsFromInput(input, tupleLength, colMap, rowBlock);
BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(iter, bptParams, recordFactory, blkMgrNodes, blkMgrRecords);
bpt2.close();
}
use of org.apache.jena.tdb.lib.ColumnMap in project jena by apache.
the class IndexAssembler method open.
@Override
public TupleIndex open(Assembler a, Resource root, Mode mode) {
exactlyOneProperty(root, pDescription);
String desc = getAsStringValue(root, pDescription).toUpperCase(Locale.ENGLISH);
exactlyOneProperty(root, pFile);
String filename = getAsStringValue(root, pFile);
// Need to get location from the enclosing PGraphAssembler
if (location != null)
filename = location.absolute(filename);
String primary = null;
RecordFactory rf = null;
switch(desc.length()) {
case 3:
primary = Names.primaryIndexTriples;
rf = SystemTDB.indexRecordTripleFactory;
break;
case 4:
primary = Names.primaryIndexQuads;
rf = SystemTDB.indexRecordQuadFactory;
break;
default:
throw new TDBException("Bad length for index description: " + desc);
}
// Problems with spotting the index technology.
//FileSet.fromFilename(filename) ;
FileSet fileset = null;
IndexParams idxParams = StoreParams.getDftStoreParams();
RangeIndex rIndex = IndexFactory.buildRangeIndex(fileset, rf, idxParams);
return new TupleIndexRecord(desc.length(), new ColumnMap(primary, desc), desc, rf, rIndex);
}
use of org.apache.jena.tdb.lib.ColumnMap 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.lib.ColumnMap in project jena by apache.
the class DatasetBuilderStd method makeTupleIndex.
protected TupleIndex makeTupleIndex(Location location, String name, String primary, String indexOrder, StoreParams params) {
// Commonly, name == indexOrder.
FileSet fs = new FileSet(location, name);
ColumnMap colMap = new ColumnMap(primary, indexOrder);
return tupleIndexBuilder.buildTupleIndex(fs, colMap, indexOrder, params);
}
Aggregations