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

Follow the SQL standard in cast from double or real to varchar #10657

Merged

Conversation

kasiafi
Copy link
Member

@kasiafi kasiafi commented Jan 18, 2022

Related to #552

@kasiafi kasiafi force-pushed the 295CastToVarcharApproxNumericFixFormat branch from 799ef4f to 0572fa4 Compare January 18, 2022 13:42
@cla-bot cla-bot bot added the cla-signed label Jan 18, 2022
@kasiafi kasiafi force-pushed the 295CastToVarcharApproxNumericFixFormat branch 2 times, most recently from 467e3cd to 323ee7c Compare January 19, 2022 10:00
@kasiafi kasiafi requested a review from findepi January 19, 2022 12:32
@kasiafi kasiafi force-pushed the 295CastToVarcharApproxNumericFixFormat branch from 323ee7c to 9359d9c Compare January 20, 2022 10:35
// String is all-ASCII, so String.length() here returns actual code points count
if (stringValue.length() <= x) {
return utf8Slice(stringValue);
}

throw new TrinoException(INVALID_CAST_ARGUMENT, format("Value %s cannot be represented as varchar(%s)", value, x));
throw new TrinoException(INVALID_CAST_ARGUMENT, format("Value %s cannot be represented as varchar(%s)", stringValue, x));
Copy link
Member

Choose a reason for hiding this comment

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

provide original value in the message, just in case we screw something up:

"Value %s (%s) ...", value, stringValue

Copy link
Member Author

Choose a reason for hiding this comment

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

Applied to both double and real.


// handle positive and negative 0
if (value == 0e0) {
if (1e0 / value > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

or, arguably more directly, Double.compare(0.0, value) == 0
the Double.compare sorts negative zero before positive zero

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's clearer the way it is. Double.compare would require a comment.

@kasiafi kasiafi force-pushed the 295CastToVarcharApproxNumericFixFormat branch from 9359d9c to 7bb9d8f Compare January 20, 2022 13:13
@kasiafi kasiafi force-pushed the 295CastToVarcharApproxNumericFixFormat branch from 7bb9d8f to ce125d0 Compare January 20, 2022 20:06
@kasiafi kasiafi merged commit 196072e into trinodb:master Jan 21, 2022
@github-actions github-actions bot added this to the 369 milestone Jan 21, 2022
@kasiafi kasiafi mentioned this pull request Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants