@@ -91,26 +91,6 @@ object Row {
91
91
* // isNull: Boolean = true
92
92
* }}}
93
93
*
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
- *
114
94
* In Scala, fields in a [[Row ]] object can be extracted in a pattern match. Example:
115
95
* {{{
116
96
* import org.apache.spark.sql._
@@ -124,99 +104,181 @@ object Row {
124
104
* @group row
125
105
*/
126
106
trait 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
+ */
127
130
def apply (i : Int ): Any
128
131
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
+ */
130
155
def get (i : Int ): Any = apply(i)
131
156
132
157
/** Checks whether the value at position i is null. */
133
158
def isNullAt (i : Int ): Boolean
134
159
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
+
135
184
/**
136
185
* 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.
138
189
*/
139
190
def getInt (i : Int ): Int
140
191
141
192
/**
142
193
* 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.
144
197
*/
145
198
def getLong (i : Int ): Long
146
199
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
-
153
200
/**
154
201
* Returns the value at position i as a primitive float.
155
202
* 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.
156
206
*/
157
207
def getFloat (i : Int ): Float
158
208
159
209
/**
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.
162
214
*/
163
- def getBoolean (i : Int ): Boolean
215
+ def getDouble (i : Int ): Double
164
216
165
217
/**
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.
168
222
*/
169
- def getShort (i : Int ): Short
223
+ def getString (i : Int ): String
170
224
171
225
/**
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.
174
229
*/
175
- def getByte (i : Int ): Byte
230
+ def getDecimal (i : Int ): BigDecimal = apply(i). asInstanceOf [ BigDecimal ]
176
231
177
232
/**
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.
180
236
*/
181
- def getString (i : Int ): String
237
+ def getDate (i : Int ): java.sql. Date = apply(i). asInstanceOf [java.sql. Date ]
182
238
183
239
/**
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.
186
243
*/
187
244
def getSeq [T ](i : Int ): Seq [T ] = apply(i).asInstanceOf [Seq [T ]]
188
245
189
246
/**
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.
192
250
*/
193
251
def getList [T ](i : Int ): java.util.List [T ] = {
194
252
scala.collection.JavaConversions .seqAsJavaList(getSeq[T ](i))
195
253
}
196
254
197
255
/**
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.
200
259
*/
201
260
def getMap [K , V ](i : Int ): scala.collection.Map [K , V ] = apply(i).asInstanceOf [Map [K , V ]]
202
261
203
262
/**
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.
206
266
*/
207
267
def getJavaMap [K , V ](i : Int ): java.util.Map [K , V ] = {
208
268
scala.collection.JavaConversions .mapAsJavaMap(getMap[K , V ](i))
209
269
}
210
270
211
271
/**
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.
214
275
*/
215
276
def getStruct (i : Int ): Row = getAs[Row ](i)
216
277
217
278
/**
218
279
* Returns the value at position i.
219
- * Throws an exception if the type mismatches.
280
+ *
281
+ * @throws ClassCastException when data type does not match.
220
282
*/
221
283
def getAs [T ](i : Int ): T = apply(i).asInstanceOf [T ]
222
284
0 commit comments