Skip to content

Commit

Permalink
fix: write data tail on io.EOF OnInput
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Jul 14, 2022
1 parent a1f4bc0 commit ffd6f24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,19 @@ func (c *Client) sendInput(ctx context.Context, info proto.ColInfoInput, q Query
if err := f(ctx); err != nil {
if errors.Is(err, io.EOF) {
// No more data.
if tailRows := q.Input[0].Data.Rows(); tailRows > 0 {
// Write data tail on next tick and break.
//
// This is required to resemble io.Reader behavior.
if ce := c.lg.Check(zap.DebugLevel, "Writing tail of input data (not empty and io.EOF)"); ce != nil {
ce.Write(
zap.Int("rows", tailRows),
)
}
f = nil
continue
}

break
}
// ClickHouse server persists blocks after receive.
Expand Down
2 changes: 1 addition & 1 deletion query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func TestClient_Query(t *testing.T) {
OnInput: func(ctx context.Context) error {
data = append(data[:0], uint8(total), 2, 3, 4)
total++
if total > blocks {
if total >= blocks {
return io.EOF
}
return nil
Expand Down

0 comments on commit ffd6f24

Please sign in to comment.