szehon-ho commented on code in PR #56031:
URL: https://github.com/apache/spark/pull/56031#discussion_r3283349911


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ScanRelationPushDown.scala:
##########
@@ -151,11 +151,14 @@ object V2ScanRelationPushDown extends Rule[LogicalPlan] 
with PredicateHelper {
         rightProjections.forall(_.isInstanceOf[AttributeReference]) &&
         // Cross joins are not supported because they increase the amount of 
data.
         condition.isDefined &&
-        // Do not push down join if either side has a pushed sample, because
-        // the merged scan builder would silently discard it.
+        // Do not push down join if either side has a pushed sample with
+        // fraction < 1, because the merged scan builder would silently
+        // discard it and change the result. At fraction = 1 the sample is
+        // a no-op on the result set, so dropping it is safe.
         // TODO(SPARK-56504): Extend SupportsPushDownJoin to accept pushed
         //   samples so sources supporting both can handle the composition.
-        leftHolder.pushedSample.isEmpty && rightHolder.pushedSample.isEmpty &&
+        leftHolder.pushedSample.forall(s => s.upperBound - s.lowerBound >= 
1.0) &&

Review Comment:
   `upperBound - lowerBound >= 1.0` does not check `withReplacement`. With 
`withReplacement = true`, `SampleExec` uses `PoissonSampler`: even at rate 
`1.0`, each input row can be emitted 0, 1, 2, … times, so discarding the pushed 
sample during join pushdown is **not** the same as a full scan. SQL 
`TABLESAMPLE` always sets `withReplacement = false`, but 
`DataFrame.sample(withReplacement = true, fraction = 1.0)` can be pushed to 
DSv2.
   
   Suggest tightening the guard, e.g.:
   
   ```scala
   !s.withReplacement && s.upperBound - s.lowerBound >= 1.0
   ```
   
   (optionally also `s.lowerBound <= RandomSampler.roundingEpsilon` for 
clarity).



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to