diff options
author | Josh Rosen <joshrosen@databricks.com> | 2016-09-27 14:14:27 -0700 |
---|---|---|
committer | Josh Rosen <joshrosen@databricks.com> | 2016-09-27 14:14:27 -0700 |
commit | 2f84a686604b298537bfd4d087b41594d2aa7ec6 (patch) | |
tree | 9c926ad42a9ddc14d81282555871b4b9a0482adc /sql | |
parent | 67c73052b877a8709ae6fa22b844a45f114b1f7e (diff) | |
download | spark-2f84a686604b298537bfd4d087b41594d2aa7ec6.tar.gz spark-2f84a686604b298537bfd4d087b41594d2aa7ec6.tar.bz2 spark-2f84a686604b298537bfd4d087b41594d2aa7ec6.zip |
[SPARK-17618] Guard against invalid comparisons between UnsafeRow and other formats
This patch ports changes from #15185 to Spark 2.x. In that patch, a correctness bug in Spark 1.6.x which was caused by an invalid `equals()` comparison between an `UnsafeRow` and another row of a different format. Spark 2.x is not affected by that specific correctness bug but it can still reap the error-prevention benefits of that patch's changes, which modify ``UnsafeRow.equals()` to throw an IllegalArgumentException if it is called with an object that is not an `UnsafeRow`.
Author: Josh Rosen <joshrosen@databricks.com>
Closes #15265 from JoshRosen/SPARK-17618-master.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeRow.java | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeRow.java b/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeRow.java index dd2f39eb81..9027652d57 100644 --- a/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeRow.java +++ b/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeRow.java @@ -31,6 +31,7 @@ import com.esotericsoftware.kryo.KryoSerializable; import com.esotericsoftware.kryo.io.Input; import com.esotericsoftware.kryo.io.Output; +import org.apache.spark.sql.catalyst.InternalRow; import org.apache.spark.sql.types.*; import org.apache.spark.unsafe.Platform; import org.apache.spark.unsafe.array.ByteArrayMethods; @@ -577,8 +578,12 @@ public final class UnsafeRow extends MutableRow implements Externalizable, KryoS return (sizeInBytes == o.sizeInBytes) && ByteArrayMethods.arrayEquals(baseObject, baseOffset, o.baseObject, o.baseOffset, sizeInBytes); + } else if (!(other instanceof InternalRow)) { + return false; + } else { + throw new IllegalArgumentException( + "Cannot compare UnsafeRow to " + other.getClass().getName()); } - return false; } /** |