org.apache.flink.api.java.sampling.ReservoirSamplerWithReplacement Java Examples

The following examples show how to use org.apache.flink.api.java.sampling.ReservoirSamplerWithReplacement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SampleInPartition.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void mapPartition(Iterable<T> values, Collector<IntermediateSampleData<T>> out) throws Exception {
	DistributedRandomSampler<T> sampler;
	long seedAndIndex = seed + getRuntimeContext().getIndexOfThisSubtask();
	if (withReplacement) {
		sampler = new ReservoirSamplerWithReplacement<T>(numSample, seedAndIndex);
	} else {
		sampler = new ReservoirSamplerWithoutReplacement<T>(numSample, seedAndIndex);
	}

	Iterator<IntermediateSampleData<T>> sampled = sampler.sampleInPartition(values.iterator());
	while (sampled.hasNext()) {
		out.collect(sampled.next());
	}
}
 
Example #2
Source File: SampleInCoordinator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void reduce(Iterable<IntermediateSampleData<T>> values, Collector<T> out) throws Exception {
	DistributedRandomSampler<T> sampler;
	if (withReplacement) {
		sampler = new ReservoirSamplerWithReplacement<>(numSample, seed);
	} else {
		sampler = new ReservoirSamplerWithoutReplacement<>(numSample, seed);
	}

	Iterator<T> sampled = sampler.sampleInCoordinator(values.iterator());
	while (sampled.hasNext()) {
		out.collect(sampled.next());
	}
}
 
Example #3
Source File: SampleInPartition.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void mapPartition(Iterable<T> values, Collector<IntermediateSampleData<T>> out) throws Exception {
	DistributedRandomSampler<T> sampler;
	long seedAndIndex = seed + getRuntimeContext().getIndexOfThisSubtask();
	if (withReplacement) {
		sampler = new ReservoirSamplerWithReplacement<T>(numSample, seedAndIndex);
	} else {
		sampler = new ReservoirSamplerWithoutReplacement<T>(numSample, seedAndIndex);
	}

	Iterator<IntermediateSampleData<T>> sampled = sampler.sampleInPartition(values.iterator());
	while (sampled.hasNext()) {
		out.collect(sampled.next());
	}
}
 
Example #4
Source File: SampleInCoordinator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void reduce(Iterable<IntermediateSampleData<T>> values, Collector<T> out) throws Exception {
	DistributedRandomSampler<T> sampler;
	if (withReplacement) {
		sampler = new ReservoirSamplerWithReplacement<>(numSample, seed);
	} else {
		sampler = new ReservoirSamplerWithoutReplacement<>(numSample, seed);
	}

	Iterator<T> sampled = sampler.sampleInCoordinator(values.iterator());
	while (sampled.hasNext()) {
		out.collect(sampled.next());
	}
}
 
Example #5
Source File: SampleInPartition.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void mapPartition(Iterable<T> values, Collector<IntermediateSampleData<T>> out) throws Exception {
	DistributedRandomSampler<T> sampler;
	long seedAndIndex = seed + getRuntimeContext().getIndexOfThisSubtask();
	if (withReplacement) {
		sampler = new ReservoirSamplerWithReplacement<T>(numSample, seedAndIndex);
	} else {
		sampler = new ReservoirSamplerWithoutReplacement<T>(numSample, seedAndIndex);
	}

	Iterator<IntermediateSampleData<T>> sampled = sampler.sampleInPartition(values.iterator());
	while (sampled.hasNext()) {
		out.collect(sampled.next());
	}
}
 
Example #6
Source File: SampleInCoordinator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void reduce(Iterable<IntermediateSampleData<T>> values, Collector<T> out) throws Exception {
	DistributedRandomSampler<T> sampler;
	if (withReplacement) {
		sampler = new ReservoirSamplerWithReplacement<>(numSample, seed);
	} else {
		sampler = new ReservoirSamplerWithoutReplacement<>(numSample, seed);
	}

	Iterator<T> sampled = sampler.sampleInCoordinator(values.iterator());
	while (sampled.hasNext()) {
		out.collect(sampled.next());
	}
}