first

Gets the first record in the RelationalGroupedDataset.

The first API has several implementations as follows. The exact API used depends on the specific use case:

def first(columnName: String): Column
Aggregate function: returns the first value of a column in a group.
def first(e: Column): Column
Aggregate function: returns the first value in a group.
def first(columnName: String, ignoreNulls: Boolean): Column
Aggregate function: returns the first value of a column in a group.
def first(e: Column, ignoreNulls: Boolean): Column
Aggregate function: returns the first value in a group.

Let's look at example of invoking first on the DataFrame to output the first row:

import org.apache.spark.sql.functions._
scala> statesPopulationDF.select(first("State")).show
+-------------------+
|first(State, false)|
+-------------------+
| Alabama|
+-------------------+
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset