/* Perform discards on the relationNumber dimension 1=first 2=second */
protected void performDiscards(int relationNumber) {
final PredicateCreateIndexesVisitor visitor = new PredicateCreateIndexesVisitor();
_joinPredicate.accept(visitor);
final TupleStorage keepStorage = new TupleStorage();
ArrayList<Index> keepIndexes;
String discardingEmitterIndex;
int discardingParts, discardingIndex;
TupleStorage discardingTupleStorage, discardingTaggedRelationStorage;
if (relationNumber == 1) {
discardingTupleStorage = _firstRelationStorage;
discardingTaggedRelationStorage = _firstTaggedRelationStorage;
keepIndexes = new ArrayList<Index>(visitor._firstRelationIndexes);
discardingEmitterIndex = _firstEmitterIndex;
discardingParts = _currentAction.getDiscardRowSplits();
discardingIndex = _currentAction.getRowKeptPieceIndexByNewId(_renamedIDindex);
} else {
discardingTupleStorage = _secondRelationStorage;
discardingTaggedRelationStorage = _secondTaggedRelationStorage;
keepIndexes = new ArrayList<Index>(visitor._secondRelationIndexes);
discardingEmitterIndex = _secondEmitterIndex;
discardingParts = _currentAction.getDiscardColumnSplits();
discardingIndex = _currentAction.getColumnKeptPieceIndexByNewId(_renamedIDindex);
}
final int[] hash = new int[discardingTaggedRelationStorage.size()
+ discardingTupleStorage.size()];
final int[] addresses = new int[discardingTaggedRelationStorage.size()
+ discardingTupleStorage.size()];
final BitVector isTagged = new BitVector(discardingTaggedRelationStorage.size()
+ discardingTupleStorage.size());
isTagged.set(0, discardingTaggedRelationStorage.size());
TupleStorage.preProcess(discardingTaggedRelationStorage, discardingTupleStorage, hash,
addresses);
final int bounds[] = Discard.keep(hash, addresses, isTagged, discardingParts,
discardingIndex);
for (int i = bounds[0]; i <= bounds[1]; i++) {
final int address = addresses[i];
final boolean isTaggedTuple = isTagged.get(i);
String tupleString = "";
if (isTaggedTuple)
tupleString = discardingTaggedRelationStorage.get(address);
else
tupleString = discardingTupleStorage.get(address);
final int row_id = keepStorage.insert(tupleString);
if (_existIndexes) {
if (MyUtilities.isStoreTimestamp(getConf(), getHierarchyPosition())) {
// timestamp has to be removed
final String parts[] = tupleString.split("\\@");
tupleString = new String(parts[1]);
}
updateIndexes(discardingEmitterIndex,
MyUtilities.stringToTuple(tupleString, getConf()), keepIndexes, row_id);
}
}
if (relationNumber == 1) {
_firstTaggedRelationStorage = keepStorage;
_firstTaggedRelationIndexes = keepIndexes;
_firstRelationStorage = _firstRelationStorageNewEpoch;
_firstRelationIndexes = _firstRelationIndexesNewEpoch;
_firstRelationStorageNewEpoch = new TupleStorage();
createIndexes(1, false, true);
} else {
_secondTaggedRelationStorage = keepStorage;
_secondTaggedRelationIndexes = keepIndexes;
_secondRelationStorage = _secondRelationStorageNewEpoch;
_secondRelationIndexes = _secondRelationIndexesNewEpoch;
_secondRelationStorageNewEpoch = new TupleStorage();
createIndexes(2, false, true);
}
}