Github user squito commented on a diff in the pull request:
https://github.com/apache/spark/pull/5400#discussion_r31563959
--- Diff:
core/src/main/scala/org/apache/spark/util/io/ByteArrayChunkOutputStream.scala
---
@@ -91,4 +95,45 @@ class ByteArrayChunkOutputStream(chunkSize: Int) extends
OutputStream {
ret
}
}
+
+ /**
+ * Get a copy of the data between the two endpoints, start <= idx <
until. Always returns
+ * an array of size (until - start). Throws an IllegalArgumentException
if
+ * 0 <= start <= until <= size
+ */
+ def slice(start: Long, until: Long): Array[Byte] = {
+ require((until - start) < Integer.MAX_VALUE, "max slice length =
Integer.MAX_VALUE")
+ require(start >= 0 && start <= until, s"start ($start) must be >= 0
and <= until ($until)")
+ require(until >= start && until <= size,
+ s"until ($until) must be >= start ($start) and <= size ($size)")
+ var chunkStart = 0L
+ var chunkIdx = 0
+ val length = (until - start).toInt
+ var foundStart = false
+ val result = new Array[Byte](length)
+ while (!foundStart) {
+ val nextSize = chunkStart + chunks(chunkIdx).size
--- End diff --
I think its correct as is, the problem is that `nextSize` is actually a
very misleading name, it should be `nextChunkStart` (it puzzled me too when I
looked at it again). I think the
[tests](https://github.com/squito/spark/blob/6c2a115b970d31400cd77dc8f0236555e382a1af/core/src/test/scala/org/apache/spark/util/io/ByteArrayChunkOutputStreamSuite.scala#L111)
already cover this case. I will fix the variable name and the test to use
chunk size of 5 bytes, so we get more coverage of slicing across several chunks.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]