zeroshade commented on code in PR #1047:
URL: https://github.com/apache/arrow-go/pull/1047#discussion_r3722058653
##########
arrow/ipc/writer.go:
##########
@@ -148,24 +165,38 @@ func (w *Writer) Close() error {
}
err := w.pw.Close()
+ w.pw = nil
+ w.releaseDictionaries()
if err != nil {
- return fmt.Errorf("arrow/ipc: could not close payload writer:
%w", err)
+ return w.fail(fmt.Errorf("arrow/ipc: could not close payload
writer: %w", err))
}
- w.pw = nil
+ return nil
+}
+
+func (w *Writer) releaseDictionaries() {
for _, d := range w.lastWrittenDicts {
d.Release()
}
+ w.lastWrittenDicts = nil
+}
- return nil
+func (w *Writer) fail(err error) error {
+ if w.err == nil {
+ w.err = err
+ }
+ return w.err
Review Comment:
```suggestion
w.err = errors.Join(w.err, err)
return w.err
```
otherwise we can lose the error if we end up with multiple errors
##########
arrow/ipc/writer.go:
##########
@@ -291,10 +330,11 @@ func (w *Writer) start() error {
for _, data := range ps {
err := w.pw.WritePayload(data)
if err != nil {
- return err
+ return w.fail(err)
}
}
+ w.started = true
Review Comment:
we should probably move `w.started = true` above the for loop here since if
even one succeeds writing then we technically started. The way this is
currently written, if we succeed on one payload, but then fail on a subsequent
payload `w.started` will remain `false`.
##########
arrow/ipc/writer.go:
##########
@@ -59,6 +59,17 @@ func (w *streamWriter) WritePayload(p Payload) error {
func (w *streamWriter) Write(p []byte) (int, error) {
n, err := w.w.Write(p)
w.pos += int64(n)
+ if err == nil && n != len(p) {
+ err = io.ErrShortWrite
+ }
+ return n, err
+}
+
+func writeFull(w io.Writer, p []byte) (int, error) {
+ n, err := w.Write(p)
+ if err == nil && n != len(p) {
+ err = io.ErrShortWrite
+ }
return n, err
}
Review Comment:
we ignore the n on every call to `writeFull`, should we bother even
returning n here?
--
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]