-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-21344][SQL] BinaryType comparison does signed byte array comparison #18571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
ac86eed
0fea784
bb01063
814d4c4
a84776b
e33ec8e
08776e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,4 +137,26 @@ class OrderingSuite extends SparkFunSuite with ExpressionEvalHelper { | |
| // verify that we can support up to 5000 ordering comparisons, which should be sufficient | ||
| GenerateOrdering.generate(Array.fill(5000)(sortOrder)) | ||
| } | ||
|
|
||
| test("SPARK-21344: BinaryType comparison does signed byte array comparison") { | ||
| val data = Seq( | ||
| (Array[Byte](1), Array[Byte](-1)), | ||
| (Array[Byte](1, 1, 1, 1, 1), Array[Byte](1, 1, 1, 1, -1)), | ||
| (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)) | ||
|
||
| val genOrdering = GenerateOrdering.generate( | ||
| BoundReference(0, BinaryType, nullable = true).asc :: | ||
| BoundReference(1, BinaryType, nullable = true).asc :: Nil) | ||
| val rowType = StructType( | ||
| StructField("b1", BinaryType, nullable = true) :: | ||
| StructField("b2", BinaryType, nullable = true) :: Nil) | ||
|
||
| val toCatalyst = CatalystTypeConverters.createToCatalystConverter(rowType) | ||
| val rowB1 = toCatalyst(Row(b1)).asInstanceOf[InternalRow] | ||
| val rowB2 = toCatalyst(Row(b2)).asInstanceOf[InternalRow] | ||
| assert(rowOrdering.compare(rowB1, rowB2) < 0) | ||
| assert(genOrdering.compare(rowB1, rowB2) < 0) | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| -- binary type | ||
| select x'00' < x'0f'; | ||
| select x'00' < x'ff'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| -- Automatically generated by SQLQueryTestSuite | ||
| -- Number of queries: 2 | ||
|
|
||
|
|
||
| -- !query 0 | ||
| select x'00' < x'0f' | ||
| -- !query 0 schema | ||
| struct<(X'00' < X'0F'):boolean> | ||
| -- !query 0 output | ||
| true | ||
|
|
||
|
|
||
| -- !query 1 | ||
| select x'00' < x'ff' | ||
| -- !query 1 schema | ||
| struct<(X'00' < X'FF'):boolean> | ||
| -- !query 1 output | ||
| true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems we don't have unit test for this. Shall we add a ByteArraySuite?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have the unit test for this. I added some cases.