Uh oh!
There was an error while loading. Please reload this page.
[SPARK-21344][SQL] BinaryType comparison does signed byte array comparison - #18571
[SPARK-21344][SQL] BinaryType comparison does signed byte array comparison#18571kiszk wants to merge 7 commits into
Conversation
SparkQA
commented
Jul 8, 2017
Test build #79381 has finished for PR 18571 at commit
|
srowen
commented
Jul 8, 2017
Aren't byte comparisons signed though elsewhere? as well as other integer type comparison? this would become inconsistent. Maybe I'm missing the reason this should be different. |
IIUC, What do you think? |
maropu
commented
Jul 9, 2017
I checked other dbms (dbms-like) systems handled binary as unassigned; In some parts of the Spark implementation, they also handle binary as unassigned (https://github.com/apache/spark/blob/master/core/src/main/java/org/apache/spark/util/collection/unsafe/sort/PrefixComparators.java#L36). I feel, based on the principle of least astonishment, we'd be better to handle binary as unassigned in user-facing pieces. |
kiszk
commented
Jul 9, 2017
@maropu, thank you for your comment. |
| test("SPARK-21344: BinaryType comparison does signed byte array comparison") { | ||
| val b1 = Array[Byte](1) // 0x01 | ||
| val b2 = Array[Byte](-1) // 0xff |
There was a problem hiding this comment.
Hi, @kiszk
Can we have another test case with more than one byte for code coverage?
There was a problem hiding this comment.
Thank you for your comment, done.
There was a problem hiding this comment.
Also, it looks better to check the boundary values like -128 and 127.
SparkQA
commented
Jul 9, 2017
Test build #79425 has finished for PR 18571 at commit
|
| long p = 0; | ||
| for (int i = 0; i < minLen; ++i) { | ||
| p |= (128L + Platform.getByte(bytes, Platform.BYTE_ARRAY_OFFSET + i)) | ||
| p |= ((long)Platform.getByte(bytes, Platform.BYTE_ARRAY_OFFSET + i) & 0xff) |
There was a problem hiding this comment.
Nit: maybe we need a single space like ((long) Platform....
SparkQA
commented
Jul 10, 2017
Test build #79436 has finished for PR 18571 at commit
|
SparkQA
commented
Jul 10, 2017
Test build #79439 has finished for PR 18571 at commit
|
maropu
commented
Jul 10, 2017
Jenkins, retest this please. |
SparkQA
commented
Jul 10, 2017
Test build #79450 has finished for PR 18571 at commit
|
kiszk
commented
Jul 10, 2017
@gatorsmile could you please review this? |
gatorsmile
commented
Jul 13, 2017
SELECT x'00'< x'0f'SELECT x'00'< x'ff'Could you add the above queries to a new |
SparkQA
commented
Jul 14, 2017
Test build #79600 has finished for PR 18571 at commit
|
kiszk
commented
Jul 14, 2017
@gatorsmile thank you for your comment, done |
| (Array[Byte](1, 1, 1, 1, 1, 1, 1, 1, 1), Array[Byte](1, 1, 1, 1, 1, 1, 1, 1, -1)) | ||
| ) | ||
| data.foreach { case (b1, b2) => | ||
| val rowOrdering = InterpretedOrdering.forSchema(Seq(BinaryType, BinaryType)) |
There was a problem hiding this comment.
hmmm, don't you just have one binary field for each row? Why you specify two fields to compare?
| BoundReference(1, BinaryType, nullable = true).asc :: Nil) | ||
| val rowType = StructType( | ||
| StructField("b1", BinaryType, nullable = true) :: | ||
| StructField("b2", BinaryType, nullable = true) :: Nil) |
There was a problem hiding this comment.
You specify two binary fields as row schema. But actually your input just has one binary field (i.e., Row(b1)).
| long p = 0; | ||
| for (int i = 0; i < minLen; ++i) { | ||
| p |= (128L + Platform.getByte(bytes, Platform.BYTE_ARRAY_OFFSET + i)) | ||
| p |= ((long) Platform.getByte(bytes, Platform.BYTE_ARRAY_OFFSET + i) & 0xff) |
There was a problem hiding this comment.
Seems we don't have unit test for this. Shall we add a ByteArraySuite?
There was a problem hiding this comment.
We have the unit test for this. I added some cases.
SparkQA
commented
Jul 14, 2017
Test build #79612 has finished for PR 18571 at commit
|
gatorsmile
commented
Jul 14, 2017
It sounds like all the comments from @viirya have been resolved. Will merge it tonight. Thanks! |
viirya
commented
Jul 14, 2017
LGTM |
…rison ## What changes were proposed in this pull request? This PR fixes a wrong comparison for `BinaryType`. This PR enables unsigned comparison and unsigned prefix generation for an array for `BinaryType`. Previous implementations uses signed operations. ## How was this patch tested? Added a test suite in `OrderingSuite`. Author: Kazuaki Ishizaki <ishizaki@jp.ibm.com> Closes#18571 from kiszk/SPARK-21344. (cherry picked from commit ac5d5d7) Signed-off-by: gatorsmile <gatorsmile@gmail.com>
…rison ## What changes were proposed in this pull request? This PR fixes a wrong comparison for `BinaryType`. This PR enables unsigned comparison and unsigned prefix generation for an array for `BinaryType`. Previous implementations uses signed operations. ## How was this patch tested? Added a test suite in `OrderingSuite`. Author: Kazuaki Ishizaki <ishizaki@jp.ibm.com> Closes#18571 from kiszk/SPARK-21344. (cherry picked from commit ac5d5d7) Signed-off-by: gatorsmile <gatorsmile@gmail.com>
…rison ## What changes were proposed in this pull request? This PR fixes a wrong comparison for `BinaryType`. This PR enables unsigned comparison and unsigned prefix generation for an array for `BinaryType`. Previous implementations uses signed operations. ## How was this patch tested? Added a test suite in `OrderingSuite`. Author: Kazuaki Ishizaki <ishizaki@jp.ibm.com> Closes#18571 from kiszk/SPARK-21344. (cherry picked from commit ac5d5d7) Signed-off-by: gatorsmile <gatorsmile@gmail.com>
gatorsmile
commented
Jul 15, 2017
Thanks! Merging to master/2.2/2.1/2.0 |
…rison ## What changes were proposed in this pull request? This PR fixes a wrong comparison for `BinaryType`. This PR enables unsigned comparison and unsigned prefix generation for an array for `BinaryType`. Previous implementations uses signed operations. ## How was this patch tested? Added a test suite in `OrderingSuite`. Author: Kazuaki Ishizaki <ishizaki@jp.ibm.com> Closesapache#18571 from kiszk/SPARK-21344. (cherry picked from commit ac5d5d7) Signed-off-by: gatorsmile <gatorsmile@gmail.com>
…rison This PR fixes a wrong comparison for `BinaryType`. This PR enables unsigned comparison and unsigned prefix generation for an array for `BinaryType`. Previous implementations uses signed operations. Added a test suite in `OrderingSuite`. Author: Kazuaki Ishizaki <ishizaki@jp.ibm.com> Closesapache#18571 from kiszk/SPARK-21344. (cherry picked from commit ac5d5d7) Signed-off-by: gatorsmile <gatorsmile@gmail.com>
What changes were proposed in this pull request?
This PR fixes a wrong comparison for
BinaryType. This PR enables unsigned comparison and unsigned prefix generation for an array forBinaryType. Previous implementations uses signed operations.How was this patch tested?
Added a test suite in
OrderingSuite.