Skip to content

Conversation

@MaxGekk
Copy link
Member

@MaxGekk MaxGekk commented Nov 1, 2019

What changes were proposed in this pull request?

In the PR, I propose to extract parsing of the seconds interval units to the private method parseNanos in CalendarInterval and modify the code to correctly parse the fractional part of the seconds unit of intervals in the cases:

  • When the fractional part has less than 9 digits
  • The seconds unit is negative

This is a back port of the commit 3206a99.

Why are the changes needed?

The changes are needed to fix the issues:

spark-sql> select interval 10.123456 seconds;
interval 10 seconds 123 microseconds

The correct result must be interval 10 seconds 123 milliseconds 456 microseconds

spark-sql> select interval -10.123456789 seconds;
interval -9 seconds -876 milliseconds -544 microseconds

but the whole interval should be negated, and the result must be interval -10 seconds -123 milliseconds -456 microseconds, taking into account the truncation to microseconds.

Does this PR introduce any user-facing change?

Yes. After changes:

spark-sql> select interval 10.123456 seconds;
interval 10 seconds 123 milliseconds 456 microseconds
spark-sql> select interval -10.123456789 seconds;
interval -10 seconds -123 milliseconds -456 microseconds

How was this patch tested?

By existing test suite, literals.sql and new tests in ExpressionParserSuite.

@SparkQA
Copy link

SparkQA commented Nov 1, 2019

Test build #113081 has finished for PR 26355 at commit 56faeb0.

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

@SparkQA
Copy link

SparkQA commented Nov 1, 2019

Test build #113083 has finished for PR 26355 at commit f9b063c.

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

@MaxGekk
Copy link
Member Author

MaxGekk commented Nov 1, 2019

ping @cloud-fan

@cloud-fan
Copy link
Contributor

thanks, merging to 2.4!

cloud-fan pushed a commit that referenced this pull request Nov 1, 2019
### What changes were proposed in this pull request?
In the PR, I propose to extract parsing of the seconds interval units to the private method `parseNanos` in `CalendarInterval` and modify the code to correctly parse the fractional part of the seconds unit of intervals in the cases:
- When the fractional part has less than 9 digits
- The seconds unit is negative

This is a back port of the commit 3206a99.

### Why are the changes needed?
The changes are needed to fix the issues:
```sql
spark-sql> select interval 10.123456 seconds;
interval 10 seconds 123 microseconds
```
The correct result must be `interval 10 seconds 123 milliseconds 456 microseconds`
```sql
spark-sql> select interval -10.123456789 seconds;
interval -9 seconds -876 milliseconds -544 microseconds
```
but the whole interval should be negated, and the result must be `interval -10 seconds -123 milliseconds -456 microseconds`, taking into account the truncation to microseconds.

### Does this PR introduce any user-facing change?
Yes. After changes:
```sql
spark-sql> select interval 10.123456 seconds;
interval 10 seconds 123 milliseconds 456 microseconds
spark-sql> select interval -10.123456789 seconds;
interval -10 seconds -123 milliseconds -456 microseconds
```

### How was this patch tested?
By existing test suite, `literals.sql` and new tests in `ExpressionParserSuite`.

Closes #26355 from MaxGekk/fix-interval-nanos-parsing-2.4.

Authored-by: Maxim Gekk <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
@cloud-fan cloud-fan closed this Nov 1, 2019
@dongjoon-hyun
Copy link
Member

Thank you all!

@MaxGekk MaxGekk deleted the fix-interval-nanos-parsing-2.4 branch June 5, 2020 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants