Skip to content

Commit

Permalink
clickhouse-go-655 Establish batch semantics (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkaflik authored Dec 16, 2022
1 parent 4d33629 commit ee4161e
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/issues/655_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package issues

import (
"context"
"github.com/ClickHouse/clickhouse-go/v2"
clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)

// Test655 confirms an agreed semantic on failing batch append results with entire batch cancellation.
func Test655(t *testing.T) {
var (
conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{
"max_execution_time": 60,
}, nil, &clickhouse.Compression{
Method: clickhouse.CompressionLZ4,
})
ctx = context.Background()
)

require.NoError(t, err)
conn.Exec(ctx, "DROP TABLE test_enum")
const ddl = `CREATE TABLE test_enum (
Col1 Enum8 ('Click'=5, 'House'=25)
) Engine Memory`
require.NoError(t, conn.Exec(ctx, ddl))

defer func() {
conn.Exec(ctx, "DROP TABLE test_enum")
}()
batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_enum")
require.NoError(t, err)
type request struct {
Col1 string
}
require.Error(t, batch.AppendStruct(&request{Col1: "house"}), "clickhouse [AppendRow]: (Col1 Enum8('Click' = 5, 'House' = 25)) unknown element \"house\"")
assert.ErrorContains(t, batch.Send(), "clickhouse: batch is invalid. check appended data is correct")
}

0 comments on commit ee4161e

Please sign in to comment.