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

Add CAST (double as decimal) #8500

Closed
wants to merge 2 commits into from
Closed

Conversation

rui-mo
Copy link
Collaborator

@rui-mo rui-mo commented Jan 24, 2024

A replacement for #5767 from @wuxueyang96.
#8412

Copy link

netlify bot commented Jan 24, 2024

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit 82fa77c
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/65b26def6d1dfe00085706a8

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 24, 2024
@rui-mo rui-mo changed the title Add CAST (from double to decimal) Add CAST (double as decimal) Jan 24, 2024
@rui-mo rui-mo force-pushed the wip_double branch 3 times, most recently from 50f3119 to 5394aa0 Compare January 25, 2024 05:33
Copy link
Collaborator Author

@rui-mo rui-mo left a comment

Choose a reason for hiding this comment

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

@mbasmanova Could you help review this PR? Some unmerged changes from #8478 are added in this PR if still needed. Thanks.

@@ -54,6 +54,13 @@
VELOX_ASSERT_THROW_IMPL( \
facebook::velox::VeloxRuntimeError, _expression, _errorMessage)

#define VELOX_ASSERT_ERROR_STATUS(_expression, _statusCode, _errorMessage) \
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Add VELOX_ASSERT_ERROR_STATUS if it is needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

CC: @pedroerp

testComplexCast(
"c0",
makeConstant<double>(std::numeric_limits<double>::min(), 1),
makeConstant<int128_t>(0, 1, DECIMAL(38, 2)));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tests for both lowest and min are added.

Copy link
Contributor

@mbasmanova mbasmanova left a comment

Choose a reason for hiding this comment

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

@rui-mo Looks great % some nits.

@@ -54,6 +54,13 @@
VELOX_ASSERT_THROW_IMPL( \
facebook::velox::VeloxRuntimeError, _expression, _errorMessage)

#define VELOX_ASSERT_ERROR_STATUS(_expression, _statusCode, _errorMessage) \
const auto status = (_expression); \
ASSERT_TRUE(status.code() == _statusCode); \
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to include mismatches codes in the error message? What does the failure look like now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added code in the error message. Now the message looks like below.
Code mismatch:

Expected error code to be 'Type error', but received 'User error'.

Message mismatch:

Value of: status.message().find(expectedErrorMessage) != std::string::npos
  Actual: false
Expected: true
Expected error message to contain 'Unknown error.', but received 'Result overflows.'.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice. Thank you.

velox/expression/CastExpr-inl.h Outdated Show resolved Hide resolved
const auto toPrecisionScale = getDecimalPrecisionScale(*toType);

applyToSelectedNoThrowLocal(context, rows, result, [&](vector_size_t row) {
if (sourceVector->isNullAt(row)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this ever be the case? Are we not handling nulls elsewhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I checked and found this branch would not be entered. Removed this branch and I will open a PR to remove similar checks of other cast kernels.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect. Thanks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Opened #8557 for this minor fix. Thanks.

DECIMAL(10, 4)));

// Double to long decimal.
testComplexCast(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remind me what does 'complex' mean here? This is not about complex types, is it?

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 is similar with testCast with some tiny differences. This is one PR #8254 to combine them inspired by #7377 (comment). cc @kagamiori

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. Thank you for clarifying. Let's review and land that other PR to reduce confusion.

@facebook-github-bot
Copy link
Contributor

@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mbasmanova merged this pull request in 3596a72.

Copy link

Conbench analyzed the 1 benchmark run on commit 3596a725.

There weren't enough matching historic benchmark results to make a call on whether there were regressions.

The full Conbench report has more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants