viirya commented on code in PR #44636:
URL: https://github.com/apache/spark/pull/44636#discussion_r1480266624


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/FileStreamSource.scala:
##########
@@ -166,6 +197,25 @@ class FileStreamSource(
         // implies "sourceOptions.latestFirst = true" which we want to refresh 
the list per batch
         (newFiles.take(files.maxFiles()), null)
 
+      case files: ReadMaxBytes if !sourceOptions.latestFirst =>
+        // we can cache and reuse remaining fetched list of files in further 
batches
+        val (FilesSplit(bFiles, _), FilesSplit(usFiles, rSize)) =
+          takeFilesUntilMax(newFiles, files.maxBytes())
+        if (rSize < (files.maxBytes() * DISCARD_UNSEEN_FILES_RATIO).toLong) {

Review Comment:
   To be clear, If `rSize` is a value larger than `Lonx.MaxValue`, once you did 
`rSize.toLong`, it may possibly cast to a long value truncated to 1, for 
example. So the condition `rSize.toLong < (files.maxBytes() * 
DISCARD_UNSEEN_FILES_RATIO).toLong` will wrongly evaluate to `true`, although 
`rSize` is actually larger than `files.maxBytes() * 
DISCARD_UNSEEN_FILES_RATIO).toLong`.
   
   To compare two values in different ranges, it seems more reasonable to 
compare them in wider range, instead of narrow one (as you will truncate the 
value from wider range).
   
   



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