/** Construct a column mapping that maps the input (one col, one char) to the output */ public ColumnMap(String input, String output) { this(input+"->"+output, compileMapping(input, output)) ; }
@Override public final int weight(Tuple<NodeId> pattern) { for ( int i = 0 ; i < tupleLength ; i++ ) { NodeId X = colMap.fetchSlot(i, pattern) ; if ( undef(X) ) // End of fixed terms return i ; } return tupleLength ; }
/** Apply to an <em>unmapped</em> tuple to get a tuple with the column mapping applied */ public <T> Tuple<T> map(Tuple<T> src) { return map(src, insertOrder) ; }
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) ; }
@Test public void remap2() { ColumnMap x = new ColumnMap("SPO->POS", 2,0,1) ; Integer[] array = { 0,1,2 } ; assertEquals(Integer.valueOf(1), x.fetchSlot(0, array)) ; // The index 1 comes from position 0. assertEquals(Integer.valueOf(2), x.fetchSlot(1, array)) ; assertEquals(Integer.valueOf(0), x.fetchSlot(2, array)) ; }
public static Record record(RecordFactory factory, Tuple<NodeId> tuple, ColumnMap cMap) { byte[] b = new byte[tuple.len()*NodeId.SIZE] ; for ( int i = 0 ; i < tuple.len() ; i++ ) { int j = cMap.mapSlotIdx(i) ; // i'th Nodeid goes to j'th bytes slot. Bytes.setLong(tuple.get(i).getId(), b,j*SizeOfLong) ; } return factory.create(b) ; } }
private TupleIndex buildTupleIndex(FileSet fileSet, ColumnMap colMap, String name, StoreParams params) { RecordFactory recordFactory = new RecordFactory(SystemTDB.SizeOfNodeId * colMap.length(), 0) ; RangeIndex rIdx = /*rangeIndexBuilder.*/buildRangeIndex(fileSet, recordFactory, params) ; TupleIndex tIdx = new TupleIndexRecord(colMap.length(), colMap, name, recordFactory, rIdx) ; return tIdx ; }
@Override public final String getMapping() { return colMap.getLabel() ; }
public static Tuple<NodeId> tuple(Record r, ColumnMap cMap) { int N = r.getKey().length/SizeOfLong ; NodeId[] nodeIds = new NodeId[N] ; for ( int i = 0 ; i < N ; i++ ) { NodeId id = NodeId.create(r.getKey(), i*SizeOfLong) ; int j = i ; if ( cMap != null ) j = cMap.fetchSlotIdx(i) ; nodeIds[j] = id ; } return TupleFactory.asTuple(nodeIds) ; }
public static TupleIndex makeTupleIndex(Location location, String primary, String indexOrder, String indexName, int keyLength) { FileSet fs = new FileSet(location, indexName) ; int readCacheSize = params.getBlockReadCacheSize() ; int writeCacheSize = params.getBlockWriteCacheSize() ; // Value part is null (zero length) RangeIndex rIndex = SetupIndex.makeRangeIndex(location, indexName, params.getBlockSize(), keyLength, 0, readCacheSize, writeCacheSize) ; TupleIndex tupleIndex = new TupleIndexRecord(primary.length(), new ColumnMap(primary, indexOrder), indexOrder, rIndex.getRecordFactory(), rIndex) ; return tupleIndex ; }
@Test public void remap2() { ColumnMap x = new ColumnMap("SPO->POS", 2,0,1) ; Integer[] array = { 0,1,2 } ; assertEquals(Integer.valueOf(1), x.fetchSlot(0, array)) ; // The index 1 comes from position 0. assertEquals(Integer.valueOf(2), x.fetchSlot(1, array)) ; assertEquals(Integer.valueOf(0), x.fetchSlot(2, array)) ; }
int j = ( colMap == null ) ? i : colMap.mapSlotIdx(i) ; int recordOffset = j*SystemTDB.SizeOfLong ; Bytes.setLong(x, record.getKey(), recordOffset) ;
@Override public TupleIndex buildTupleIndex(FileSet fileSet, ColumnMap colMap, String name, StoreParams params) { RecordFactory recordFactory = new RecordFactory(SystemTDB.SizeOfNodeId * colMap.length(), 0) ; RangeIndex rIdx = rangeIndexBuilder.buildRangeIndex(fileSet, recordFactory, params) ; TupleIndex tIdx = new TupleIndexRecord(colMap.length(), colMap, name, recordFactory, rIdx) ; return tIdx ; } }