@@ -91,26 +91,6 @@ object Row {
9191 * // isNull: Boolean = true
9292 * }}}
9393 *
94- * Interfaces related to native primitive access are:
95- *
96- * `isNullAt(i: Int): Boolean`
97- *
98- * `getInt(i: Int): Int`
99- *
100- * `getLong(i: Int): Long`
101- *
102- * `getDouble(i: Int): Double`
103- *
104- * `getFloat(i: Int): Float`
105- *
106- * `getBoolean(i: Int): Boolean`
107- *
108- * `getShort(i: Int): Short`
109- *
110- * `getByte(i: Int): Byte`
111- *
112- * `getString(i: Int): String`
113- *
11494 * In Scala, fields in a [[Row ]] object can be extracted in a pattern match. Example:
11595 * {{{
11696 * import org.apache.spark.sql._
@@ -124,99 +104,181 @@ object Row {
124104 * @group row
125105 */
126106trait Row extends Seq [Any ] with Serializable {
107+ /**
108+ * Returns the value at position i. If the value is null, null is returned. The following
109+ * is a mapping between Spark SQL types and return types:
110+ *
111+ * {{{
112+ * BooleanType -> java.lang.Boolean
113+ * ByteType -> java.lang.Byte
114+ * ShortType -> java.lang.Short
115+ * IntegerType -> java.lang.Integer
116+ * FloatType -> java.lang.Float
117+ * DoubleType -> java.lang.Double
118+ * StringType -> String
119+ * DecimalType -> scala.math.BigDecimal
120+ *
121+ * DateType -> java.sql.Date
122+ * TimestampType -> java.sql.Timestamp
123+ *
124+ * BinaryType -> byte array
125+ * ArrayType -> scala.collection.Seq (use getList for java.util.List)
126+ * MapType -> scala.collection.Map (use getJavaMap for java.util.Map)
127+ * StructType -> org.apache.spark.sql.Row
128+ * }}}
129+ */
127130 def apply (i : Int ): Any
128131
129- /** Returns the value at position i. If the value is null, null is returned. */
132+ /**
133+ * Returns the value at position i. If the value is null, null is returned. The following
134+ * is a mapping between Spark SQL types and return types:
135+ *
136+ * {{{
137+ * BooleanType -> java.lang.Boolean
138+ * ByteType -> java.lang.Byte
139+ * ShortType -> java.lang.Short
140+ * IntegerType -> java.lang.Integer
141+ * FloatType -> java.lang.Float
142+ * DoubleType -> java.lang.Double
143+ * StringType -> String
144+ * DecimalType -> scala.math.BigDecimal
145+ *
146+ * DateType -> java.sql.Date
147+ * TimestampType -> java.sql.Timestamp
148+ *
149+ * BinaryType -> byte array
150+ * ArrayType -> scala.collection.Seq (use getList for java.util.List)
151+ * MapType -> scala.collection.Map (use getJavaMap for java.util.Map)
152+ * StructType -> org.apache.spark.sql.Row
153+ * }}}
154+ */
130155 def get (i : Int ): Any = apply(i)
131156
132157 /** Checks whether the value at position i is null. */
133158 def isNullAt (i : Int ): Boolean
134159
160+ /**
161+ * Returns the value at position i as a primitive boolean.
162+ *
163+ * @throws ClassCastException when data type does not match.
164+ * @throws NullPointerException when value is null.
165+ */
166+ def getBoolean (i : Int ): Boolean
167+
168+ /**
169+ * Returns the value at position i as a primitive byte.
170+ *
171+ * @throws ClassCastException when data type does not match.
172+ * @throws NullPointerException when value is null.
173+ */
174+ def getByte (i : Int ): Byte
175+
176+ /**
177+ * Returns the value at position i as a primitive short.
178+ *
179+ * @throws ClassCastException when data type does not match.
180+ * @throws NullPointerException when value is null.
181+ */
182+ def getShort (i : Int ): Short
183+
135184 /**
136185 * Returns the value at position i as a primitive int.
137- * Throws an exception if the type mismatches or if the value is null.
186+ *
187+ * @throws ClassCastException when data type does not match.
188+ * @throws NullPointerException when value is null.
138189 */
139190 def getInt (i : Int ): Int
140191
141192 /**
142193 * Returns the value at position i as a primitive long.
143- * Throws an exception if the type mismatches or if the value is null.
194+ *
195+ * @throws ClassCastException when data type does not match.
196+ * @throws NullPointerException when value is null.
144197 */
145198 def getLong (i : Int ): Long
146199
147- /**
148- * Returns the value at position i as a primitive double.
149- * Throws an exception if the type mismatches or if the value is null.
150- */
151- def getDouble (i : Int ): Double
152-
153200 /**
154201 * Returns the value at position i as a primitive float.
155202 * Throws an exception if the type mismatches or if the value is null.
203+ *
204+ * @throws ClassCastException when data type does not match.
205+ * @throws NullPointerException when value is null.
156206 */
157207 def getFloat (i : Int ): Float
158208
159209 /**
160- * Returns the value at position i as a primitive boolean.
161- * Throws an exception if the type mismatches or if the value is null.
210+ * Returns the value at position i as a primitive double.
211+ *
212+ * @throws ClassCastException when data type does not match.
213+ * @throws NullPointerException when value is null.
162214 */
163- def getBoolean (i : Int ): Boolean
215+ def getDouble (i : Int ): Double
164216
165217 /**
166- * Returns the value at position i as a primitive short.
167- * Throws an exception if the type mismatches or if the value is null.
218+ * Returns the value at position i as a String object.
219+ *
220+ * @throws ClassCastException when data type does not match.
221+ * @throws NullPointerException when value is null.
168222 */
169- def getShort (i : Int ): Short
223+ def getString (i : Int ): String
170224
171225 /**
172- * Returns the value at position i as a primitive byte.
173- * Throws an exception if the type mismatches or if the value is null.
226+ * Returns the value at position i of decimal type as java.math.BigDecimal.
227+ *
228+ * @throws ClassCastException when data type does not match.
174229 */
175- def getByte (i : Int ): Byte
230+ def getDecimal (i : Int ): BigDecimal = apply(i). asInstanceOf [ BigDecimal ]
176231
177232 /**
178- * Returns the value at position i as a String object.
179- * Throws an exception if the type mismatches or if the value is null.
233+ * Returns the value at position i of date type as java.sql.Date.
234+ *
235+ * @throws ClassCastException when data type does not match.
180236 */
181- def getString (i : Int ): String
237+ def getDate (i : Int ): java.sql. Date = apply(i). asInstanceOf [java.sql. Date ]
182238
183239 /**
184- * Return the value at position i of array type as a Scala Seq.
185- * Throws an exception if the type mismatches.
240+ * Returns the value at position i of array type as a Scala Seq.
241+ *
242+ * @throws ClassCastException when data type does not match.
186243 */
187244 def getSeq [T ](i : Int ): Seq [T ] = apply(i).asInstanceOf [Seq [T ]]
188245
189246 /**
190- * Return the value at position i of array type as [[java.util.List ]].
191- * Throws an exception if the type mismatches.
247+ * Returns the value at position i of array type as [[java.util.List ]].
248+ *
249+ * @throws ClassCastException when data type does not match.
192250 */
193251 def getList [T ](i : Int ): java.util.List [T ] = {
194252 scala.collection.JavaConversions .seqAsJavaList(getSeq[T ](i))
195253 }
196254
197255 /**
198- * Return the value at position i of map type as a Scala Map.
199- * Throws an exception if the type mismatches.
256+ * Returns the value at position i of map type as a Scala Map.
257+ *
258+ * @throws ClassCastException when data type does not match.
200259 */
201260 def getMap [K , V ](i : Int ): scala.collection.Map [K , V ] = apply(i).asInstanceOf [Map [K , V ]]
202261
203262 /**
204- * Return the value at position i of array type as a [[java.util.Map ]].
205- * Throws an exception if the type mismatches.
263+ * Returns the value at position i of array type as a [[java.util.Map ]].
264+ *
265+ * @throws ClassCastException when data type does not match.
206266 */
207267 def getJavaMap [K , V ](i : Int ): java.util.Map [K , V ] = {
208268 scala.collection.JavaConversions .mapAsJavaMap(getMap[K , V ](i))
209269 }
210270
211271 /**
212- * Return the value at position i of struct type as an [[Row ]] object.
213- * Throws an exception if the type mismatches.
272+ * Returns the value at position i of struct type as an [[Row ]] object.
273+ *
274+ * @throws ClassCastException when data type does not match.
214275 */
215276 def getStruct (i : Int ): Row = getAs[Row ](i)
216277
217278 /**
218279 * Returns the value at position i.
219- * Throws an exception if the type mismatches.
280+ *
281+ * @throws ClassCastException when data type does not match.
220282 */
221283 def getAs [T ](i : Int ): T = apply(i).asInstanceOf [T ]
222284
0 commit comments