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-40008][SQL] Support casting of integrals to ANSI intervals #37442

Closed
wants to merge 2 commits into from

Conversation

MaxGekk
Copy link
Member

@MaxGekk MaxGekk commented Aug 8, 2022

What changes were proposed in this pull request?

In the PR, I propose

  1. to support casting of the integral type: TINYINT, SMALLINT, INT, BIGINT to ANSI interval types.
  2. and remove the restriction of casting only single unit intervals.

This PR is complement to #36811.

Why are the changes needed?

To conform the SQL standard which allows such casting:
173228149-17e1fbaa-c095-4eb7-bb3b-81a3f9c91928

Does this PR introduce any user-facing change?

No, it extends existing behavior.

How was this patch tested?

By running new tests:

$ build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z cast.sql"

@github-actions github-actions bot added the SQL label Aug 8, 2022
@MaxGekk MaxGekk changed the title [SPARK-40008][SQL] Support casting integrals to intervals in ANSI mode [SPARK-40008][SQL] Support casting of integrals to ANSI intervals Aug 8, 2022
Copy link
Member

@HyukjinKwon HyukjinKwon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, cc @gengliangwang

@MaxGekk
Copy link
Member Author

MaxGekk commented Aug 9, 2022

Merging to master. Thank you, @HyukjinKwon @cloud-fan for review.

@MaxGekk MaxGekk closed this in 04ea0ac Aug 9, 2022
MaxGekk added a commit that referenced this pull request Aug 10, 2022
… intervals

### What changes were proposed in this pull request?
This is a follow up of #37442 that fixes the codegen of casting integrals to ANSI intervals w/ multi units. The PR removes the assert:
```scala
assert(it.startField == it.endField)
```

### Why are the changes needed?
To make codegen consistent to interpreted code, and fix the assert.

### Does this PR introduce _any_ user-facing change?
Yes.

Before:
```sql
> select cast(dt as interval hour to second) from values(100Y) as t(dt);
java.lang.AssertionError
assertion failed
```

After:
```sql
> select cast(dt as interval hour to second) from values(100Y) as t(dt);
0 00:01:40.000000000
```

### How was this patch tested?
By running new tests:
```
$ build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z cast.sql"
```

Closes #37464 from MaxGekk/cast-integral-to-interval-followup.

Authored-by: Max Gekk <max.gekk@gmail.com>
Signed-off-by: Max Gekk <max.gekk@gmail.com>
MaxGekk added a commit that referenced this pull request Aug 13, 2022
### What changes were proposed in this pull request?
In the PR, I propose to update the doc page https://spark.apache.org/docs/latest/sql-ref-ansi-compliance.html#cast about new behaviour of CAST introduced by the following PRs:
1. [[SPARK-40008][SQL] Support casting of integrals to ANSI intervals](#37442)
2. [[SPARK-39451][SQL] Support casting intervals to integrals in ANSI mode](#36811)
3. [[SPARK-39470][SQL] Support cast of ANSI intervals to decimals](#36857)
4. [[SPARK-40014][SQL] Support cast of decimals to ANSI intervals](#37466)
<img width="1004" alt="Screenshot 2022-08-12 at 15 00 10" src="https://user-images.githubusercontent.com/1580697/184349887-700c64f6-e9c8-40c4-85cc-a77072506cf5.png">

### Why are the changes needed?
To inform Spark SQL about new behaviour of `CAST`.

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
By building Spark SQL docs and check them manually:
```
$ SKIP_SCALADOC=1 SKIP_PYTHONDOC=1 SKIP_RDOC=1 bundle exec jekyll build
```

Closes #37495 from MaxGekk/doc-interval-cast.

Authored-by: Max Gekk <max.gekk@gmail.com>
Signed-off-by: Max Gekk <max.gekk@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants