JavaReservoirSampleOperator returns the whole input when the dataset size is unknown
维护者通常 2 天内回复
评估
调研方向
阅读 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 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/wayang 的其他 Issue
-
Record.compareTo() throws ClassCastException when comparing records可能已有人在做 @harshitsingh070 于 64 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 2 天内回复
-
Unused parameter in function ProjectionDescriptor.createPojoJavaImplementation()可能已有人在做 @AliRana30 于 72 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 2 天内回复
-
难度 4/5 3-5 天 新手友好度 42/100
维护者通常 2 天内回复
-
Add ClickHouse platform support (wayang-clickhouse)可能已有人在做 @ekas-7 于 6 天前认领。 未关闭
难度 5/5 一周以上 新手友好度 25/100
维护者通常 2 天内回复
-
[PyWayang] Implement load_collection() and collect()可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 4/5 3-5 天 新手友好度 25/100
维护者通常 2 天内回复
相似的 Issue
-
area-templates triage:bot-seen triage:needs-human
难度 2/5 1-3 小时 新手友好度 75/100
microsoft/aspire#22356 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
apache/flink-agents#1395 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
microsoft/kiota-java#2257 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
openhab/openhab-core#5992 ·
维护者通常 1 天内回复