You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "disq (via GitHub)" <gi...@apache.org> on 2024/03/20 18:32:19 UTC
[PR] GH-40693: [Go] Add tests for Decimal type precision loss on GetOneForMarshal [arrow]
disq opened a new pull request, #40694:
URL: https://github.com/apache/arrow/pull/40694
### Rationale for this change
Loss of precision when using GetOneForMarshal on Decimal128 and Decimal256
### What changes are included in this PR?
For the time being it's just the tests. Seems I haven't managed to fix these yet, pointers appreciated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40693: [Go] Fix Decimal type precision loss on GetOneForMarshal [arrow]
Posted by "disq (via GitHub)" <gi...@apache.org>.
disq commented on PR #40694:
URL: https://github.com/apache/arrow/pull/40694#issuecomment-2012195900
@hermanschaaf Came through and fixed these 🥇
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40693: [Go] Fix Decimal type precision loss on GetOneForMarshal [arrow]
Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #40694:
URL: https://github.com/apache/arrow/pull/40694#issuecomment-2019106996
After merging your PR, Conbench analyzed the 5 benchmarking runs that have been run so far on merge-commit 1781b3248743812f737f32c244434b00e8d18579.
There were no benchmark performance regressions. 🎉
The [full Conbench report](https://github.com/apache/arrow/runs/23080912930) has more details. It also includes information about 2 possible false positives for unstable benchmarks that are known to sometimes produce them.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40693: [Go] Fix Decimal type precision loss on GetOneForMarshal [arrow]
Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade merged PR #40694:
URL: https://github.com/apache/arrow/pull/40694
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40693: [Go] Fix Decimal type precision loss on GetOneForMarshal [arrow]
Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on code in PR #40694:
URL: https://github.com/apache/arrow/pull/40694#discussion_r1537755001
##########
go/arrow/array/decimal128.go:
##########
@@ -86,15 +85,19 @@ func (a *Decimal128) setData(data *Data) {
a.values = a.values[beg:end]
}
}
-
func (a *Decimal128) GetOneForMarshal(i int) interface{} {
if a.IsNull(i) {
return nil
}
-
typ := a.DataType().(*arrow.Decimal128Type)
- f := (&big.Float{}).SetInt(a.Value(i).BigInt())
- f.Quo(f, big.NewFloat(math.Pow10(int(typ.Scale))))
+ n := a.Value(i)
+ scale := typ.Scale
+ f := (&big.Float{}).SetInt(n.BigInt())
+ if scale < 0 {
+ f.SetPrec(128).Mul(f, (&big.Float{}).SetInt(decimal128.GetScaleMultiplier(int(-scale)).BigInt()))
+ } else {
+ f.SetPrec(128).Quo(f, (&big.Float{}).SetInt(decimal128.GetScaleMultiplier(int(scale)).BigInt()))
+ }
Review Comment:
huh, didn't expect the solution to be so "simple". Very nice
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40693: [Go] Add tests for Decimal type precision loss on GetOneForMarshal [arrow]
Posted by "disq (via GitHub)" <gi...@apache.org>.
disq commented on PR #40694:
URL: https://github.com/apache/arrow/pull/40694#issuecomment-2011656709
This seems to work:
```go
typ := a.DataType().(*arrow.Decimal256Type)
f := (&big.Float{}).SetInt(a.Value(i).BigInt())
scale := big.NewInt(10)
scale.Exp(scale, big.NewInt(int64(typ.Scale)), nil)
f.Quo(f, new(big.Float).SetInt(scale))
return f.Text('f', int(typ.Scale))
// return f.Text('g', int(typ.Precision))
```
But the `f` format is not what the tests expect... with `g` it results in further floaty errors, as in `0.99000000000000000000000000827180612553027674871409` or `1234567890.1234567889999999999999999938549877259069`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40693: [Go] Add tests for Decimal type precision loss on GetOneForMarshal [arrow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #40694:
URL: https://github.com/apache/arrow/pull/40694#issuecomment-2010327851
:warning: GitHub issue #40693 **has been automatically assigned in GitHub** to PR creator.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-40693: [Go] Fix Decimal type precision loss on GetOneForMarshal [arrow]
Posted by "disq (via GitHub)" <gi...@apache.org>.
disq commented on PR #40694:
URL: https://github.com/apache/arrow/pull/40694#issuecomment-2012196804
@zeroshade PTAL when you have a chance? Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org