Skip to content

feat: Support ephemeral columns #1701

@kavirajk

Description

@kavirajk

When I try to use ephemeral columns in ClickHouse. The create and insert works, but throws error when querying it back.

panic: readData: block decode: unexpected value 111 for boolean

goroutine 1 [running]:
main.main()
	/home/kavi/src/play-go2/ephemeral.go:57 +0x48b
exit status 2

Here is the code I used

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/ClickHouse/clickhouse-go/v2"
)

func main() {
	conn, err := clickhouse.Open(&clickhouse.Options{
		Protocol: clickhouse.HTTP,
		Addr:     []string{"localhost:8123"},
		Auth: clickhouse.Auth{
			Database: "default",
			Username: "default",
			Password: "",
		},
	})

	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to connect: %v\n", err)
		os.Exit(1)
	}
	defer conn.Close()

	// Execute query that will throw exception on row 3
	ctx := context.Background()
	ddl := `CREATE OR REPLACE TABLE test
(
    id UInt64,
    unhexed String EPHEMERAL,
    hexed FixedString(4) DEFAULT unhex(unhexed)
)
ENGINE = MergeTree
ORDER BY id;`
	if err := conn.Exec(ctx, ddl); err != nil {
		panic(err)
	}

	i := `INSERT INTO test (id, unhexed) VALUES (1, '5a90b714');`

	if err := conn.Exec(ctx, i); err != nil {
		panic(err)
	}

	query := `SELECT
    id,
    hexed,
    hex(hexed)
FROM test
FORMAT Vertical;`

	rows, err := conn.Query(ctx, query)
	if err != nil {
		panic(err)
	}

	for rows.Next() {
		var (
			id  uint64
			un  string
			hex string
		)
		if err := rows.Scan(&id, &un, &hex); err != nil {
			panic(err)
		}
		fmt.Println("id: ", id, "un: ", un, "hex: ", hex)
	}
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions