Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: write data tail on io.EOF OnInput #161

Merged
merged 1 commit into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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