Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/6869#discussion_r32717122
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/InternalRow.scala ---
@@ -19,39 +19,193 @@ package org.apache.spark.sql.catalyst
import org.apache.spark.sql.Row
import org.apache.spark.sql.catalyst.expressions.GenericRow
+import org.apache.spark.sql.types.StructType
+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.
+ *
+ * The following is a mapping between Spark SQL types and types of objects
in row:
+ *
+ * BooleanType -> java.lang.Boolean
+ * ByteType -> java.lang.Byte
+ * ShortType -> java.lang.Short
+ * IntegerType -> java.lang.Integer
+ * FloatType -> java.lang.Float
+ * DoubleType -> java.lang.Double
+ * StringType -> UTF8String
+ * DecimalType -> org.apache.spark.sql.types.Decimal
+ *
+ * DateType -> java.lang.Int
+ * TimestampType -> java.lang.Long
+ *
+ * BinaryType -> Array[Byte]
+ * ArrayType -> scala.collection.Seq
+ * MapType -> scala.collection.Map
+ * StructType -> InternalRow
*/
-abstract class InternalRow extends Row {
- // A default implementation to change the return type
- override def copy(): InternalRow = {this}
-}
+abstract class InternalRow extends Serializable {
+ /** Number of elements in the Row. */
+ def size: Int = length
-object InternalRow {
- def unapplySeq(row: InternalRow): Some[Seq[Any]] = Some(row.toSeq)
+ /** Number of elements in the Row. */
+ def length: Int
/**
- * This method can be used to construct a [[Row]] with the given values.
+ * Schema for the row.
*/
- def apply(values: Any*): InternalRow = new GenericRow(values.toArray)
+ def schema: StructType = null
/**
- * This method can be used to construct a [[Row]] from a [[Seq]] of
values.
+ * Returns the value at position i. If the value is null, null is
returned.
*/
- def fromSeq(values: Seq[Any]): InternalRow = new
GenericRow(values.toArray)
+ def apply(i: Int): Any
+
+ /**
+ * Returns the value at position i. If the value is null, null is
returned.
+ */
+ def get(i: Int): Any = apply(i)
+
+ /** Checks whether the value at position i is null. */
+ def isNullAt(i: Int): Boolean
+
+ /**
+ * Returns the value at position i as a primitive boolean.
+ *
+ * @throws ClassCastException when data type does not match.
+ * @throws NullPointerException when value is null.
+ */
+ def getBoolean(i: Int): Boolean
+
+ /**
+ * Returns the value at position i as a primitive byte.
+ *
+ * @throws ClassCastException when data type does not match.
+ * @throws NullPointerException when value is null.
+ */
+ def getByte(i: Int): Byte
+
+ /**
+ * Returns the value at position i as a primitive short.
+ *
+ * @throws ClassCastException when data type does not match.
+ * @throws NullPointerException when value is null.
+ */
+ def getShort(i: Int): Short
+
+ /**
+ * Returns the value at position i as a primitive int.
+ *
+ * @throws ClassCastException when data type does not match.
+ * @throws NullPointerException when value is null.
+ */
+ def getInt(i: Int): Int
+
+ /**
+ * Returns the value at position i as a primitive long.
+ *
+ * @throws ClassCastException when data type does not match.
+ * @throws NullPointerException when value is null.
+ */
+ def getLong(i: Int): Long
- def fromTuple(tuple: Product): InternalRow =
fromSeq(tuple.productIterator.toSeq)
+ /**
+ * Returns the value at position i as a primitive float.
+ * Throws an exception if the type mismatches or if the value is null.
+ *
+ * @throws ClassCastException when data type does not match.
+ * @throws NullPointerException when value is null.
+ */
+ def getFloat(i: Int): Float
/**
- * Merge multiple rows into a single row, one after another.
+ * Returns the value at position i as a primitive double.
+ *
+ * @throws ClassCastException when data type does not match.
+ * @throws NullPointerException when value is null.
*/
- def merge(rows: InternalRow*): InternalRow = {
- // TODO: Improve the performance of this if used in performance
critical part.
- new GenericRow(rows.flatMap(_.toSeq).toArray)
+ def getDouble(i: Int): Double
+
+ /**
+ * Returns the value at position i as a String object.
+ *
+ * @throws ClassCastException when data type does not match.
+ * @throws NullPointerException when value is null.
+ */
+ def getString(i: Int): String = getAs[UTF8String](i).toString
--- End diff --
As it's internal row, should we just return `UTF8String`?
---
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]