MaxGekk commented on a change in pull request #33258:
URL: https://github.com/apache/spark/pull/33258#discussion_r667378378
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
##########
@@ -968,6 +968,11 @@ object DateTimeUtils {
*/
def currentTimestamp(): Long = instantToMicros(Instant.now())
+ /**
+ * Obtains the current local date-time as microseconds since the epoch in
the default time-zone.
+ */
+ def currentTimestampNTZ(): Long = localDateTimeToMicros(LocalDateTime.now())
Review comment:
hmm, do you propose to return local date-time at JVM time zone?
```java
/**
* Obtains the current date-time from the system clock in the default
time-zone.
* <p>
* This will query the {@link Clock#systemDefaultZone() system clock} in
the default
* time-zone to obtain the current date-time.
* <p>
* Using this method will prevent the ability to use an alternate clock
for testing
* because the clock is hard-coded.
*
* @return the current date-time using the system clock and default
time-zone, not null
*/
public static LocalDateTime now() {
return now(Clock.systemDefaultZone());
}
```
I would expect to get local date-time at the session time zone.
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala
##########
@@ -200,6 +200,30 @@ 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 timestamp without time zone at the start of
query evaluation.
Review comment:
current timestamp at which time zone?
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/UnsupportedOperationChecker.scala
##########
@@ -417,7 +417,7 @@ object UnsupportedOperationChecker extends Logging {
subPlan.expressions.foreach { e =>
if (e.collectLeaves().exists {
- case (_: CurrentTimestamp | _: Now | _: CurrentDate) => true
+ case (_: CurrentTimestamp | _: Now | _: CurrentDate | _:
LocalTimestamp) => true
Review comment:
Let's just check `CurrentTimestampLike` instead of `CurrentTimestamp`,
`Now` and `LocalTimestamp `
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala
##########
@@ -95,6 +95,12 @@ class DateExpressionsSuite extends SparkFunSuite with
ExpressionEvalHelper {
assert(math.abs(t1 - ct.getTime) < 5000)
}
+ test("datetime function localtimestamp") {
+ val ct = LocalTimestamp().eval(EmptyRow).asInstanceOf[Long]
+ val t1 = DateTimeUtils.localDateTimeToMicros(LocalDateTime.now())
+ assert(math.abs(t1 - ct) < 5000)
+ }
Review comment:
Could you check different combinations of the session time zone (the SQL
config `(SQLConf.SESSION_LOCAL_TIMEZONE`) and the default (JVM) time zone
(`DateTimeTestUtils.withDefaultTimeZone`). The list to check
`DateTimeTestUtils.outstandingTimezonesIds` should be enough.
--
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]