Skip to content

Conversation

@pitrou
Copy link
Member

@pitrou pitrou commented Feb 14, 2019

Also add a debug check on the C++ side.

@pitrou
Copy link
Member Author

pitrou commented Feb 14, 2019

cc @pravindra for the gandiva changes.

Also add a debug check on the C++ side.
@pitrou pitrou force-pushed the ARROW-4563-py-validate-decimal128-inputs branch from 26e2dcc to 5a4cd6a Compare February 14, 2019 16:29
Decimal128Type::Decimal128Type(int32_t precision, int32_t scale)
: DecimalType(16, precision, scale) {
DCHECK_GE(precision, 1);
DCHECK_LE(precision, 38);
Copy link
Contributor

@pravindra pravindra Feb 14, 2019

Choose a reason for hiding this comment

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

also, check for scale >= 0 && scale <= precision ?

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'm not sure. Why can't scale be arbitrary? It's simply an exponent.

Copy link
Contributor

Choose a reason for hiding this comment

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

From this

Precision is the number of digits in a number. Scale is the number of digits to the right of the decimal point in a number. For example, the number 123.45 has a precision of 5 and a scale of 2.

The number of digits after the decimal must be >=0 and must be <= the digits in the number. Am I missing something ?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is Microsoft-specific. There is no a priori reason why scale should be limited. Apparently Oracle allows scales between -128 and 127 (?):
https://docs.oracle.com/cd/A81042_01/DOC/server.816/a76965/c10datyp.htm#743

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@pitrou - thanks, I didn't realize that oracle allows scale to be more than precision, and -ve also. The decimal functions in gandiva don't handle this.

However, I checked the links from @wesm - spark-sql, impala and presto (and of course, sql-server) all require scale to be <= precision.

@pitrou pitrou closed this in b9819e8 Feb 14, 2019
@pitrou pitrou deleted the ARROW-4563-py-validate-decimal128-inputs branch February 14, 2019 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants