clickhouse-go icon indicating copy to clipboard operation
clickhouse-go copied to clipboard

PrepareBatch for tablename with special characters in name, stop works after upgrade from 2.23.2 to 2.26.0

Open Slach opened this issue 1 year ago • 1 comments

Observed

PrepareBatch for tablename with special characters in name, stop works after upgrade from 2.23.2 to 2.26.0

Expected behaviour

2.23.2 output

[clickhouse][conn=1][127.0.0.1:9000][handshake] ->  0.0.0
[clickhouse][conn=1][127.0.0.1:9000][handshake] <- ClickHouse (clickhouse) server version 24.3.3 revision 54467 (timezone UTC)
[clickhouse][conn=1][127.0.0.1:9000][send query] compression="none" CREATE DATABASE IF NOT EXISTS `_test#$.ДБ_ordinary__TestS3NoDeletePermission` ENGINE=Ordinary
[clickhouse][conn=1][127.0.0.1:9000][send data] compression="none"
[clickhouse][conn=1][127.0.0.1:9000][end of stream]
[clickhouse][conn=1][127.0.0.1:9000][send query] compression="none" CREATE  TABLE  IF NOT EXISTS `_test#$.ДБ_ordinary__TestS3NoDeletePermission`.`2. Таблица №2_TestS3NoDeletePermission` (id UInt64, User String) ENGINE = MergeTree ORDER BY id SETTINGS index_granularity = 8192
[clickhouse][conn=1][127.0.0.1:9000][send data] compression="none"
[clickhouse][conn=1][127.0.0.1:9000][end of stream]
[clickhouse][conn=1][127.0.0.1:9000][send query] compression="none" INSERT INTO `_test#$.ДБ_ordinary__TestS3NoDeletePermission`.`2. Таблица №2_TestS3NoDeletePermission` VALUES
[clickhouse][conn=1][127.0.0.1:9000][send data] compression="none"
[clickhouse][conn=1][127.0.0.1:9000][table columns]
[clickhouse][conn=1][127.0.0.1:9000][read data] compression="none". block: columns=2, rows=0
TRY INSERT VALUES map[User:Alice id:1]
TRY INSERT VALUES map[User:Bob id:2]
TRY INSERT VALUES map[User:John id:3]
TRY INSERT VALUES map[User:Frank id:4]
TRY INSERT VALUES map[User:Nancy id:5]
TRY INSERT VALUES map[User:Brandon id:6]
[clickhouse][conn=1][127.0.0.1:9000][send data] compression="none"
[clickhouse][conn=1][127.0.0.1:9000][send data] compression="none"
[clickhouse][conn=1][127.0.0.1:9000][read data] compression="none". block: columns=6, rows=15
[clickhouse][conn=1][127.0.0.1:9000][profile events] rows=15
[clickhouse][conn=1][127.0.0.1:9000][read data] compression="none". block: columns=6, rows=26
[clickhouse][conn=1][127.0.0.1:9000][profile events] rows=26
[clickhouse][conn=1][127.0.0.1:9000][end of stream]

Code example

following code works success with 2.23.2 and doesn't work with 2.24.0, 2.25.0, 2.26.0

package main

import (
	"context"
	"fmt"
	"github.com/ClickHouse/clickhouse-go/v2"
	"os"
)

