Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-30793][SQL][2.4] Fix truncations of timestamps before the epoch to minutes and seconds #27611

Closed
wants to merge 2 commits into from

Conversation

MaxGekk
Copy link
Member

@MaxGekk MaxGekk commented Feb 17, 2020

What changes were proposed in this pull request?

In the PR (a backport of #27543), I propose to replace % by Math.floorMod in DateTimeUtils.truncTimestamp for the SECOND and MINUTE levels.

Why are the changes needed?

This fixes the issue of incorrect truncation of timestamps before the epoch 1970-01-01T00:00:00.000000Z to the SECOND and MINUTE levels. For example, timestamps after the epoch are truncated by cutting off the rest part of the timestamp:

spark-sql> select date_trunc('SECOND', '2020-02-11 00:01:02.123');
2020-02-11 00:01:02

but seconds in the truncated timestamp before the epoch are increased by 1:

spark-sql> select date_trunc('SECOND', '1960-02-11 00:01:02.123');
1960-02-11 00:01:03

Does this PR introduce any user-facing change?

Yes. After the changes, the example above outputs correct result:

spark-sql> select date_trunc('SECOND', '1960-02-11 00:01:02.123');
1960-02-11 00:01:02

How was this patch tested?

Added new tests to DateFunctionsSuite.

@SparkQA
Copy link

SparkQA commented Feb 17, 2020

Test build #118593 has finished for PR 27611 at commit 755bce5.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@MaxGekk
Copy link
Member Author

MaxGekk commented Feb 17, 2020

jenkins, retest this, please

@SparkQA
Copy link

SparkQA commented Feb 17, 2020

Test build #118600 has finished for PR 27611 at commit 755bce5.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

cloud-fan pushed a commit that referenced this pull request Feb 18, 2020
…h to minutes and seconds

### What changes were proposed in this pull request?
In the PR (a backport of #27543), I propose to replace `%` by `Math.floorMod` in `DateTimeUtils.truncTimestamp` for the `SECOND` and `MINUTE` levels.

### Why are the changes needed?
This fixes the issue of incorrect truncation of timestamps before the epoch `1970-01-01T00:00:00.000000Z` to the `SECOND` and `MINUTE` levels. For example, timestamps after the epoch are truncated by cutting off the rest part of the timestamp:
```sql
spark-sql> select date_trunc('SECOND', '2020-02-11 00:01:02.123');
2020-02-11 00:01:02
```
but seconds in the truncated timestamp before the epoch are increased by 1:
```sql
spark-sql> select date_trunc('SECOND', '1960-02-11 00:01:02.123');
1960-02-11 00:01:03
```

### Does this PR introduce any user-facing change?
Yes. After the changes, the example above outputs correct result:
```sql
spark-sql> select date_trunc('SECOND', '1960-02-11 00:01:02.123');
1960-02-11 00:01:02
```

### How was this patch tested?
Added new tests to `DateFunctionsSuite`.

Closes #27611 from MaxGekk/fix-second-minute-truc-2.4.

Authored-by: Maxim Gekk <max.gekk@gmail.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
@cloud-fan
Copy link
Contributor

thanks, merging to 2.4!

@cloud-fan cloud-fan closed this Feb 18, 2020
@MaxGekk MaxGekk deleted the fix-second-minute-truc-2.4 branch June 5, 2020 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants