Skip to content

Commit c8e7cd2

Browse files
author
Davies Liu
committed
address comment
1 parent a8618c9 commit c8e7cd2

File tree

5 files changed

+16
-24
lines changed

5 files changed

+16
-24
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/BaseRow.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ public int fieldIndex(String name) {
148148
throw new UnsupportedOperationException();
149149
}
150150

151+
/**
152+
* A generic version of Row.equals(Row), which is used for tests.
153+
*/
151154
@Override
152155
public boolean equals(Object other) {
153156
if (other instanceof Row) {

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateOrdering.scala

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,7 @@ object GenerateOrdering extends CodeGenerator[Seq[SortOrder], Ordering[Row]] wit
6161
{
6262
byte[] x = ${if (asc) evalA.primitive else evalB.primitive};
6363
byte[] y = ${if (!asc) evalB.primitive else evalA.primitive};
64-
int j = 0;
65-
while (j < x.length && j < y.length) {
66-
if (x[j] != y[j]) return x[j] - y[j];
67-
j = j + 1;
68-
}
69-
int d = x.length - y.length;
64+
int d = org.apache.spark.sql.catalyst.util.TypeUtils.compareBinary(x, y);
7065
if (d != 0) {
7166
return d;
7267
}

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -267,19 +267,8 @@ abstract class BinaryComparison extends BinaryExpression with Predicate {
267267
if (!${ev.isNull}) {
268268
${eval2.code}
269269
if (!${eval2.isNull}) {
270-
boolean done = false;
271-
for (int j = 0; j < ${eval1.primitive}.length && j < ${eval2.primitive}.length; j++) {
272-
byte a = ${eval1.primitive}[j];
273-
byte b = ${eval2.primitive}[j];
274-
if (a != b) {
275-
${ev.primitive} = a $symbol b;
276-
done = true;
277-
break;
278-
}
279-
}
280-
if (!done) {
281-
${ev.primitive} = ${eval1.primitive}.length $symbol ${eval2.primitive}.length;
282-
}
270+
${ev.primitive} = org.apache.spark.sql.catalyst.util.TypeUtils.compareBinary(
271+
${eval1.primitive}, ${eval2.primitive}) $symbol 0;
283272
} else {
284273
${ev.isNull} = true;
285274
}

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TypeUtils.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,12 @@ object TypeUtils {
5353

5454
def getOrdering(t: DataType): Ordering[Any] =
5555
t.asInstanceOf[AtomicType].ordering.asInstanceOf[Ordering[Any]]
56+
57+
def compareBinary(x: Array[Byte], y: Array[Byte]): Int = {
58+
for (i <- 0 until x.length; if i < y.length) {
59+
val res = x(i).compareTo(y(i))
60+
if (res != 0) return res
61+
}
62+
x.length - y.length
63+
}
5664
}

sql/catalyst/src/main/scala/org/apache/spark/sql/types/BinaryType.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import scala.reflect.runtime.universe.typeTag
2222

2323
import org.apache.spark.annotation.DeveloperApi
2424
import org.apache.spark.sql.catalyst.ScalaReflectionLock
25+
import org.apache.spark.sql.catalyst.util.TypeUtils
2526

2627

2728
/**
@@ -43,11 +44,7 @@ class BinaryType private() extends AtomicType {
4344

4445
private[sql] val ordering = new Ordering[InternalType] {
4546
def compare(x: Array[Byte], y: Array[Byte]): Int = {
46-
for (i <- 0 until x.length; if i < y.length) {
47-
val res = x(i).compareTo(y(i))
48-
if (res != 0) return res
49-
}
50-
x.length - y.length
47+
TypeUtils.compareBinary(x, y)
5148
}
5249
}
5350

0 commit comments

Comments
 (0)