Skip to content

Commit

Permalink
attempting to use runtimereplaceable
Browse files Browse the repository at this point in the history
  • Loading branch information
bllchmbrs committed Dec 6, 2016
1 parent e9c9161 commit 8837bdb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,28 @@ case class ToDate(child: Expression) extends UnaryExpression with ImplicitCastIn
override def prettyName: String = "to_date"
}

/**
* Parses a column with a format to a timestamp.
*/
@ExpressionDescription(
usage = "_FUNC_(timestamp, fmt) - Parses the `timestamp` expression with the `fmt` expression.",
extended = """
Examples:
> SELECT _FUNC_('2016-12-31', 'yyyy-MM-dd');
1483142400
""")
case class ToTimestamp(left: Expression, right: Expression, child: Expression)
extends RuntimeReplaceable {

def this(left: Expression, right: Expression) = {
this(left, right, UnixTimestamp(left, right))
}

override def dataType: DataType = TimestampType
override def flatArguments: Iterator[Any] = Iterator(left, right)
override def sql: String = s"$prettyName(${left.sql}, ${right.sql})"
}

/**
* Returns date truncated to the unit specified by the format.
*/
Expand Down
4 changes: 1 addition & 3 deletions sql/core/src/main/scala/org/apache/spark/sql/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2667,9 +2667,7 @@ object functions {
* @group datetime_funcs
* @since 2.2.0
*/
def to_timestamp(s: Column, p: String): Column = {
withExpr {UnixTimestamp(s.expr, Literal(p)) }.cast("timestamp")
}
def to_timestamp(s: Column, p: String): Column = withExpr {ToTimestamp(s.expr, Literal(p)) }

/**
* Converts the column into DateType.
Expand Down

0 comments on commit 8837bdb

Please sign in to comment.