Skip to content

Commit e495e4e

Browse files
committed
More comments.
1 parent 42d47a3 commit e495e4e

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

sql/core/src/main/scala/org/apache/spark/sql/package.scala

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,52 @@ package object sql {
5151
* Row(value1, value2, value3, ...)
5252
* }}}
5353
*
54+
* A value of a row can be accessed through both generic access by ordinal,
55+
* which will incur boxing overhead for primitives, as well as native primitive access.
56+
* An example of generic access by ordinal:
57+
* {{{
58+
* import org.apache.spark.sql._
59+
*
60+
* val row = Row(1, true, "a string", null)
61+
* // row: Row = [1,true,a string,null]
62+
* val firstValue = row(0)
63+
* // firstValue: Any = 1
64+
* val fourthValue = row(3)
65+
* // fourthValue: Any = null
66+
* }}}
67+
*
68+
* For native primitive access, it is invalid to use the native primitive interface to retrieve
69+
* a value that is null, instead a user must check `isNullAt` before attempting to retrieve a value
70+
* that might be null.
71+
* An example of native primitive access:
72+
* {{{
73+
* // using the row from the previous example.
74+
* val firstValue = row.getInt(0)
75+
* // firstValue: Int = 1
76+
* val isNull = row.isNullAt(3)
77+
* // isNull: Boolean = true
78+
* }}}
79+
*
80+
* Interfaces related to native primitive access are:
81+
*
82+
* `isNullAt(i: Int): Boolean`
83+
*
84+
* `getInt(i: Int): Int`
85+
*
86+
* `getLong(i: Int): Long`
87+
*
88+
* `getDouble(i: Int): Double`
89+
*
90+
* `getFloat(i: Int): Float`
91+
*
92+
* `getBoolean(i: Int): Boolean`
93+
*
94+
* `getShort(i: Int): Short`
95+
*
96+
* `getByte(i: Int): Byte`
97+
*
98+
* `getString(i: Int): String`
99+
*
54100
* Fields in a [[Row]] object can be extracted in a pattern match. Example:
55101
* {{{
56102
* import org.apache.spark.sql._
@@ -60,6 +106,7 @@ package object sql {
60106
* key -> value
61107
* }
62108
* }}}
109+
*
63110
* @group row
64111
*/
65112
@DeveloperApi

0 commit comments

Comments
 (0)