func main() {
	opt := &clickhouse.Options{
		Addr:            []string{"localhost:9000"},
		MaxOpenConns:    1,
		ConnMaxLifetime: 0, // don't change it, it related to SYSTEM SHUTDOWN behavior for properly rebuild RBAC lists on 20.4-22.3
		MaxIdleConns:    1,
		Debug:           true,
	}

	ch, err := clickhouse.Open(opt)
	if err != nil {
		fmt.Printf("connection error: %v", err)
		os.Exit(1)
	}
	createDatabaseSQL := "CREATE DATABASE IF NOT EXISTS `_test#$.ДБ_ordinary__TestS3NoDeletePermission` ENGINE=Ordinary"
	if err = ch.Exec(context.Background(), createDatabaseSQL); err != nil {
		fmt.Printf("%s error: %v", createDatabaseSQL, err)
		os.Exit(1)
	}
	createTableSQL := "CREATE  TABLE  IF NOT EXISTS `_test#$.ДБ_ordinary__TestS3NoDeletePermission`.`2. Таблица №2_TestS3NoDeletePermission` (id UInt64, User String) ENGINE = MergeTree ORDER BY id SETTINGS index_granularity = 8192"
	if err = ch.Exec(context.Background(), createTableSQL); err != nil {
		fmt.Printf("%s error: %v", createTableSQL, err)
		os.Exit(1)
	}

	insertSQL := "INSERT INTO `_test#$.ДБ_ordinary__TestS3NoDeletePermission`.`2. Таблица №2_TestS3NoDeletePermission`"
	batch, err := ch.PrepareBatch(context.Background(), insertSQL)
	if err != nil {
		fmt.Printf("ch.PrepareBatch(\"%s\") error: %v", insertSQL, err)
		os.Exit(1)
	}
	Fields :=  []string{"id", "User"}
	Rows := []map[string]interface{}{
		{"id": uint64(1), "User": "Alice"},
		{"id": uint64(2), "User": "Bob"},
		{"id": uint64(3), "User": "John"},
		{"id": uint64(4), "User": "Frank"},
		{"id": uint64(5), "User": "Nancy"},
		{"id": uint64(6), "User": "Brandon"},
	}

	for _, row := range Rows {
		insertData := make([]interface{}, len(Fields))
		fmt.Printf("TRY INSERT VALUES %v\n", row)
		for idx, field := range Fields {
			insertData[idx] = row[field]
		}
		if err = batch.Append(insertData...); err != nil {
			fmt.Printf("batch.Append(%#v) error: %v", insertData, err)
			os.Exit(1)
		}
	}
	if err = batch.Send(); err != nil {
		fmt.Printf("batch.Send() error: %v", err)
		os.Exit(1)
	}
}

Error log

[clickhouse][conn=1][127.0.0.1:9000][handshake] ->  0.0.0
[clickhouse][conn=1][127.0.0.1:9000][handshake] <- ClickHouse (clickhouse) server version 24.3.3 revision 54467 (timezone UTC)
[clickhouse][conn=1][127.0.0.1:9000][send query] compression="none" CREATE DATABASE IF NOT EXISTS `_test#$.ДБ_ordinary__TestS3NoDeletePermission` ENGINE=Ordinary
[clickhouse][conn=1][127.0.0.1:9000][send data] compression="none"
[clickhouse][conn=1][127.0.0.1:9000][end of stream]
[clickhouse][conn=1][127.0.0.1:9000][send query] compression="none" CREATE  TABLE  IF NOT EXISTS `_test#$.ДБ_ordinary__TestS3NoDeletePermission`.`2. Таблица №2_TestS3NoDeletePermission` (id UInt64, User String) ENGINE = MergeTree ORDER BY id SETTINGS index_granularity = 8192
[clickhouse][conn=1][127.0.0.1:9000][send data] compression="none"
[clickhouse][conn=1][127.0.0.1:9000][end of stream]
[clickhouse][conn=1][127.0.0.1:9000][send query] compression="none" INSERT INTO `_test#$.ДБ_ordinary__TestS3NoDeletePermission`.`2. VALUES
[clickhouse][conn=1][127.0.0.1:9000][send data] compression="none"
[clickhouse][conn=1][127.0.0.1:9000][exception] code: 62, message: Syntax error: failed at position 63 ('`2. VALUES'): `2. VALUES. Back quoted string is not closed: '`2. VALUES'
ch.PrepareBatch("INSERT INTO `_test#$.ДБ_ordinary__TestS3NoDeletePermission`.`2. Таблица №2_TestS3NoDeletePermission`") error: code: 62, message: Syntax error: failed at position 63 ('`2. VALUES'): `2. VALUES. Back quoted string is not closed: '`2. VALUES'
exit status 1

Details

Environment

  • [x] clickhouse-go version: 2.26.0
  • [x] Interface: ClickHouse API
  • [x] Go version: 1.22
  • [x] Operating system: Ubuntu 22.04
  • [x] ClickHouse version: any
  • [x] Is it a ClickHouse Cloud? no

Slach avatar Jul 02 '24 11:07 Slach

Thanks for reporting @Slach . This is a regression, definitely. I will take care.

jkaflik avatar Jul 02 '24 14:07 jkaflik

@jkaflik any news?

Slach avatar Aug 03 '24 16:08 Slach