/** * Should be called exclusively from the {@link HollowDiff} -- not intended for external consumption * * @param fromOrdinal the from ordinal * @param toOrdinal the to ordinal * @param score the score */ public void addDiff(int fromOrdinal, int toOrdinal, int score) { if(isSameDiffAsLastAdd(fromOrdinal, toOrdinal)) { int scoreIdx = diffPairScores.size() - 1; diffPairScores.set(scoreIdx, diffPairScores.get(scoreIdx) + score); } else { diffFromOrdinals.add(fromOrdinal); diffToOrdinals.add(toOrdinal); diffPairScores.add(score); } totalDiffScore += score; }
public DiffEqualOrdinalFilter(DiffEqualOrdinalMap equalityMapping) { this.equalOrdinalMap = equalityMapping; this.matchedFromOrdinals = new IntList(); this.matchedToOrdinals = new IntList(); this.unmatchedFromOrdinals = new IntList(); this.unmatchedToOrdinals = new IntList(); this.hashedIdentityOrdinals = new int[0]; this.hashedIdentityOrdinalsCounts = new int[0]; this.matchedOrdinalsCounts = new int[0]; }
public int traverseMissingFields(IntList fromOrdinals, IntList toOrdinals) { int score = 0; for(int i=0;i<fieldNodes.length;i++) { if(fieldRequiresMissingFieldTraversal[i]) { traversalFromOrdinals.clear(); traversalToOrdinals.clear(); if(fromFieldMapping[i] != -1) { for(int j=0;j<fromOrdinals.size();j++) { int fromOrdinal = fromState.readOrdinal(fromOrdinals.get(j), fromFieldMapping[i]); if(fromOrdinal != -1) traversalFromOrdinals.add(fromOrdinal); } } if(toFieldMapping[i] != -1) { for(int j=0;j<toOrdinals.size();j++) { int toOrdinal = toState.readOrdinal(toOrdinals.get(j), toFieldMapping[i]); if(toOrdinal != -1) traversalToOrdinals.add(toOrdinal); } } score += fieldNodes[i].traverseMissingFields(traversalFromOrdinals, traversalToOrdinals); } else if(fieldNodes[i] instanceof HollowDiffFieldCountingNode) { score += fieldNodes[i].traverseMissingFields(fromOrdinals, toOrdinals); } } return score; }
/** * @return the transitive child branch field positions */ public IntList setUpMultiplication() { this.shouldMultiplyBranchResults = shouldMultiplyBranchResults(); this.childrenRepeatCounts = new int[children.size()]; this.childrenMatchCounts = new int[children.size()]; this.fieldChildMap = new int[fieldMatches.length]; this.childFirstFieldMap = new int[children.size()]; Arrays.fill(fieldChildMap, -1); IntList branchFieldPositions = new IntList(); if(indexedFieldPosition != -1) branchFieldPositions.add(indexedFieldPosition); int childCounter = 0; for(Map.Entry<String, HollowIndexerTraversalNode> entry : children.entrySet()) { IntList childBranchFieldPositions = entry.getValue().setUpMultiplication(); this.childFirstFieldMap[childCounter] = childBranchFieldPositions.get(0); for(int i=0;i<childBranchFieldPositions.size();i++) { this.fieldChildMap[childBranchFieldPositions.get(i)] = childCounter; branchFieldPositions.add(childBranchFieldPositions.get(i)); } childCounter++; } return branchFieldPositions; }
/** * @param diffPairIdx a number from 0-n, where n is the value returned from numDiffs * @return the from ordinal for the (diffPairIdx)th record pair in which there were differences for this field. */ public int getFromOrdinal(int diffPairIdx) { return diffFromOrdinals.get(diffPairIdx); }
private HollowListWriteRecord copyToWriteRecord(List<?> l, FlatRecordWriter flatRecordWriter) { HollowListWriteRecord rec = (HollowListWriteRecord) writeRecord(); if (ignoreListOrdering) { IntList ordinalList = getIntList(); for (Object o : l) { if (o == null) { throw new NullPointerException(String.format(NULL_ELEMENT_MESSAGE, schema)); } int ordinal = flatRecordWriter == null ? elementMapper.write(o) : elementMapper.writeFlat(o, flatRecordWriter); ordinalList.add(ordinal); } ordinalList.sort(); for (int i = 0; i < ordinalList.size(); i++) rec.addElement(ordinalList.get(i)); } else { for (Object o : l) { if (o == null) { throw new NullPointerException(String.format(NULL_ELEMENT_MESSAGE, schema)); } int ordinal = flatRecordWriter == null ? elementMapper.write(o) : elementMapper.writeFlat(o, flatRecordWriter); rec.addElement(ordinal); } } return rec; }
public void putEqualOrdinals(int fromOrdinal, IntList toOrdinals) { long fromOrdinalMapEntry = (long)toOrdinals.get(0) << 32 | fromOrdinal; if(toOrdinals.size() > 1) { fromOrdinalMapEntry = Long.MIN_VALUE | (long)pivotedToOrdinalClusters.size() << 32 | fromOrdinal; for(int i=0;i<toOrdinals.size();i++) { int valueToAdd = toOrdinals.get(i); if(i == toOrdinals.size() - 1) valueToAdd |= Integer.MIN_VALUE; pivotedToOrdinalClusters.add(valueToAdd); } } int hashCode = HashCodes.hashInt(fromOrdinal); int bucket = hashCode & (fromOrdinalsMap.length - 1); while(fromOrdinalsMap[bucket] != -1) bucket = (bucket + 1) & (fromOrdinalsMap.length - 1); fromOrdinalsMap[bucket] = fromOrdinalMapEntry; }
/** * @return the number of records which had at least one diff for this field. */ public int getNumDiffs() { return diffToOrdinals.size(); }
childrenMatchCounts[i] = fieldMatches[childFirstFieldMap[i]].size() - currentMultiplyFieldMatchListPosition; childrenRepeatCounts[i] = nextRepeatCount; nextRepeatCount *= childrenMatchCounts[i]; fieldMatches[childFirstFieldMap[i]].expandTo(currentMultiplyFieldMatchListPosition); fieldMatches[i].expandTo(newFieldMatchListPosition); while(currentCopyToIdx > currentMultiplyFieldMatchListPosition) { for(int j=0;j<childrenRepeatCounts[fieldChildMap[i]];j++) { fieldMatches[i].set(currentCopyToIdx, fieldMatches[i].get(currentCopyFromIdx)); currentCopyToIdx--; return fieldMatches[childFirstFieldMap[0]].size() - currentMultiplyFieldMatchListPosition;
private void fillTraversalLists(IntList fromOrdinals, IntList toOrdinals) { traversalFromOrdinals.clear(); traversalToOrdinals.clear(); if(fromState != null) { for(int i=0;i<fromOrdinals.size();i++) { fillListWithReferencedOrdinals(fromState, fromOrdinals.get(i), traversalFromOrdinals); } } if(toState != null) { for(int i=0;i<toOrdinals.size();i++) { fillListWithReferencedOrdinals(toState, toOrdinals.get(i), traversalToOrdinals); } } }
private void assertResults(HollowHistoryKeyIndex keyIdx, String type, String query, int... expectedResults) { IntList actualResults = keyIdx.getTypeKeyIndexes().get(type).queryIndexedFields(query); Assert.assertEquals(expectedResults.length, actualResults.size()); actualResults.sort(); for(int i=0;i<expectedResults.length;i++) { Assert.assertEquals(expectedResults[i], actualResults.get(i)); } }
private boolean populateIntList(IntList list, HollowOrdinalIterator iter, OrdinalIdentityTranslator identityTranslator) { list.clear(); int nextOrdinal = iter.next(); while(nextOrdinal != HollowOrdinalIterator.NO_MORE_ORDINALS) { int identityOrdinal = identityTranslator.getIdentityOrdinal(nextOrdinal); if(identityOrdinal == -1 && nextOrdinal != -1) return false; list.add(identityOrdinal); nextOrdinal = iter.next(); } if(!orderingIsImportant) list.sort(); return true; } };
public boolean recordsAreEqual(int ordinal) { int size = fromSetState.size(ordinal); if(toSetState.size(ordinal) != size) return false; fromScratch.clear(); toScratch.clear(); HollowOrdinalIterator iter = fromSetState.ordinalIterator(ordinal); int next = iter.next(); while(next != HollowOrdinalIterator.NO_MORE_ORDINALS) { fromScratch.add(next); next = iter.next(); } iter = toSetState.ordinalIterator(ordinal); next = iter.next(); while(next != HollowOrdinalIterator.NO_MORE_ORDINALS) { toScratch.add(next); next = iter.next(); } fromScratch.sort(); toScratch.sort(); return fromScratch.equals(toScratch); } };
public void addElement(int ordinal) { elementOrdinals.add(ordinal); }
public int write(HollowSchema schema, HollowWriteRecord rec) { int schemaOrdinal = schemaIdMapper.getSchemaId(schema); int nextRecordOrdinal = recordLocationsByOrdinal.size(); existingRecLocs = Collections.<RecordLocation>singletonList(newRecordLocation); recordLocationsByHashCode.put(recordHashCode, existingRecLocs); recordLocationsByOrdinal.add(recStart);