Skip to content

Commit 20edec8

Browse files
[MINOR][SQL][DOCS] Improve unix_timestamp's scaladoc (and typo hunting)
1 parent b90bf52 commit 20edec8

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ case class DateFormatClass(left: Expression, right: Expression, timeZoneId: Opti
488488
* Deterministic version of [[UnixTimestamp]], must have at least one parameter.
489489
*/
490490
@ExpressionDescription(
491-
usage = "_FUNC_(expr[, pattern]) - Returns the UNIX timestamp of the give time.",
491+
usage = "_FUNC_(expr[, pattern]) - Returns the UNIX timestamp of the given time.",
492492
extended = """
493493
Examples:
494494
> SELECT _FUNC_('2016-04-08', 'yyyy-MM-dd');
@@ -1225,8 +1225,8 @@ case class ParseToTimestamp(left: Expression, format: Expression, child: Express
12251225
extends RuntimeReplaceable {
12261226

12271227
def this(left: Expression, format: Expression) = {
1228-
this(left, format, Cast(UnixTimestamp(left, format), TimestampType))
1229-
}
1228+
this(left, format, Cast(UnixTimestamp(left, format), TimestampType))
1229+
}
12301230

12311231
override def flatArguments: Iterator[Any] = Iterator(left, format)
12321232
override def sql: String = s"$prettyName(${left.sql}, ${format.sql})"

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ object DateTimeUtils {
423423
}
424424

425425
/**
426-
* Parses a given UTF8 date string to the corresponding a corresponding [[Int]] value.
426+
* Parses a given UTF8 date string to a corresponding [[Int]] value.
427427
* The return type is [[Option]] in order to distinguish between 0 and null. The following
428428
* formats are allowed:
429429
*

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,19 +2487,21 @@ object functions {
24872487
*/
24882488
def current_timestamp(): Column = withExpr { CurrentTimestamp() }
24892489

2490+
// scalastyle:off line.size.limit
24902491
/**
24912492
* Converts a date/timestamp/string to a value of string in the format specified by the date
24922493
* format given by the second argument.
24932494
*
24942495
* A pattern could be for instance `dd.MM.yyyy` and could return a string like '18.03.1993'. All
2495-
* pattern letters of `java.text.SimpleDateFormat` can be used.
2496+
* pattern letters of [[https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html java.text.SimpleDateFormat]] can be used.
24962497
*
24972498
* @note Use when ever possible specialized functions like [[year]]. These benefit from a
24982499
* specialized implementation.
24992500
*
25002501
* @group datetime_funcs
25012502
* @since 1.5.0
25022503
*/
2504+
// scalastyle:on line.size.limit
25032505
def date_format(dateExpr: Column, format: String): Column = withExpr {
25042506
DateFormatClass(dateExpr.expr, Literal(format))
25052507
}
@@ -2647,7 +2649,11 @@ object functions {
26472649
}
26482650

26492651
/**
2650-
* Gets current Unix timestamp in seconds.
2652+
* Returns the current Unix timestamp (in seconds).
2653+
*
2654+
* NOTE: All calls of `unix_timestamp` within the same query return the same value
2655+
* (i.e. the current timestamp is calculated at the start of query evaluation).
2656+
*
26512657
* @group datetime_funcs
26522658
* @since 1.5.0
26532659
*/
@@ -2657,22 +2663,27 @@ object functions {
26572663

26582664
/**
26592665
* Converts time string in format yyyy-MM-dd HH:mm:ss to Unix timestamp (in seconds),
2660-
* using the default timezone and the default locale, return null if fail.
2666+
* using the default timezone and the default locale.
2667+
* Returns `null` if fails.
2668+
*
26612669
* @group datetime_funcs
26622670
* @since 1.5.0
26632671
*/
26642672
def unix_timestamp(s: Column): Column = withExpr {
26652673
UnixTimestamp(s.expr, Literal("yyyy-MM-dd HH:mm:ss"))
26662674
}
26672675

2676+
// scalastyle:off line.size.limit
26682677
/**
2669-
* Convert time string with given pattern
2670-
* (see [http://docs.oracle.com/javase/tutorial/i18n/format/simpleDateFormat.html])
2671-
* to Unix time stamp (in seconds), return null if fail.
2678+
* Converts time string with given pattern to Unix timestamp (in seconds).
2679+
* Returns `null` if fails.
2680+
*
2681+
* @see [[http://docs.oracle.com/javase/tutorial/i18n/format/simpleDateFormat.html Customizing Formats]]
26722682
* @group datetime_funcs
26732683
* @since 1.5.0
26742684
*/
2675-
def unix_timestamp(s: Column, p: String): Column = withExpr {UnixTimestamp(s.expr, Literal(p)) }
2685+
// scalastyle:on
2686+
def unix_timestamp(s: Column, p: String): Column = withExpr { UnixTimestamp(s.expr, Literal(p)) }
26762687

26772688
/**
26782689
* Convert time string to a Unix timestamp (in seconds).

0 commit comments

Comments
 (0)