ClickHouse/ch-go

group by with totals fails with 'handle packet: unexpected packet "Totals"'

Closed this issue · 0 comments

Describe the bug

Any query with GROUP BY WITH TOTALS statement, fails with handle packet: unexpected packet "Totals"

Steps to reproduce

We can take the totals test from clickhouse-go for example

SELECT
	number AS n, COUNT()
FROM (
	SELECT number FROM system.numbers LIMIT 100
) GROUP BY n WITH TOTALS

Expected behaviour

Return The totals row as part of the result.

Code example

package main

import (
	"context"
	"fmt"

	"github.com/ClickHouse/ch-go"
	"github.com/ClickHouse/ch-go/proto"
)

func main() {
	ctx := context.Background()
	client, err := ch.Dial(ctx, ch.Options{Address: "localhost:9000"})
	if err != nil {
		panic(err)
	}
	n := proto.ColUInt64{}
	c := proto.ColUInt64{}
	query := `
		SELECT
			number AS n, COUNT() AS c
		FROM (
			SELECT number FROM system.numbers LIMIT 100
		) GROUP BY n WITH TOTALS
	`
	data := map[string][]uint64{"n": {}, "c": {}}
	r := proto.Results{{Name: "n", Data: &n}, {Name: "c", Data: &c}}
	onResult := func(context.Context, proto.Block) error {
		for i := 0; i < r.Rows(); i++ {
			data["n"] = append(data["n"], n.Row(i))
			data["c"] = append(data["c"], c.Row(i))
		}
		return nil
	}
	if err := client.Do(ctx, ch.Query{Body: query, Result: &r, OnResult: onResult}); err != nil {
		panic(err)
	}
	fmt.Printf("%+v\n", data)
}

Error log

handle packet: unexpected packet "Totals"

Configuration

Any

Environment

Any

ClickHouse server

Any