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(query): add with totals case (issue #382) #384

Merged
merged 1 commit into from
Feb 22, 2024
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
2 changes: 1 addition & 1 deletion query.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ func (c *Client) Do(ctx context.Context, q Query) (err error) {
return errors.Wrap(err, "packet")
}
switch code {
case proto.ServerCodeData:
case proto.ServerCodeData, proto.ServerCodeTotals:
if err := c.decodeBlock(ctx, decodeOptions{
Handler: onResult,
Result: q.Result,
Expand Down
31 changes: 31 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,37 @@ func requireEqual[T any](t *testing.T, a, b proto.ColumnOf[T]) {
}
}

func TestWithTotals(t *testing.T) {
t.Parallel()
ctx := context.Background()
conn := Conn(t)
var n proto.ColUInt64
var c proto.ColUInt64

var data []uint64
query := Query{
Body: `
SELECT
number AS n,
COUNT() AS c
FROM (
SELECT number FROM system.numbers LIMIT 100
) GROUP BY n WITH TOTALS
`,
Result: proto.Results{
{Name: "n", Data: &n},
{Name: "c", Data: &c},
},
OnResult: func(ctx context.Context, b proto.Block) error {
data = append(data, c...)
return nil
},
}
require.NoError(t, conn.Do(ctx, query))
require.Equal(t, 101, len(data))
require.Equal(t, uint64(100), data[100])
}

func TestDateTimeOverflow(t *testing.T) {
t.Parallel()
ctx := context.Background()
Expand Down
Loading