Github user ChengXiangLi commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1110#discussion_r39003293
  
    --- Diff: 
flink-java/src/main/java/org/apache/flink/api/java/sampling/BernoulliSampler.java
 ---
    @@ -102,15 +106,31 @@ public T next() {
                        }
     
                        private T getNextSampledElement() {
    -                           while (input.hasNext()) {
    -                                   T element = input.next();
    -
    -                                   if (random.nextDouble() <= fraction) {
    +                           if (fraction <= THRESHOLD) {
    +                                   double rand = random.nextDouble();
    +                                   double u = Math.max(rand, EPSILON);
    +                                   int gap = (int) (Math.log(u) / 
Math.log(1 - fraction));
    +                                   int elementCount = 0;
    +                                   if (input.hasNext()) {
    +                                           T element = input.next();
    +                                           while (input.hasNext() && 
elementCount < gap) {
    --- End diff --
    
    While gap is larger than the input remain elements number, this should 
return null, right? but the implementation here return the last input element.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to