Conversation
|
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
Reviewer's GuideThis PR refactors the TrinoBigDecimal type to explicitly track and preserve the numeric sign, overhaul the decimal-conversion logic with integrated precision checks, and expose utility getters, while cleaning up legacy conversion code and comments. Class diagram for updated TrinoBigDecimal structureclassDiagram
class TrinoBigDecimal {
- BigInteger integerPart
- BigInteger fractionalPart
- int scale
- int sign
+ TrinoBigDecimal(string value)
+ TrinoBigDecimal(BigInteger integerPart, BigInteger fractionalPart, int scale)
+ decimal ToDecimal()
+ int GetScale()
+ int GetPrecision()
+ int GetSign()
+ BigInteger GetIntegerPart()
+ BigInteger GetFractionalPart()
+ override string ToString()
+ override bool Equals(object obj)
+ override int GetHashCode()
- void Validate()
- static void AlignScales(ref TrinoBigDecimal a, ref TrinoBigDecimal b)
}
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `trino-csharp/Trino.Client/Types/BigDecimal.cs:22` </location>
<code_context>
+ value = value.Trim();
+
+ // Detect sign explicitly
+ sign = value.StartsWith("-", StringComparison.Ordinal) ? -1 : 1;
+ if (value.StartsWith("+") || value.StartsWith("-"))
+ value = value.Substring(1);
</code_context>
<issue_to_address>
**issue (bug_risk):** Sign detection logic may mishandle strings with multiple sign characters.
Please add validation to ensure only one leading sign character is allowed and the remainder of the string is numeric.
</issue_to_address>
### Comment 2
<location> `trino-csharp/Trino.Client/Types/BigDecimal.cs:27` </location>
<code_context>
+ value = value.Substring(1);
+
var parts = value.Split('.');
integerPart = BigInteger.Parse(parts[0]);
fractionalPart = parts.Length > 1 ? BigInteger.Parse(parts[1]) : BigInteger.Zero;
scale = parts.Length > 1 ? parts[1].Length : 0;
</code_context>
<issue_to_address>
**issue:** Parsing may throw if integer part is empty after sign removal.
For inputs like '-.123', parts[0] becomes an empty string, which will cause BigInteger.Parse to fail. Please handle cases where the integer part is missing by defaulting it to zero.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
I have signed the verification and returned back with ok. |
stephen-zhao
left a comment
There was a problem hiding this comment.
fyi, the maintainers haven't been active on this repo..
| public TrinoBigDecimal(BigInteger integerPart, BigInteger fractionalPart, int scale) | ||
| { | ||
| this.integerPart = integerPart; | ||
| sign = integerPart.Sign < 0 ? -1 : 1; |
There was a problem hiding this comment.
| sign = integerPart.Sign < 0 ? -1 : 1; | |
| this.sign = integerPart.Sign < 0 ? -1 : 1; |
for style
|
|
||
| /// <summary> | ||
| /// The scale represents the number of digits to the right of the decimal point. | ||
| /// It is used to determine the precision of the fractional part of the BigDecimal. | ||
| /// </summary> | ||
| /// <example> | ||
| /// For example, if the BigDecimal is "123.00456", the scale is 5 because there are five digits to the right of the decimal point, including the leading zeros. | ||
| /// </example> |
There was a problem hiding this comment.
Can we add back all these comments? why remove them?
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
Summary by Sourcery
Preserve explicit sign in TrinoBigDecimal to correctly handle negative zero and improve decimal parsing, string conversion, equality, hashing, and conversion to decimal.
New Features:
Bug Fixes:
Enhancements: