MaxGekk commented on a change in pull request #33258:
URL: https://github.com/apache/spark/pull/33258#discussion_r667974590
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala
##########
@@ -236,6 +274,8 @@ case class CurrentBatchTimestamp(
val timestampUs = millisToMicros(timestampMs)
dataType match {
case _: TimestampType => Literal(timestampUs, TimestampType)
+ case _: TimestampNTZType =>
+ Literal(convertTz(timestampUs, ZoneOffset.UTC, zoneId),
TimestampNTZType)
Review comment:
I wonder how it is related to new function? If it is not related, I
would exclude this from the PR, and open new PR with a test.
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala
##########
@@ -200,6 +200,44 @@ case class Now() extends CurrentTimestampLike {
override def prettyName: String = "now"
}
+/**
+ * Returns the current timestamp without time zone at the start of query
evaluation.
+ * There is no code generation since this expression should get constant
folded by the optimizer.
+ */
+// scalastyle:off line.size.limit
+@ExpressionDescription(
+ usage = """
+ _FUNC_() - Returns the current timestamp without time zone at the start of
query evaluation. All calls of localtimestamp within the same query return the
same value.
+
+ _FUNC_ - Returns the current local date-time at the session time zone at
the start of query evaluation.
+ """,
+ examples = """
+ Examples:
+ > SELECT _FUNC_();
+ 2020-04-25 15:49:11.914
+ """,
+ group = "datetime_funcs",
+ since = "3.3.0")
+case class LocalTimestamp(timeZoneId: Option[String] = None) extends
LeafExpression
+ with TimeZoneAwareExpression with CodegenFallback {
+
+ def this() = this(None)
+
+ override def foldable: Boolean = true
+ override def nullable: Boolean = false
+
+ override def dataType: DataType = TimestampNTZType
+
+ final override def nodePatternsInternal(): Seq[TreePattern] =
Seq(CURRENT_LIKE)
+
+ override def withTimeZone(timeZoneId: String): TimeZoneAwareExpression =
+ copy(timeZoneId = Option(timeZoneId))
+
+ override def eval(input: InternalRow): Any =
localDateTimeToMicros(LocalDateTime.now(zoneId))
Review comment:
Yep,I think so.
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala
##########
@@ -200,6 +200,44 @@ case class Now() extends CurrentTimestampLike {
override def prettyName: String = "now"
}
+/**
+ * Returns the current timestamp without time zone at the start of query
evaluation.
+ * There is no code generation since this expression should get constant
folded by the optimizer.
+ */
+// scalastyle:off line.size.limit
+@ExpressionDescription(
+ usage = """
+ _FUNC_() - Returns the current timestamp without time zone at the start of
query evaluation. All calls of localtimestamp within the same query return the
same value.
+
+ _FUNC_ - Returns the current local date-time at the session time zone at
the start of query evaluation.
+ """,
+ examples = """
+ Examples:
+ > SELECT _FUNC_();
+ 2020-04-25 15:49:11.914
+ """,
+ group = "datetime_funcs",
+ since = "3.3.0")
+case class LocalTimestamp(timeZoneId: Option[String] = None) extends
LeafExpression
+ with TimeZoneAwareExpression with CodegenFallback {
+
+ def this() = this(None)
+
+ override def foldable: Boolean = true
+ override def nullable: Boolean = false
+
+ override def dataType: DataType = TimestampNTZType
+
+ final override def nodePatternsInternal(): Seq[TreePattern] =
Seq(CURRENT_LIKE)
+
+ override def withTimeZone(timeZoneId: String): TimeZoneAwareExpression =
+ copy(timeZoneId = Option(timeZoneId))
+
+ override def eval(input: InternalRow): Any =
localDateTimeToMicros(LocalDateTime.now(zoneId))
Review comment:
@cloud-fan Yes,I think so. If you don't specify tz, the
`LocalDateTime.now()` will take the default JVM time zone, see
https://github.com/apache/spark/pull/33258#discussion_r667378378
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]