/** * Include the record which matches the specified key. * * @param idx the index in which to query for the key * @param key the key */ public void includeKey(HollowPrimaryKeyIndex idx, Object... key) { inverseCopyDirector.excludeKey(idx, key); }
private OrdinalRemapper[] createOrdinalRemappers() { for(int i=0;i<ordinalRemappers.length;i++) ordinalRemappers[i] = new HollowCombinerOrdinalRemapper(this, inputs[i]); return ordinalRemappers; }
@Override public boolean ordinalIsMapped(String type, int originalOrdinal) { return baseRemappers[stateEngineIdx].ordinalIsMapped(type, originalOrdinal); }
@Test public void testExplicitlyExcludedAndRemappedKeys() throws IOException { HollowPrimaryKeyIndex cIdx1 = new HollowPrimaryKeyIndex(input1, "TypeC", "key"); HollowCombinerExcludePrimaryKeysCopyDirector director = new HollowCombinerExcludePrimaryKeysCopyDirector(); director.excludeKey(cIdx1, 3); HollowCombiner combiner = new HollowCombiner(director, input1, input2, input3); combiner.setPrimaryKeys(new PrimaryKey("TypeB", "key", "c.key"), new PrimaryKey("TypeC", "key")); combiner.combine(); HollowReadStateEngine output = StateEngineRoundTripper.roundTripSnapshot(combiner.getCombinedStateEngine()); assertObject(output, 1, 1, 1, 1, 1, 1); assertObject(output, 2, 1, 2, 1, 2, 1); assertObject(output, 3, 1, 3, 1, 3, 2); assertObject(output, 4, 2, 2, 2, 3, 2); assertObject(output, 5, 2, 4, 2, 4, 2); assertObject(output, 6, 2, 6, 2, 6, 2); assertObject(output, 7, 3, 2, 2, 3, 2); assertObject(output, 8, 3, 7, 3, 6, 2); assertObject(output, 9, 3, 8, 3, 8, 3); assertObject(output, 10,3, 4, 3, 10,3); }
@Test public void testCompoundKeys() throws IOException { HollowCombiner combiner = new HollowCombiner(input1, input2, input3); combiner.setPrimaryKeys(new PrimaryKey("TypeB", "key", "c.key")); combiner.combine(); HollowReadStateEngine output = StateEngineRoundTripper.roundTripSnapshot(combiner.getCombinedStateEngine()); assertObject(output, 1, 1, 1, 1, 1, 1); assertObject(output, 2, 1, 2, 1, 2, 1); assertObject(output, 3, 1, 3, 1, 3, 1); assertObject(output, 4, 2, 2, 2, 3, 2); assertObject(output, 5, 2, 4, 2, 4, 2); assertObject(output, 6, 2, 6, 2, 6, 2); assertObject(output, 7, 3, 2, 2, 3, 2); assertObject(output, 8, 3, 7, 3, 6, 3); assertObject(output, 9, 3, 8, 3, 8, 3); assertObject(output, 10,3, 4, 3, 10,3); }
public HollowCombinerIncludePrimaryKeysCopyDirector() { this.inverseCopyDirector = new HollowCombinerExcludePrimaryKeysCopyDirector(); }
@Override public int getMappedOrdinal(String type, int originalOrdinal) { return baseRemappers[stateEngineIdx].getMappedOrdinal(type, originalOrdinal); }
@Override public boolean shouldCopy(HollowTypeReadState typeState, int ordinal) { return !inverseCopyDirector.shouldCopy(typeState, ordinal); }
public HollowCombinerOrdinalRemapper(HollowCombiner combiner, HollowReadStateEngine inputStateEngine) { this.combiner = combiner; this.typeMappings = initializeTypeMappings(inputStateEngine); }
public int compare(PrimaryKey o1, PrimaryKey o2) { return schemaDependencyIdx(o1) - schemaDependencyIdx(o2); }
@Override public int getMappedOrdinal(String type, int originalOrdinal) { int typeMapping[] = typeMappings.get(type); if(typeMapping == null) return originalOrdinal; if(typeMapping[originalOrdinal] == -1) typeMapping[originalOrdinal] = combiner.copyOrdinal(type, originalOrdinal); return typeMapping[originalOrdinal]; }
TypeA(int id, int bVal) { this.id = id; this.typeB = new TypeB(); typeB.val = bVal; } }
@Override public boolean shouldCopy(HollowTypeReadState typeState, int ordinal) { BitSet bitSet = excludedOrdinals.get(typeState); if(bitSet != null && bitSet.get(ordinal)) return false; return baseDirector.shouldCopy(typeState, ordinal); }
@Test public void testExplicitlyExcludedButOtherwiseReferencedKeys() throws IOException { HollowPrimaryKeyIndex cIdx3 = new HollowPrimaryKeyIndex(input3, "TypeC", "key"); HollowCombinerExcludePrimaryKeysCopyDirector director = new HollowCombinerExcludePrimaryKeysCopyDirector(); director.excludeKey(cIdx3, 8); HollowCombiner combiner = new HollowCombiner(director, input1, input2, input3); combiner.setPrimaryKeys(new PrimaryKey("TypeB", "key", "c.key"), new PrimaryKey("TypeC", "key")); combiner.combine(); HollowReadStateEngine output = StateEngineRoundTripper.roundTripSnapshot(combiner.getCombinedStateEngine()); assertObject(output, 9, 3, 8, 3, 8, 3); }
@Test public void testCascadingKeys() throws IOException { HollowCombiner combiner = new HollowCombiner(input1, input2, input3); combiner.setPrimaryKeys(new PrimaryKey("TypeB", "key"), new PrimaryKey("TypeC", "key")); combiner.combine(); HollowReadStateEngine output = StateEngineRoundTripper.roundTripSnapshot(combiner.getCombinedStateEngine()); assertObject(output, 1, 1, 1, 1, 1, 1); assertObject(output, 2, 1, 2, 1, 2, 1); assertObject(output, 3, 1, 3, 1, 3, 1); assertObject(output, 4, 2, 2, 1, 2, 1); assertObject(output, 5, 2, 4, 2, 4, 2); assertObject(output, 6, 2, 6, 2, 6, 2); assertObject(output, 7, 3, 2, 1, 2, 1); assertObject(output, 8, 3, 7, 3, 6, 2); assertObject(output, 9, 3, 8, 3, 8, 3); assertObject(output, 10,3, 4, 2, 4, 2); }
public HollowCombinerIncludePrimaryKeysCopyDirector(HollowCombinerCopyDirector baseDirector) { this.inverseCopyDirector = new HollowCombinerExcludePrimaryKeysCopyDirector(baseDirector); }
@Override public HollowTypeDataAccess getTypeDataAccess(String typeName, int ordinal) { HollowDataAccess state = this; while(state instanceof HollowHistoricalStateDataAccess) { HollowHistoricalStateDataAccess historicalState = (HollowHistoricalStateDataAccess)state; if(historicalState.getOrdinalMapping().ordinalIsMapped(typeName, ordinal)) return state.getTypeDataAccess(typeName); state = historicalState.getNextState(); } return state.getTypeDataAccess(typeName); }
private IntMap remapPreviousOrdinalMapping(IntMap previousOrdinalMapping, String typeName, OrdinalRemapper ordinalRemapper) { IntMapEntryIterator ordinalMappingIter = previousOrdinalMapping.iterator(); IntMap ordinalLookupMap = new IntMap(previousOrdinalMapping.size()); while(ordinalMappingIter.next()) ordinalLookupMap.put(ordinalRemapper.getMappedOrdinal(typeName, ordinalMappingIter.getKey()), ordinalMappingIter.getValue()); return ordinalLookupMap; }
@Test public void testCompoundCascadingKeys() throws IOException { HollowCombiner combiner = new HollowCombiner(input1, input2, input3); combiner.setPrimaryKeys(new PrimaryKey("TypeB", "key", "c.key"), new PrimaryKey("TypeC", "key")); combiner.combine(); HollowReadStateEngine output = StateEngineRoundTripper.roundTripSnapshot(combiner.getCombinedStateEngine()); assertObject(output, 1, 1, 1, 1, 1, 1); assertObject(output, 2, 1, 2, 1, 2, 1); assertObject(output, 3, 1, 3, 1, 3, 1); assertObject(output, 4, 2, 2, 2, 3, 1); assertObject(output, 5, 2, 4, 2, 4, 2); assertObject(output, 6, 2, 6, 2, 6, 2); assertObject(output, 7, 3, 2, 2, 3, 1); assertObject(output, 8, 3, 7, 3, 6, 2); assertObject(output, 9, 3, 8, 3, 8, 3); assertObject(output, 10,3, 4, 3, 10,3); }