-
Notifications
You must be signed in to change notification settings - Fork 107
Add integration tests for Decimal scanning and fix byte ordering bug #1938
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
base: master
Are you sure you want to change the base?
Conversation
github.com/ydb-platform/ydb-go-sdk/v3/decimalcompatible changespackage added github.com/ydb-platform/ydb-go-sdk/v3/table/typesincompatible changesDecimal: changed from github.com/ydb-platform/ydb-go-sdk/v3/internal/decimal.Decimal to github.com/ydb-platform/ydb-go-sdk/v3/decimal.Decimal summaryInferred base version: v3.121.1 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1938 +/- ##
==========================================
+ Coverage 73.96% 74.15% +0.19%
==========================================
Files 395 395
Lines 34557 34573 +16
==========================================
+ Hits 25560 25638 +78
+ Misses 7875 7812 -63
- Partials 1122 1123 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: asmyasnikov <14202262+asmyasnikov@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds comprehensive integration tests for scanning YDB Decimal values using types.Decimal as the destination type in both query client and database/sql client. The functionality already existed but lacked test coverage.
Key changes:
- Added extensive integration tests in
tests/integration/decimal_test.gocovering query client, database/sql, parameters, NULL handling, and negative values - Refactored
internal/decimalpackage to introduce anInterfacetype and implementsql.Scannerinterface onDecimal - Simplified function signatures by removing redundant
scaleparameter fromBigIntToByte,FromBytes, andFromInt128functions
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/integration/decimal_test.go | New comprehensive integration tests for Decimal scanning in query client, database/sql, and parameter passing |
| tests/integration/unexpected_decimal_parse_test.go | Removed file (test moved and improved in decimal_test.go) |
| tests/integration/query_execute_test.go | Updated BigIntToByte calls to use new 2-parameter signature |
| internal/decimal/type.go | Added Interface type, sql.Scanner implementation, and helper methods (String, Format, BigInt) |
| internal/decimal/decimal.go | Added ParseDecimal function, Decimal.apply method, Format trimTrailingZeros parameter, simplified function signatures |
| internal/decimal/errors.go | Added errOverflow error |
| internal/decimal/decimal_test.go | Updated tests for new function signatures and added ParseDecimal tests |
| internal/value/value.go | Implemented decimal.Interface, updated castTo to use ToDecimal helper, removed scale parameter from function calls |
| internal/value/any.go | Added case for decimalValue to return *decimal.Decimal |
| internal/value/value_test.go | Updated test to use new Decimal() method instead of individual getters |
| internal/query/scanner/struct_test.go | Updated BigIntToByte calls to use new 2-parameter signature |
| table/types/cast.go | Simplified ToDecimal to use decimal.Interface and ToDecimal helper |
| internal/xcontext/context_with_stoppable_timeout_test.go | Reordered imports (minor) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Use BigIntToByte() instead of manual byte copying to ensure proper 128-bit decimal format conversion with correct endianness and sign handling. Addresses code review feedback from copilot-pull-request-reviewer[bot]. Co-authored-by: asmyasnikov <14202262+asmyasnikov@users.noreply.github.com>
🌋 SLO Test ResultsStatus: 🟢 6 workloads tested • All passed
Generated by ydb-slo-action |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 18 out of 21 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (3)
decimal/decimal.go:63
- The apply method is a private helper method that lacks documentation. While private methods don't always need documentation, this method performs complex logic (string parsing, precision calculation, type assertions) that would benefit from a doc comment explaining its purpose, the types it handles, and any assumptions it makes about the input values.
decimal/decimal.go:60 - The ParseDecimal function doesn't validate for edge cases like trailing dots (e.g., "123.") or empty strings. When input is "123.", dotIndex = 3, integerPart = "123", fractionalPart = "", combined = "123", which will parse correctly, but exp will be 0 (length of empty string). While this might work, consider adding explicit handling or validation for such edge cases to make behavior more predictable and add corresponding test cases.
decimal/decimal.go:84 - The precision calculation appears to use a magic number formula (bufferSize - exp - 3) where bufferSize is 40. This results in precision = 37 - exp. For very large fractional parts (high exp values), this could result in negative or very small precision values. Consider adding validation to ensure the calculated precision is within valid YDB Decimal bounds (typically 1-35) and documenting why this specific formula is used.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Pull request type
What is the current behavior?
The SDK already supports scanning YDB Decimal values using
types.Decimalas the destination type in both query client and database/sql, but lacked comprehensive test coverage. Additionally, there was a bug in theDecimal.Scanmethod when handling string values where manual byte copying didn't properly handle the conversion to YDB's 128-bit decimal format.What is the new behavior?
tests/integration/decimal_scan_test.gocovering:row.Scan(&decimal)with various precision/scale combinations, negative values, NULL handlinginternal/decimal/decimal.goby replacing manual byte copying withBigIntToByte()function which properly handles:big.Intto YDB's 128-bit decimal formatUsage Example
Other information
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.