Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/7644#discussion_r35490365
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeFunctions.scala
---
@@ -247,14 +248,112 @@ case class DateFormatClass(left: Expression, right:
Expression) extends BinaryEx
override protected def nullSafeEval(timestamp: Any, format: Any): Any = {
val sdf = new SimpleDateFormat(format.toString)
- UTF8String.fromString(sdf.format(new Date(timestamp.asInstanceOf[Long]
/ 1000)))
+ UTF8String.fromString(sdf.format(new
java.util.Date(timestamp.asInstanceOf[Long] / 1000)))
}
override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode):
String = {
val sdf = classOf[SimpleDateFormat].getName
defineCodeGen(ctx, ev, (timestamp, format) => {
s"""UTF8String.fromString((new $sdf($format.toString()))
- .format(new java.sql.Date($timestamp / 1000)))"""
+ .format(new java.sql.Timestamp($timestamp / 1000)))"""
+ })
+ }
+}
+
+/**
+ * Convert time string with given pattern
+ * (see
[http://docs.oracle.com/javase/tutorial/i18n/format/simpleDateFormat.html])
+ * to Unix time stamp (in seconds), return null if fail.
+ * If the second parameter is missing, use "yyyy-MM-dd HH:mm:ss".
+ * If no parameters provided, the first parameter will be
current_timestamp.
+ * If the first parameter is a Date or Timestamp instead of String, we
will ignore the
+ * second parameter.
+ */
+case class UnixTimestamp(nodes: Seq[Expression])
--- End diff --
This function would be simpler to just put two parameters, and add a ctor
that takes in only one expression, and sets the 2nd parameter to
Literal("yyyy-MM-dd HH:mm:ss").
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]