Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -760,14 +760,16 @@ public void onUpdate(TableUpdate upstream) {

final SegmentedSortedArray rightSsa = asOfJoinStateManager.getRightSsa(slot);

final RowSet rightAdded = sequentialBuilders.get(slotIndex).build();
sequentialBuilders.set(slotIndex, null);
final int rightSize;
try (final RowSet rightAdded = sequentialBuilders.get(slotIndex).build()) {
sequentialBuilders.set(slotIndex, null);

final int rightSize = rightAdded.intSize();
rightSize = rightAdded.intSize();

rightStampSource.fillChunk(rightStampFillContext.ensureCapacity(rightSize),
rightStampChunk.ensureCapacity(rightSize), rightAdded);
rightAdded.fillRowKeyChunk(insertedIndices.ensureCapacity(rightSize));
rightStampSource.fillChunk(rightStampFillContext.ensureCapacity(rightSize),
rightStampChunk.ensureCapacity(rightSize), rightAdded);
rightAdded.fillRowKeyChunk(insertedIndices.ensureCapacity(rightSize));
}
sortContext.ensureCapacity(rightSize).sort(insertedIndices.get(), rightStampChunk.get());

final int valuesWithNext = rightSsa.insertAndGetNextValue(rightStampChunk.get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,20 +507,21 @@ void flushLeftRemoves() {
continue;
}

final RowSet leftRemoved = slotState.indexBuilder.build();
slotState.leftRowSet.remove(leftRemoved);
slotState.indexBuilder = RowSetFactory.builderRandom();
long sizePrev = slotState.rightRowSet.sizePrev();
if (sizePrev > 0) {
leftRemoved.forAllRowKeys(ii -> {
final long prevOffset = ii << jsm.getPrevNumShiftBits();
builder.addRange(prevOffset, prevOffset + sizePrev - 1);
});
} else if (jsm.leftOuterJoin()) {
leftRemoved.forAllRowKeys(ii -> {
final long prevOffset = ii << jsm.getPrevNumShiftBits();
builder.addKey(prevOffset);
});
final long sizePrev = slotState.rightRowSet.sizePrev();
try (final RowSet slotLeftRemoved = slotState.indexBuilder.build()) {
slotState.leftRowSet.remove(slotLeftRemoved);
slotState.indexBuilder = RowSetFactory.builderRandom();
if (sizePrev > 0) {
slotLeftRemoved.forAllRowKeys(ii -> {
final long prevOffset = ii << jsm.getPrevNumShiftBits();
builder.addRange(prevOffset, prevOffset + sizePrev - 1);
});
} else if (jsm.leftOuterJoin()) {
slotLeftRemoved.forAllRowKeys(ii -> {
final long prevOffset = ii << jsm.getPrevNumShiftBits();
builder.addKey(prevOffset);
});
}
}
}
leftRemoved = builder.build();
Expand All @@ -534,22 +535,23 @@ void flushLeftAdds() {
continue;
}

final RowSet leftAdded = slotState.indexBuilder.build();
slotState.leftRowSet.insert(leftAdded);
jsm.updateLeftRowRedirection(leftAdded, slotState.slotLocation);

slotState.indexBuilder = null;
long size = slotState.rightRowSet.size();
if (size > 0) {
leftAdded.forAllRowKeys(ii -> {
final long currOffset = ii << jsm.getNumShiftBits();
downstreamAdds.addRange(currOffset, currOffset + size - 1);
});
} else if (jsm.leftOuterJoin()) {
leftAdded.forAllRowKeys(ii -> {
final long currOffset = ii << jsm.getNumShiftBits();
downstreamAdds.addKey(currOffset);
});
final long size = slotState.rightRowSet.size();
try (final RowSet slotLeftAdded = slotState.indexBuilder.build()) {
slotState.leftRowSet.insert(slotLeftAdded);
jsm.updateLeftRowRedirection(slotLeftAdded, slotState.slotLocation);

slotState.indexBuilder = null;
if (size > 0) {
slotLeftAdded.forAllRowKeys(ii -> {
final long currOffset = ii << jsm.getNumShiftBits();
downstreamAdds.addRange(currOffset, currOffset + size - 1);
});
} else if (jsm.leftOuterJoin()) {
slotLeftAdded.forAllRowKeys(ii -> {
final long currOffset = ii << jsm.getNumShiftBits();
downstreamAdds.addKey(currOffset);
});
}
}

final RowSetBuilderRandom modifiedAdds = RowSetFactory.builderRandom();
Expand Down Expand Up @@ -598,21 +600,22 @@ void flushLeftModifies() {
if (slotState == null) {
continue;
}
final RowSet leftRemoved = slotState.indexBuilder.build();
slotState.leftRowSet.remove(leftRemoved);
jsm.updateLeftRowRedirection(leftRemoved, RowSequence.NULL_ROW_KEY);
slotState.indexBuilder = RowSetFactory.builderRandom();
final long sizePrev = slotState.rightRowSet.sizePrev();
if (sizePrev > 0) {
leftRemoved.forAllRowKeys(ii -> {
final long prevOffset = ii << jsm.getPrevNumShiftBits();
rmBuilder.addRange(prevOffset, prevOffset + sizePrev - 1);
});
} else if (jsm.leftOuterJoin()) {
leftRemoved.forAllRowKeys(ii -> {
final long prevOffset = ii << jsm.getPrevNumShiftBits();
rmBuilder.addKey(prevOffset);
});
try (final RowSet slotLeftRemoved = slotState.indexBuilder.build()) {
slotState.leftRowSet.remove(slotLeftRemoved);
jsm.updateLeftRowRedirection(slotLeftRemoved, RowSequence.NULL_ROW_KEY);
slotState.indexBuilder = RowSetFactory.builderRandom();
if (sizePrev > 0) {
slotLeftRemoved.forAllRowKeys(ii -> {
final long prevOffset = ii << jsm.getPrevNumShiftBits();
rmBuilder.addRange(prevOffset, prevOffset + sizePrev - 1);
});
} else if (jsm.leftOuterJoin()) {
slotLeftRemoved.forAllRowKeys(ii -> {
final long prevOffset = ii << jsm.getPrevNumShiftBits();
rmBuilder.addKey(prevOffset);
});
}
}
final long size = slotState.rightRowSet.size();
if (sizePrev > 0 && size > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1175,20 +1175,26 @@ public boolean rehashRequired() {
private void verifyKeyHashes() {
final int maxSize = tableHashPivot;

final ChunkSource.FillContext [] keyFillContext = makeFillContexts(keySources, SharedContext.makeSharedContext(), maxSize);
final ChunkSource.FillContext [] keyFillContext = new ChunkSource.FillContext[keySources.length];
final WritableChunk [] keyChunks = getWritableKeyChunks(maxSize);

try (final WritableLongChunk<RowKeys> positions = WritableLongChunk.makeWritableChunk(maxSize);
try (final SharedContext sharedContext = SharedContext.makeSharedContext();
final SafeCloseableArray ignored = new SafeCloseableArray<>(keyFillContext);
final SafeCloseableArray ignored2 = new SafeCloseableArray<>(keyChunks);
final WritableLongChunk<RowKeys> positions = WritableLongChunk.makeWritableChunk(maxSize);
final WritableBooleanChunk exists = WritableBooleanChunk.makeWritableChunk(maxSize);
final WritableIntChunk hashChunk = WritableIntChunk.makeWritableChunk(maxSize);
final WritableLongChunk<RowKeys> tableLocationsChunk = WritableLongChunk.makeWritableChunk(maxSize);
final SafeCloseableArray ignored = new SafeCloseableArray<>(keyFillContext);
final SafeCloseableArray ignored2 = new SafeCloseableArray<>(keyChunks);
final RowSet flatRowSet = RowSetFactory.flat(tableHashPivot);
// @StateChunkName@ from \QObjectChunk\E
final WritableObjectChunk stateChunk = WritableObjectChunk.makeWritableChunk(maxSize);
final ChunkSource.FillContext fillContext = rightRowSetSource.makeFillContext(maxSize)) {

rightRowSetSource.fillChunk(fillContext, stateChunk, RowSetFactory.flat(tableHashPivot));
for (int ii = 0; ii < keySources.length; ++ii) {
keyFillContext[ii] = keySources[ii].makeFillContext(maxSize, sharedContext);
}

rightRowSetSource.fillChunk(fillContext, stateChunk, flatRowSet);

ChunkUtils.fillInOrder(positions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1532,20 +1532,26 @@ public boolean rehashRequired() {
private void verifyKeyHashes() {
final int maxSize = tableHashPivot;

final ChunkSource.FillContext [] keyFillContext = makeFillContexts(keySources, SharedContext.makeSharedContext(), maxSize);
final ChunkSource.FillContext [] keyFillContext = new ChunkSource.FillContext[keySources.length];
final WritableChunk [] keyChunks = getWritableKeyChunks(maxSize);

try (final WritableLongChunk<RowKeys> positions = WritableLongChunk.makeWritableChunk(maxSize);
try (final SharedContext sharedContext = SharedContext.makeSharedContext();
final SafeCloseableArray ignored = new SafeCloseableArray<>(keyFillContext);
final SafeCloseableArray ignored2 = new SafeCloseableArray<>(keyChunks);
final WritableLongChunk<RowKeys> positions = WritableLongChunk.makeWritableChunk(maxSize);
final WritableBooleanChunk exists = WritableBooleanChunk.makeWritableChunk(maxSize);
final WritableIntChunk hashChunk = WritableIntChunk.makeWritableChunk(maxSize);
final WritableLongChunk<RowKeys> tableLocationsChunk = WritableLongChunk.makeWritableChunk(maxSize);
final SafeCloseableArray ignored = new SafeCloseableArray<>(keyFillContext);
final SafeCloseableArray ignored2 = new SafeCloseableArray<>(keyChunks);
final RowSet flatRowSet = RowSetFactory.flat(tableHashPivot);
// @StateChunkName@ from \QObjectChunk\E
final WritableObjectChunk stateChunk = WritableObjectChunk.makeWritableChunk(maxSize);
final ChunkSource.FillContext fillContext = rightRowSetSource.makeFillContext(maxSize)) {

rightRowSetSource.fillChunk(fillContext, stateChunk, RowSetFactory.flat(tableHashPivot));
for (int ii = 0; ii < keySources.length; ++ii) {
keyFillContext[ii] = keySources[ii].makeFillContext(maxSize, sharedContext);
}

rightRowSetSource.fillChunk(fillContext, stateChunk, flatRowSet);

ChunkUtils.fillInOrder(positions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,35 +157,37 @@ public void onUpdate(TableUpdate upstream) {

private void onUpdate(final TableUpdate upstream) {
final TrackingWritableRowSet rowSet = resultTable.getRowSet().writableCast();
final RowSet sliceRowSet = computeSliceRowSet(parent.getRowSet());

final TableUpdateImpl downstream = new TableUpdateImpl();
downstream.removed = upstream.removed().intersect(rowSet);
rowSet.remove(downstream.removed());
try (final RowSet sliceRowSet = computeSliceRowSet(parent.getRowSet())) {
final TableUpdateImpl downstream = new TableUpdateImpl();
downstream.removed = upstream.removed().intersect(rowSet);
rowSet.remove(downstream.removed());

downstream.shifted = upstream.shifted().intersect(rowSet);
downstream.shifted().apply(rowSet);
downstream.shifted = upstream.shifted().intersect(rowSet);
downstream.shifted().apply(rowSet);

// Must calculate in post-shift space what indices were removed by the slice operation.
final WritableRowSet opRemoved = rowSet.minus(sliceRowSet);
rowSet.remove(opRemoved);
downstream.shifted().unapply(opRemoved);
downstream.removed().writableCast().insert(opRemoved);
// Must calculate in post-shift space what indices were removed by the slice operation.
try (final WritableRowSet opRemoved = rowSet.minus(sliceRowSet)) {
rowSet.remove(opRemoved);
downstream.shifted().unapply(opRemoved);
downstream.removed().writableCast().insert(opRemoved);
}

// Must intersect against modified set before adding the new rows to result rowSet.
downstream.modified = upstream.modified().intersect(rowSet);
// Must intersect against modified set before adding the new rows to result rowSet.
downstream.modified = upstream.modified().intersect(rowSet);

downstream.added = sliceRowSet.minus(rowSet);
rowSet.insert(downstream.added());
downstream.added = sliceRowSet.minus(rowSet);
rowSet.insert(downstream.added());

// propagate an empty MCS if modified is empty
downstream.modifiedColumnSet = upstream.modifiedColumnSet();
if (downstream.modified().isEmpty()) {
downstream.modifiedColumnSet = resultTable.getModifiedColumnSetForUpdates();
downstream.modifiedColumnSet.clear();
}
// propagate an empty MCS if modified is empty
downstream.modifiedColumnSet = upstream.modifiedColumnSet();
if (downstream.modified().isEmpty()) {
downstream.modifiedColumnSet = resultTable.getModifiedColumnSetForUpdates();
downstream.modifiedColumnSet.clear();
}

resultTable.notifyListeners(downstream);
resultTable.notifyListeners(downstream);
}
}

private WritableRowSet computeSliceRowSet(RowSet useRowSet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,20 +1136,26 @@ public boolean rehashRequired() {
private void verifyKeyHashes() {
final int maxSize = tableHashPivot;

final ChunkSource.FillContext [] keyFillContext = makeFillContexts(keySources, SharedContext.makeSharedContext(), maxSize);
final ChunkSource.FillContext [] keyFillContext = new ChunkSource.FillContext[keySources.length];
final WritableChunk [] keyChunks = getWritableKeyChunks(maxSize);

try (final WritableLongChunk<RowKeys> positions = WritableLongChunk.makeWritableChunk(maxSize);
try (final SharedContext sharedContext = SharedContext.makeSharedContext();
final SafeCloseableArray ignored = new SafeCloseableArray<>(keyFillContext);
final SafeCloseableArray ignored2 = new SafeCloseableArray<>(keyChunks);
final WritableLongChunk<RowKeys> positions = WritableLongChunk.makeWritableChunk(maxSize);
final WritableBooleanChunk exists = WritableBooleanChunk.makeWritableChunk(maxSize);
final WritableIntChunk hashChunk = WritableIntChunk.makeWritableChunk(maxSize);
final WritableLongChunk<RowKeys> tableLocationsChunk = WritableLongChunk.makeWritableChunk(maxSize);
final SafeCloseableArray ignored = new SafeCloseableArray<>(keyFillContext);
final SafeCloseableArray ignored2 = new SafeCloseableArray<>(keyChunks);
final RowSet flatRowSet = RowSetFactory.flat(tableHashPivot);
// @StateChunkName@ from \QLongChunk\E
final WritableLongChunk stateChunk = WritableLongChunk.makeWritableChunk(maxSize);
final ChunkSource.FillContext fillContext = slotSource.makeFillContext(maxSize)) {

slotSource.fillChunk(fillContext, stateChunk, RowSetFactory.flat(tableHashPivot));
for (int ii = 0; ii < keySources.length; ++ii) {
keyFillContext[ii] = keySources[ii].makeFillContext(maxSize, sharedContext);
}

slotSource.fillChunk(fillContext, stateChunk, flatRowSet);

ChunkUtils.fillInOrder(positions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1006,20 +1006,26 @@ public boolean rehashRequired() {
private void verifyKeyHashes() {
final int maxSize = tableHashPivot;

final ChunkSource.FillContext [] keyFillContext = makeFillContexts(keySources, SharedContext.makeSharedContext(), maxSize);
final ChunkSource.FillContext [] keyFillContext = new ChunkSource.FillContext[keySources.length];
final WritableChunk [] keyChunks = getWritableKeyChunks(maxSize);

try (final WritableLongChunk<RowKeys> positions = WritableLongChunk.makeWritableChunk(maxSize);
try (final SharedContext sharedContext = SharedContext.makeSharedContext();
final SafeCloseableArray ignored = new SafeCloseableArray<>(keyFillContext);
final SafeCloseableArray ignored2 = new SafeCloseableArray<>(keyChunks);
final WritableLongChunk<RowKeys> positions = WritableLongChunk.makeWritableChunk(maxSize);
final WritableBooleanChunk exists = WritableBooleanChunk.makeWritableChunk(maxSize);
final WritableIntChunk hashChunk = WritableIntChunk.makeWritableChunk(maxSize);
final WritableLongChunk<RowKeys> tableLocationsChunk = WritableLongChunk.makeWritableChunk(maxSize);
final SafeCloseableArray ignored = new SafeCloseableArray<>(keyFillContext);
final SafeCloseableArray ignored2 = new SafeCloseableArray<>(keyChunks);
final RowSet flatRowSet = RowSetFactory.flat(tableHashPivot);
// @StateChunkName@ from \QIntChunk\E
final WritableIntChunk stateChunk = WritableIntChunk.makeWritableChunk(maxSize);
final ChunkSource.FillContext fillContext = uniqueIdentifierSource.makeFillContext(maxSize)) {

uniqueIdentifierSource.fillChunk(fillContext, stateChunk, RowSetFactory.flat(tableHashPivot));
for (int ii = 0; ii < keySources.length; ++ii) {
keyFillContext[ii] = keySources[ii].makeFillContext(maxSize, sharedContext);
}

uniqueIdentifierSource.fillChunk(fillContext, stateChunk, flatRowSet);

ChunkUtils.fillInOrder(positions);

Expand Down
Loading
Loading