JavaReservoirSampleOperator returns the whole input when the dataset size is unknown

未关闭 适合新手
#884 3 条评论 0 个 reaction 已指派 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() 守卫进行比较。扩展 JavaReservoirSampleOperatorTest(它总是调用 setDatasetSize(10)),添加一个让大小保持未知并断言 10 个元素中恰好输出 5 个的用例。注意报告者说 fix 和 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 小时
30 天内合并 PR
16

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/wayang 的其他 Issue

查看 apache/wayang 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。