JavaReservoirSampleOperator returns the whole input when the dataset size is unknown

オープン 初心者向け
#884 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@sasmith-14 がすでに取り組んでいます。

2026年11月14日 から。

  • #885 @sasmith-14 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java
領域
data

調査の方向性

wayang-platforms/wayang-java/src/main/java/org/apache/wayang/java/operators/JavaReservoirSampleOperator.java の 84 行目付近を読み、次に兄弟の JavaRandomSampleOperator にある isDataSetSizeKnown() ガードと比較してください。常に setDatasetSize(10) を呼ぶ JavaReservoirSampleOperatorTest を拡張し、サイズを不明のままにして 10 個中ちょうど 5 個の要素が出ることをアサートするケースを追加してください。報告者が修正と PR はすでに用意済みだと言っているので、始める前にスレッドを確認してください。

索引モデルが issue の本文から書いたものです。

説明

JavaReservoirSampleOperator returns the entire input instead of a sample whenever the dataset size is unknown.

The bug

evaluate() takes a "return all" shortcut at JavaReservoirSampleOperator.java:84:

if (sampleSize >= datasetSize) { // return all

datasetSize defaults to SampleOperator.UNKNOWN_DATASET_SIZE (0). So when the size isn't known, sampleSize >= 0 is always true and the operator emits every element. The sibling JavaRandomSampleOperator already guards this with isDataSetSizeKnown() — the reservoir operator doesn't.

Reproduce

Sample 5 from 10 elements, without setting the dataset size (the normal streaming case):

JavaReservoirSampleOperator<Integer> op = new JavaReservoirSampleOperator<>(
        it -> 5, DataSetType.createDefaultUnchecked(Integer.class), it -> 42L);
// no setDatasetSize(...)  ->  size is UNKNOWN
// input: 1..10
Result
Expected 5 elements
Actual 10 elements (all of them)

The existing JavaReservoirSampleOperatorTest always calls setDatasetSize(10), so it never hits this path.

Environment

wayang-platforms/wayang-java · main (713faa7d) and 1.1.1.

Fix

A one-line guard (isDataSetSizeKnown() && …) plus a regression test — the streaming reservoir algorithm already handles inputs smaller than the sample size. I have it ready and can open a PR.

主要言語
Java
スター
284
フォーク
143
平均マージ
2日 6時間
マージ済み PR(30日)
16

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/wayang のほかの issue

apache/wayang の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。