Copilot commented on code in PR #918:
URL: https://github.com/apache/arrow-go/pull/918#discussion_r3554587387
##########
arrow/array/record_test.go:
##########
@@ -527,9 +538,27 @@ func TestRecordBuilder(t *testing.T) {
if got, want := rec.ColumnName(0), schema.Field(0).Name; got != want {
t.Fatalf("invalid column name: got=%q, want=%q", got, want)
}
- if got, want := rec.Column(2).String(), `[{["0" "2" "3"] ["a" "b" "c"]}
{[] []} {[] []} {["3" "2" "3"] ["a" "b" "c"]} {[] []}]`; got != want {
- t.Fatalf("invalid column name: got=%q, want=%q", got, want)
+
+ if got, want := rec.Column(0).String(), `[(null) 2 3 4 5 6 (null)]`;
got != want {
+ t.Fatalf("invalid column values: got=%q, want=%q", got, want)
+ }
+ if got, want := rec.Column(1).String(), `[1.1 2.2 3.3 4.4 5.5 6.6 0]`;
got != want {
+ t.Fatalf("invalid column values: got=%q, want=%q", got, want)
}
+ if got, want := rec.Column(2).String(), `[{["0" "2" "3"] ["a" "b" "c"]}
{[] []} {[] []} {["3" "2" "3"] ["a" "b" "c"]} {[] []} {["4"] ["d"]} (null)]`;
got != want {
+ t.Fatalf("invalid column values: got=%q, want=%q", got, want)
+ }
+
+ // roundtripping from JSON with array.FromJSON should work
+ arr := array.RecordToStructArray(rec)
+ defer arr.Release()
+ jsonStr, err := json.Marshal(arr)
+ assert.NoError(t, err)
+
+ roundtripped, _, err := array.FromJSON(mem, arr.DataType(),
bytes.NewReader(jsonStr))
+ defer roundtripped.Release()
+ assert.NoError(t, err)
+ assert.Truef(t, array.Equal(arr, roundtripped), "JSON round trip
returns different array: got=%q, want=%d", arr, roundtripped)
Review Comment:
`roundtripped.Release()` is deferred before checking `err`, which can panic
if `FromJSON` returns an error (and a nil array). The failure message also uses
`%d` for a non-integer value.
--
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]