@@ -286,6 +286,28 @@ setMethod("ceil",
286286 column(jc )
287287 })
288288
289+ # ' Returns the first column that is not NA
290+ # '
291+ # ' Returns the first column that is not NA, or NA if all inputs are.
292+ # '
293+ # ' @rdname coalesce
294+ # ' @name coalesce
295+ # ' @family normal_funcs
296+ # ' @export
297+ # ' @aliases coalesce,Column-method
298+ # ' @examples \dontrun{coalesce(df$c, df$d, df$e)}
299+ # ' @note coalesce(Column) since 2.1.1
300+ setMethod ("coalesce ",
301+ signature(x = " Column" ),
302+ function (x , ... ) {
303+ jcols <- lapply(list (x , ... ), function (x ) {
304+ stopifnot(class(x ) == " Column" )
305+ x @ jc
306+ })
307+ jc <- callJStatic(" org.apache.spark.sql.functions" , " coalesce" , jcols )
308+ column(jc )
309+ })
310+
289311# ' Though scala functions has "col" function, we don't expose it in SparkR
290312# ' because we don't want to conflict with the "col" function in the R base
291313# ' package and we also have "column" function exported which is an alias of "col".
@@ -297,15 +319,15 @@ col <- function(x) {
297319# ' Returns a Column based on the given column name
298320# '
299321# ' Returns a Column based on the given column name.
300- #
322+ # '
301323# ' @param x Character column name.
302324# '
303325# ' @rdname column
304326# ' @name column
305327# ' @family normal_funcs
306328# ' @export
307329# ' @aliases column,character-method
308- # ' @examples \dontrun{column(df )}
330+ # ' @examples \dontrun{column("name" )}
309331# ' @note column since 1.6.0
310332setMethod ("column ",
311333 signature(x = " character" ),
@@ -1730,24 +1752,90 @@ setMethod("toRadians",
17301752
17311753# ' to_date
17321754# '
1733- # ' Converts the column into DateType.
1755+ # ' Converts the column into a DateType. You may optionally specify a format
1756+ # ' according to the rules in:
1757+ # ' \url{http://docs.oracle.com/javase/tutorial/i18n/format/simpleDateFormat.html}.
1758+ # ' If the string cannot be parsed according to the specified format (or default),
1759+ # ' the value of the column will be null.
1760+ # ' The default format is 'yyyy-MM-dd'.
17341761# '
1735- # ' @param x Column to compute on.
1762+ # ' @param x Column to parse.
1763+ # ' @param format string to use to parse x Column to DateType. (optional)
17361764# '
17371765# ' @rdname to_date
17381766# ' @name to_date
17391767# ' @family datetime_funcs
1740- # ' @aliases to_date,Column-method
1768+ # ' @aliases to_date,Column,missing -method
17411769# ' @export
1742- # ' @examples \dontrun{to_date(df$c)}
1743- # ' @note to_date since 1.5.0
1770+ # ' @examples
1771+ # ' \dontrun{
1772+ # ' to_date(df$c)
1773+ # ' to_date(df$c, 'yyyy-MM-dd')
1774+ # ' }
1775+ # ' @note to_date(Column) since 1.5.0
17441776setMethod ("to_date ",
1745- signature(x = " Column" ),
1746- function (x ) {
1777+ signature(x = " Column" , format = " missing " ),
1778+ function (x , format ) {
17471779 jc <- callJStatic(" org.apache.spark.sql.functions" , " to_date" , x @ jc )
17481780 column(jc )
17491781 })
17501782
1783+ # ' @rdname to_date
1784+ # ' @name to_date
1785+ # ' @family datetime_funcs
1786+ # ' @aliases to_date,Column,character-method
1787+ # ' @export
1788+ # ' @note to_date(Column, character) since 2.2.0
1789+ setMethod ("to_date ",
1790+ signature(x = " Column" , format = " character" ),
1791+ function (x , format ) {
1792+ jc <- callJStatic(" org.apache.spark.sql.functions" , " to_date" , x @ jc , format )
1793+ column(jc )
1794+ })
1795+
1796+ # ' to_timestamp
1797+ # '
1798+ # ' Converts the column into a TimestampType. You may optionally specify a format
1799+ # ' according to the rules in:
1800+ # ' \url{http://docs.oracle.com/javase/tutorial/i18n/format/simpleDateFormat.html}.
1801+ # ' If the string cannot be parsed according to the specified format (or default),
1802+ # ' the value of the column will be null.
1803+ # ' The default format is 'yyyy-MM-dd HH:mm:ss'.
1804+ # '
1805+ # ' @param x Column to parse.
1806+ # ' @param format string to use to parse x Column to DateType. (optional)
1807+ # '
1808+ # ' @rdname to_timestamp
1809+ # ' @name to_timestamp
1810+ # ' @family datetime_funcs
1811+ # ' @aliases to_timestamp,Column,missing-method
1812+ # ' @export
1813+ # ' @examples
1814+ # ' \dontrun{
1815+ # ' to_timestamp(df$c)
1816+ # ' to_timestamp(df$c, 'yyyy-MM-dd')
1817+ # ' }
1818+ # ' @note to_timestamp(Column) since 2.2.0
1819+ setMethod ("to_timestamp ",
1820+ signature(x = " Column" , format = " missing" ),
1821+ function (x , format ) {
1822+ jc <- callJStatic(" org.apache.spark.sql.functions" , " to_timestamp" , x @ jc )
1823+ column(jc )
1824+ })
1825+
1826+ # ' @rdname to_timestamp
1827+ # ' @name to_timestamp
1828+ # ' @family datetime_funcs
1829+ # ' @aliases to_timestamp,Column,character-method
1830+ # ' @export
1831+ # ' @note to_timestamp(Column, character) since 2.2.0
1832+ setMethod ("to_timestamp ",
1833+ signature(x = " Column" , format = " character" ),
1834+ function (x , format ) {
1835+ jc <- callJStatic(" org.apache.spark.sql.functions" , " to_timestamp" , x @ jc , format )
1836+ column(jc )
1837+ })
1838+
17511839# ' trim
17521840# '
17531841# ' Trim the spaces from both ends for the specified string column.
0 commit comments