zeroshade commented on code in PR #1267:
URL: https://github.com/apache/arrow-adbc/pull/1267#discussion_r1384824383
##########
go/adbc/driver/snowflake/record_reader.go:
##########
@@ -266,6 +282,24 @@ func getTransformer(sc *arrow.Schema, ld
gosnowflake.ArrowStreamLoader, useHighP
return out, getRecTransformer(out, transformers)
}
+func integerToDecimal128(ctx context.Context, a arrow.Array, dt
*arrow.Decimal128Type) (arrow.Array, error) {
+ // We can't do a cast directly into the destination type because the
numbers we get from Snowflake
+ // are scaled integers. So not only would the cast produce the wrong
value, it also risks producing
+ // an error of precisions which e.g. can't hold every int64. To work
around these problems, we instead
+ // cast into a decimal type of a precision and scale which we know will
hold all values and won't
+ // require scaling, We then substitute the type on this array with the
actual return type.
+
+ dt0 := &arrow.Decimal128Type{
+ Precision: int32(20),
+ Scale: int32(0),
+ }
+ result, err := compute.CastArray(ctx, a, compute.SafeCastOptions(dt0))
+ if err == nil {
+ result.Data().Reset(dt, result.Data().Len(),
result.Data().Buffers(), result.Data().Children(), result.Data().NullN(),
result.Data().Offset())
+ }
+ return result, err
Review Comment:
I think we should instead do the following:
```go
result, err := comptue.CastArray(ctx, a, compute.SafeCastOptions(dt0))
if err != nil {
return nil, err
}
data := result.Data()
result.Data().Reset(dt, data.Len(), data.Buffers(), data.Children(),
data.NullN(), data.Offset())
return result, nil
```
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]