Matthew-DWM opened a new pull request, #9505:
URL: https://github.com/apache/texera/pull/9505

   ### What changes were proposed in this PR?
   
   Reservoir Sampling runs Algorithm R, where the row at 0-based position `n` 
replaces a random slot with probability `k / (n + 1)`. The executor drew that 
slot with `rand.nextInt(n)`, one position short, and the script that Export to 
Python generates copied the bound.
   
   ```
   Before:  k = 1, rows [10, 20]  ->  row 20 draws nextInt(1), always 0  ->  
always keeps 20
   After:   k = 1, rows [10, 20]  ->  row 20 draws nextInt(2)            ->  
keeps either row, half the time each
   
   Before:  k = 1, 2 workers  ->  worker 1's share is 0  ->  nextInt(0) throws, 
worker pauses  ->  run stays Running
   After:   k = 1, 2 workers  ->  worker 1's share is 0  ->  keeps nothing      
               ->  run completes
   ```
   
   k is split across the operator's workers (two by default), so any k below 
the worker count left a worker with a share of 0 and a run that neither 
completed nor failed.
   
   - `ReservoirSamplingOpExec` draws from `n + 1`.
   - A sample size below 1 is still refused, now with a message that says why 
("needs a sample size of at least 1, got 0", not "bound must be positive"). It 
is checked at each pass's first row, since a loop block writes k after `open()`.
   - The generated script draws from `n + 1` and refuses k below 1 the same 
way, so the engine and the script still keep the same rows.
   
   A seeded run now returns different rows than before; that is the correction. 
The sample is uniform within each worker but still not across workers, because 
every worker seeds its generator with the worker count.
   
   ### Any related issues, documentation, discussions?
   
   Closes #9503
   
   ### How was this PR tested?
   
   The new and updated tests all pass with the fix; 6 of them fail on `main`.
   
   - `ReservoirSamplingOpExecSpec`:
     - the sample matches a reference Algorithm R run on the same seeded 
generator;
     - a worker whose share is 0 (k = 1, 2 workers) keeps nothing and doesn't 
throw;
     - k = 0 is refused with the new message, and so is k = -1 on 3 workers, 
where every share rounds to 0.
   - `ReservoirSamplingOpDescSpec`:
     - the generated snippet;
     - the script refuses k = 0 and k = -1 with the same message;
     - it returns an empty table for k = 0 over an empty table, as the engine 
does;
     - it keeps the same rows as the engine on four inputs (k from 1 to 7, up 
to 1,000 rows).
     - The last two pass on `main` too; they guard against fixing only one side.
   
   ```
   sbt "WorkflowOperator/testOnly *ReservoirSampling* *RandomKSampling* 
*SamplingHelpers*"  # 38 passed
   AMBER_TEST_FILTER=skip-integration sbt WorkflowOperator/jacoco               
             # 2,944 passed
   AMBER_TEST_FILTER=integration-only sbt WorkflowOperator/test                 
             # 81 passed
   sbt scalafmtCheckAll "scalafixAll --check"                                   
             # clean
   ```
   
   End to end (an engine run, not part of this PR), a CSV scan of 1,000 rows 
into Reservoir Sampling on the default two workers: on `main`, k = 1 logs 
"bound must be positive" and is still Running after 45 s; with this change it 
completes with one row.
   
   ### Was this PR authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Claude Opus 5.5)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to