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

Cast from numeric types to decimal type #1438

Merged
merged 16 commits into from
Jan 12, 2021

Conversation

sperlingxx
Copy link
Collaborator

@sperlingxx sperlingxx commented Dec 31, 2020

This pull request is to support casting from numeric types to decimal type under GPU runtime, which is one of important feature of TPC-DS decimal support plan.

Here are limits of current implementation:

  1. Has restriction on range of Float/Double values, because storage capacity of GPU decimal is restricted by INT64.
  2. There may exists tiny difference between CPU results and GPU results when casting from floats/doubles. In CPU runtime, floats/doubles are firstly converted to strings, then converting to decimals from strings. We can't do the same thing under GPU runtime in current.

@sperlingxx
Copy link
Collaborator Author

build

@sperlingxx
Copy link
Collaborator Author

build

@sperlingxx
Copy link
Collaborator Author

build

@revans2 revans2 changed the title Cast from numeric types to decimal type Ansi Cast from numeric types to decimal type Jan 5, 2021
@@ -372,6 +386,59 @@ case class GpuCast(
case (ShortType | IntegerType | LongType | ByteType | StringType, BinaryType) =>
input.getBase.asByteList(true)

case (IntegerType | LongType, dt: DecimalType) =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about byte and short which are also listed as supported for ANSI cast in the docs?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry this is still missing byte. Is that expected?

docs/compatibility.md Outdated Show resolved Hide resolved
docs/compatibility.md Outdated Show resolved Hide resolved
@sperlingxx
Copy link
Collaborator Author

build

@sperlingxx
Copy link
Collaborator Author

build

@sameerz sameerz linked an issue Jan 7, 2021 that may be closed by this pull request
@sameerz sameerz added the feature request New feature or request label Jan 7, 2021
@sperlingxx sperlingxx changed the title Ansi Cast from numeric types to decimal type Cast from numeric types to decimal type Jan 7, 2021
@sperlingxx
Copy link
Collaborator Author

build

revans2
revans2 previously approved these changes Jan 7, 2021
Copy link
Collaborator

@revans2 revans2 left a comment

Choose a reason for hiding this comment

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

Just a few nits. Overall it looks really good

@sperlingxx
Copy link
Collaborator Author

build

revans2
revans2 previously approved these changes Jan 8, 2021
import TypeSig._
// nullChecks are the same

override val booleanChecks: TypeSig = integral + fp + BOOLEAN + STRING
override val sparkBooleanSig: TypeSig = numeric + BOOLEAN + STRING

override val integralChecks: TypeSig = integral + fp + BOOLEAN + STRING
override val integralChecks: TypeSig = numeric + BOOLEAN + TIMESTAMP + STRING + BINARY
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry this is a really minor nit. Spark does not support TIMESTAMP or BINARY (as you can see on the line below), so us claiming to support it is technically wrong. This should not impact the generated docs or the correctness of the code in any way.

It is also an issue for fpChecks with TIMESTAMP.

The only reason to fix it is to avoid confusion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's been fixed. My bad :)

import TypeSig._
// nullChecks are the same

override val booleanChecks: TypeSig = integral + fp + BOOLEAN + STRING
override val sparkBooleanSig: TypeSig = numeric + BOOLEAN + STRING

override val integralChecks: TypeSig = integral + fp + BOOLEAN + STRING
override val integralChecks: TypeSig = numeric + STRING + STRING
Copy link
Collaborator

Choose a reason for hiding this comment

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

BOOLEAN + STRING not STRING + STRING

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

@sperlingxx
Copy link
Collaborator Author

build

3 similar comments
@sperlingxx
Copy link
Collaborator Author

build

@pxLi
Copy link
Collaborator

pxLi commented Jan 12, 2021

build

@pxLi
Copy link
Collaborator

pxLi commented Jan 12, 2021

build

@revans2 revans2 merged commit 5b29df8 into NVIDIA:branch-0.4 Jan 12, 2021
@sperlingxx sperlingxx deleted the cast_num_to_dec branch January 13, 2021 02:49
nartal1 pushed a commit to nartal1/spark-rapids that referenced this pull request Jun 9, 2021
Signed-off-by: sperlingxx <lovedreamf@gmail.com>
nartal1 pushed a commit to nartal1/spark-rapids that referenced this pull request Jun 9, 2021
Signed-off-by: sperlingxx <lovedreamf@gmail.com>
tgravescs pushed a commit to tgravescs/spark-rapids that referenced this pull request Nov 30, 2023
[auto-merge] bot-auto-merge-branch-23.10 to branch-23.12 [skip ci] [bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEA] Support Decimal Casts
5 participants