diff --git a/CHANGELOG.md b/CHANGELOG.md index 905fc3d36f..f427eeebe9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# v2.22.4, 2024-03-25 + +## What's Changed +### Fixes 🐛 +* Fix column name with parantheses handle in prepare batch by @jkaflik in https://github.com/ClickHouse/clickhouse-go/pull/1252 +### Other Changes 🛠 +* Fix TestBatchAppendRows work different on cloud by @jkaflik in https://github.com/ClickHouse/clickhouse-go/pull/1251 + + +**Full Changelog**: https://github.com/ClickHouse/clickhouse-go/compare/v2.22.3...v2.22.4 + # v2.22.3, 2024-03-25 ## What's Changed diff --git a/client_info.go b/client_info.go index b6fef90528..d98ba3156f 100644 --- a/client_info.go +++ b/client_info.go @@ -30,7 +30,7 @@ const ClientName = "clickhouse-go" const ( ClientVersionMajor = 2 ClientVersionMinor = 22 - ClientVersionPatch = 3 + ClientVersionPatch = 4 ClientTCPProtocolVersion = proto.DBMS_TCP_PROTOCOL_VERSION ) diff --git a/conn_batch.go b/conn_batch.go index 246d9118f3..f463e4f91c 100644 --- a/conn_batch.go +++ b/conn_batch.go @@ -33,7 +33,7 @@ import ( ) var splitInsertRe = regexp.MustCompile(`(?i)\sVALUES\s*\(`) -var columnMatch = regexp.MustCompile(`.*\((?P.+)\)$`) +var columnMatch = regexp.MustCompile(`INSERT INTO .+\s\((?P.+)\)$`) func (c *connect) prepareBatch(ctx context.Context, query string, opts driver.PrepareBatchOptions, release func(*connect, error), acquire func(context.Context) (*connect, error)) (driver.Batch, error) { //defer func() { diff --git a/tests/batch_block_test.go b/tests/batch_block_test.go index 41d2fe61cf..c5a48027ac 100644 --- a/tests/batch_block_test.go +++ b/tests/batch_block_test.go @@ -18,7 +18,6 @@ package tests import ( - "sync/atomic" "testing" "github.com/ClickHouse/clickhouse-go/v2" @@ -32,14 +31,7 @@ import ( func TestBatchAppendRows(t *testing.T) { te, err := GetTestEnvironment(testSet) require.NoError(t, err) - blocksRead := atomic.Uint64{} opts := ClientOptionsFromEnv(te, clickhouse.Settings{}) - opts.Debug = true - opts.Debugf = func(format string, args ...interface{}) { - if format == "[batch.appendRowsBlocks] blockNum = %d" { - blocksRead.Store(uint64(args[0].(int))) // store the last block number read from rows - } - } conn, err := GetConnectionWithOptions(&opts) require.NoError(t, err) @@ -49,19 +41,14 @@ func TestBatchAppendRows(t *testing.T) { // given we have two tables and a million rows in the source table var tables = []string{"source", "target"} for _, table := range tables { - require.NoError(t, conn.Exec(context.Background(), "create table if not exists "+table+" (number1 Int, number2 String, number3 Tuple(String, Int), number4 DateTime) engine = MergeTree() order by tuple()")) + require.NoError(t, conn.Exec(context.Background(), "create table if not exists "+table+" (number1 Int, number2 String, number3 Tuple(String, Int), number4 DateTime) engine = Memory()")) defer conn.Exec(context.Background(), "drop table if exists "+table) } require.NoError(t, conn.Exec(ctx, "INSERT INTO source SELECT number, 'string', tuple('foo', number), now() FROM system.numbers LIMIT 1000000")) // when we create a batch with direct data block access 10 times - - selectCtx := clickhouse.Context(ctx, clickhouse.WithSettings(clickhouse.Settings{ - "max_block_size": 1000, - })) - - sourceRows, err := conn.Query(selectCtx, "SELECT * FROM source") + sourceRows, err := conn.Query(ctx, "SELECT * FROM source") require.NoError(t, err) defer sourceRows.Close() @@ -75,6 +62,5 @@ func TestBatchAppendRows(t *testing.T) { require.NoError(t, row.Err()) var count uint64 require.NoError(t, row.Scan(&count)) - assert.Equal(t, uint64(1000000), count) - assert.Equal(t, uint64(999), blocksRead.Load()) + assert.Equal(t, 1000000, int(count)) } diff --git a/tests/issues/1247_test.go b/tests/issues/1247_test.go new file mode 100644 index 0000000000..0b5695434c --- /dev/null +++ b/tests/issues/1247_test.go @@ -0,0 +1,31 @@ +package issues + +import ( + "context" + "testing" + + "github.com/ClickHouse/clickhouse-go/v2" + clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" + "github.com/stretchr/testify/require" +) + +func Test1247(t *testing.T) { + var ( + conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ + "max_execution_time": 60, + "allow_experimental_object_type": true, + }, nil, &clickhouse.Compression{ + Method: clickhouse.CompressionLZ4, + }) + ) + ctx := context.Background() + require.NoError(t, err) + const ddl = "CREATE TABLE test_1247 (`ColumnNameWithParentheses(something)` String) Engine MergeTree() ORDER BY tuple()" + require.NoError(t, conn.Exec(ctx, ddl)) + defer func() { + conn.Exec(ctx, "DROP TABLE IF EXISTS test_1247") + }() + + _, err = conn.PrepareBatch(context.Background(), "INSERT INTO test_1247 (`ColumnNameWithParentheses(something)`)") + require.NoError(t, err) +}