public class Sample extends BaseOperation<Random> implements Filter<Random>
Filter
that only allows the given fraction of Tuple
instances to pass.
Where fraction is between 1 and zero, inclusive. Thus to sample 50%
of the tuples in a stream, use the
fraction 0.5
.
By default, the seed is created at random on the constructor. This implies every branch using the Sample
filter will return the same random stream based on that seed. So if this Sample instance is distributed
into multiple systems against the same data, the result will be the same tuple stream. The alternative
would be to make this Operation "not safe". See Operation.isSafe()
.
Conversely, if the same stream of random data is require across application executions, set the seed manually.
The seed is generated from the following code:
System.identityHashCode(this) * 2654435761L ^ System.currentTimeMillis()
Override makeSeed()
to customize.fieldDeclaration, numArgs, trace
Constructor and Description |
---|
Sample(double fraction)
Creates a new Sample that permits percent Tuples to pass.
|
Sample(long seed,
double fraction)
Creates a new Sample that permits percent Tuples to pass.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object object) |
double |
getFraction() |
long |
getSeed() |
int |
hashCode() |
boolean |
isRemove(FlowProcess flowProcess,
FilterCall<Random> filterCall)
Method isRemove returns true if input should be removed from the tuple stream.
|
protected long |
makeSeed() |
void |
prepare(FlowProcess flowProcess,
OperationCall<Random> operationCall)
Method prepare does nothing, and may safely be overridden.
|
cleanup, flush, getFieldDeclaration, getNumArgs, getTrace, isSafe, printOperationInternal, toString, toStringInternal
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
cleanup, flush, getFieldDeclaration, getNumArgs, isSafe
@ConstructorProperties(value="fraction") public Sample(double fraction)
fraction
- of type double@ConstructorProperties(value={"seed","fraction"}) public Sample(long seed, double fraction)
seed
- of type longfraction
- of type doublepublic long getSeed()
public double getFraction()
protected long makeSeed()
public void prepare(FlowProcess flowProcess, OperationCall<Random> operationCall)
BaseOperation
public boolean isRemove(FlowProcess flowProcess, FilterCall<Random> filterCall)
Filter
public boolean equals(Object object)
equals
in class BaseOperation<Random>
public int hashCode()
hashCode
in class BaseOperation<Random>
Copyright © 2007-2015 Concurrent, Inc. All Rights Reserved.