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 @@ -81,7 +81,7 @@ public Tuple<Collection<ExecutionLineageNode>, Collection<ChannelInstance>> eval

int sampleSize = this.getSampleSize(operatorContext);

if (sampleSize >= datasetSize) { //return all
if (this.isDataSetSizeKnown() && sampleSize >= datasetSize) { //return all
((CollectionChannel.Instance) outputs[0]).accept(((JavaChannelInstance) inputs[0]).provideStream().collect(Collectors.toList()));
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,33 @@ void testExecution() {
assertEquals(sampleSize, result.size());
}

@Test
void testExecutionWithUnknownDatasetSize() {
// Prepare test data. The dataset size is deliberately left unknown
// (setDatasetSize is never called), which is the normal case for a
// reservoir sample over a stream.
Stream<Integer> inputStream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
final int sampleSize = 5;

// Build the operator.
JavaReservoirSampleOperator<Integer> sampleOperator =
new JavaReservoirSampleOperator<>(
iterationNumber -> sampleSize,
DataSetType.createDefaultUnchecked(Integer.class),
iterationNumber -> 42L
);

JavaChannelInstance[] inputs = new JavaChannelInstance[]{createStreamChannelInstance(inputStream)};
JavaChannelInstance[] outputs = new JavaChannelInstance[]{createCollectionChannelInstance()};

// Execute.
evaluate(sampleOperator, inputs, outputs);

// Verify the outcome: a sample of the requested size, not the whole input.
final List<Integer> result = outputs[0].<Integer>provideStream().collect(Collectors.toList());
assertEquals(sampleSize, result.size());
}

@Test
void testLargerSampleExecution() {
// Prepare test data.
Expand Down