Github user davies commented on a diff in the pull request:
https://github.com/apache/spark/pull/7626#discussion_r35369960
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/InternalRow.scala ---
@@ -25,48 +25,133 @@ import org.apache.spark.unsafe.types.UTF8String
* An abstract class for row used internal in Spark SQL, which only
contain the columns as
* internal types.
*/
-abstract class InternalRow extends Row {
+abstract class InternalRow {
- def getUTF8String(i: Int): UTF8String = getAs[UTF8String](i)
+ def numFields: Int
- def getBinary(i: Int): Array[Byte] = getAs[Array[Byte]](i)
+ def get(i: Int): Any
- // This is only use for test
- override def getString(i: Int): String = getAs[UTF8String](i).toString
-
- // These expensive API should not be used internally.
- final override def getDecimal(i: Int): java.math.BigDecimal =
- throw new UnsupportedOperationException
- final override def getDate(i: Int): java.sql.Date =
- throw new UnsupportedOperationException
- final override def getTimestamp(i: Int): java.sql.Timestamp =
- throw new UnsupportedOperationException
- final override def getSeq[T](i: Int): Seq[T] = throw new
UnsupportedOperationException
- final override def getList[T](i: Int): java.util.List[T] = throw new
UnsupportedOperationException
- final override def getMap[K, V](i: Int): scala.collection.Map[K, V] =
- throw new UnsupportedOperationException
- final override def getJavaMap[K, V](i: Int): java.util.Map[K, V] =
- throw new UnsupportedOperationException
- final override def getStruct(i: Int): Row = throw new
UnsupportedOperationException
- final override def getAs[T](fieldName: String): T = throw new
UnsupportedOperationException
- final override def getValuesMap[T](fieldNames: Seq[String]): Map[String,
T] =
- throw new UnsupportedOperationException
-
- // A default implementation to change the return type
- override def copy(): InternalRow = this
+ // TODO: Remove this.
+ def apply(i: Int): Any = get(i)
+
+ def getAs[T](i: Int): T = get(i).asInstanceOf[T]
+
+ def isNullAt(i: Int): Boolean = get(i) == null
+
+ def getBoolean(i: Int): Boolean = getAs[Boolean](i)
+
+ def getByte(i: Int): Byte = getAs[Byte](i)
+
+ def getShort(i: Int): Short = getAs[Short](i)
+
+ def getInt(i: Int): Int = getAs[Int](i)
+
+ def getLong(i: Int): Long = getAs[Long](i)
+
+ def getFloat(i: Int): Float = getAs[Float](i)
+
+ def getDouble(i: Int): Double = getAs[Double](i)
+
+ override def toString: String = s"[${this.mkString(",")}]"
/**
- * Returns true if we can check equality for these 2 rows.
- * Equality check between external row and internal row is not allowed.
- * Here we do this check to prevent call `equals` on internal row with
external row.
+ * Make a copy of the current [[Row]] object.
*/
- protected override def canEqual(other: Row) =
other.isInstanceOf[InternalRow]
+ def copy(): InternalRow = this
+
+ /** Returns true if there are any NULL values in this row. */
+ def anyNull: Boolean = {
+ val len = numFields
+ var i = 0
+ while (i < len) {
+ if (isNullAt(i)) { return true }
+ i += 1
+ }
+ false
+ }
+
+ override def equals(o: Any): Boolean = {
+ val other = o.asInstanceOf[InternalRow]
+ if (other eq null) return false
+
+ val len = numFields
+ if (len != other.numFields) {
+ return false
+ }
+
+ var i = 0
+ while (i < len) {
+ if (isNullAt(i) != other.isNullAt(i)) {
+ return false
+ }
+ if (!isNullAt(i)) {
+ val o1 = get(i)
+ val o2 = other.get(i)
+ o1 match {
+ case b1: Array[Byte] =>
+ if (!o2.isInstanceOf[Array[Byte]] ||
+ !java.util.Arrays.equals(b1, o2.asInstanceOf[Array[Byte]])) {
+ return false
+ }
+ case f1: Float if java.lang.Float.isNaN(f1) =>
+ if (!o2.isInstanceOf[Float] || !
java.lang.Float.isNaN(o2.asInstanceOf[Float])) {
+ return false
+ }
+ case d1: Double if java.lang.Double.isNaN(d1) =>
+ if (!o2.isInstanceOf[Double] || !
java.lang.Double.isNaN(o2.asInstanceOf[Double])) {
+ return false
+ }
+ case _ => if (o1 != o2) {
+ return false
+ }
+ }
+ }
+ i += 1
+ }
+ true
+ }
+
+ /* ---------------------- utility methods for Scala
---------------------- */
+
+ /**
+ * Return a Scala Seq representing the row. Elements are placed in the
same order in the Seq.
+ */
+ def toSeq: Seq[Any] = {
+ val n = numFields
+ val values = new Array[Any](n)
+ var i = 0
+ while (i < n) {
+ values.update(i, get(i))
+ i += 1
+ }
+ values.toSeq
+ }
+
+ /** Displays all elements of this sequence in a string (without a
separator). */
+ def mkString: String = toSeq.mkString
+
+ /** Displays all elements of this sequence in a string using a separator
string. */
+ def mkString(sep: String): String = toSeq.mkString(sep)
+
+ /**
+ * Displays all elements of this traversable or iterator in a string
using
+ * start, end, and separator strings.
+ */
+ def mkString(start: String, sep: String, end: String): String =
toSeq.mkString(start, sep, end)
+
+ def getUTF8String(i: Int): UTF8String = getAs[UTF8String](i)
+
+ def getBinary(i: Int): Array[Byte] = getAs[Array[Byte]](i)
+
+ // This is only use for test
+ def getString(i: Int): String = getAs[UTF8String](i).toString
--- End diff --
oh, we already have getUTF8String, that's fine.
---
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]