JavaReservoirSampleOperator returns the whole input when the dataset size is unknown

Đang mở Phù hợp với người mới
#884 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@sasmith-14 đang làm issue này rồi.

Từ ngày 14/11/2026.

  • #885 của @sasmith-14 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
data

Hướng nghiên cứu

Đọc wayang-platforms/wayang-java/src/main/java/org/apache/wayang/java/operators/JavaReservoirSampleOperator.java quanh dòng 84, rồi so sánh với guard isDataSetSizeKnown() trong JavaRandomSampleOperator anh em. Mở rộng JavaReservoirSampleOperatorTest, vốn luôn gọi setDatasetSize(10), với một trường hợp để kích thước không xác định và khẳng định đúng 5 trong 10 phần tử đi ra. Lưu ý rằng người báo cáo nói một fix và PR đã được chuẩn bị sẵn, nên hãy kiểm tra thread trước khi bắt đầu.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Java
Star
284
Fork
143
Merge trung bình
2 ngày 6 giờ
Pull request đã merge (30 ngày)
16

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/wayang

Tất cả issue của apache/wayang

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.