From f3cb25b79d8bae0f81567dc46709e80f0f1fee3f Mon Sep 17 00:00:00 2001 From: achmad Date: Fri, 20 Sep 2024 07:35:38 +0700 Subject: [PATCH 1/3] test(issue): issue 1409 --- tests/issues/1409_test.go | 68 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/issues/1409_test.go diff --git a/tests/issues/1409_test.go b/tests/issues/1409_test.go new file mode 100644 index 0000000000..187f832f61 --- /dev/null +++ b/tests/issues/1409_test.go @@ -0,0 +1,68 @@ +package issues + +import ( + "context" + "testing" + "time" + + clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" + "github.com/stretchr/testify/require" +) + +func Test1409(t *testing.T) { + var ( + ctx = context.Background() + conn, err = clickhouse_tests.GetConnection("issues", nil, nil, nil) + ) + require.NoError(t, err) + const ddl = ` + CREATE TABLE issue_1409 ( + id UInt32, + name String, + birth_date Date, + is_active Boolean + ) Engine = Memory + ` + defer func() { + conn.Exec(ctx, "DROP TABLE issue_1409") + }() + + err = conn.Exec(ctx, ddl) + require.NoError(t, err) + + batch, err := conn.PrepareBatch(ctx, "INSERT INTO issue_1409") + require.NoError(t, err) + + err = batch.Append(uint32(1), "Alice", time.Date(1990, 6, 15, 0, 0, 0, 0, time.UTC), true) + require.NoError(t, err) + // Append the second row + err = batch.Append(uint32(2), "Bob", time.Date(1985, 12, 30, 0, 0, 0, 0, time.UTC), false) + require.NoError(t, err) + + err = batch.Column(0).AppendRow(uint32(3)) + require.NoError(t, err) + err = batch.Column(1).AppendRow("Charlie") + require.NoError(t, err) + err = batch.Column(2).AppendRow(time.Date(1990, 6, 15, 0, 0, 0, 0, time.UTC)) + require.NoError(t, err) + err = batch.Column(3).AppendRow(true) + require.NoError(t, err) + + // test the issue_1409 + exampleId := []uint32{4, 5, 6} + exampleName := []string{"Dave", "Eve", "Frank"} + exampleBirthDate := []time.Time{time.Date(1990, 6, 15, 0, 0, 0, 0, time.UTC), time.Date(1985, 12, 30, 0, 0, 0, 0, time.UTC), time.Date(1990, 6, 15, 0, 0, 0, 0, time.UTC)} + exampleIsActive := []bool{true, false, true} + + err = batch.Column(0).Append(exampleId) + require.NoError(t, err) + err = batch.Column(1).Append(exampleName) + require.NoError(t, err) + err = batch.Column(2).Append(exampleBirthDate) + require.NoError(t, err) + err = batch.Column(3).Append(exampleIsActive) + require.NoError(t, err) + + err = batch.Send() + require.NoError(t, err) +} From c02a37e04e5e6caf5dc9cc278e4d21d4fee5890d Mon Sep 17 00:00:00 2001 From: achmad Date: Fri, 20 Sep 2024 07:57:45 +0700 Subject: [PATCH 2/3] chore(examples): add appendrow in columnar insert example --- examples/clickhouse_api/columnar_insert.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/examples/clickhouse_api/columnar_insert.go b/examples/clickhouse_api/columnar_insert.go index ae376ad287..5dc107c858 100644 --- a/examples/clickhouse_api/columnar_insert.go +++ b/examples/clickhouse_api/columnar_insert.go @@ -71,5 +71,23 @@ func ColumnInsert() error { if err := batch.Column(3).Append(col4); err != nil { return err } + + // AppendRow is a shortcut for Append(row) + if err := batch.Column(0).AppendRow(uint64(1_000)); err != nil { + return err + } + + if err := batch.Column(1).AppendRow("Golang SQL database driver"); err != nil { + return err + } + + if err := batch.Column(2).AppendRow([]uint8{1, 2, 3, 4, 5, 6, 7, 8, 9}); err != nil { + return err + } + + if err := batch.Column(3).AppendRow(time.Now()); err != nil { + return err + } + return batch.Send() } From baf0d9efb559d2b16b2c0e2d559bc893d32dff0f Mon Sep 17 00:00:00 2001 From: achmad Date: Sun, 22 Sep 2024 02:31:52 +0700 Subject: [PATCH 3/3] test: remove unused test file 1409_test.go --- tests/issues/1409_test.go | 68 --------------------------------------- 1 file changed, 68 deletions(-) delete mode 100644 tests/issues/1409_test.go diff --git a/tests/issues/1409_test.go b/tests/issues/1409_test.go deleted file mode 100644 index 187f832f61..0000000000 --- a/tests/issues/1409_test.go +++ /dev/null @@ -1,68 +0,0 @@ -package issues - -import ( - "context" - "testing" - "time" - - clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" - "github.com/stretchr/testify/require" -) - -func Test1409(t *testing.T) { - var ( - ctx = context.Background() - conn, err = clickhouse_tests.GetConnection("issues", nil, nil, nil) - ) - require.NoError(t, err) - const ddl = ` - CREATE TABLE issue_1409 ( - id UInt32, - name String, - birth_date Date, - is_active Boolean - ) Engine = Memory - ` - defer func() { - conn.Exec(ctx, "DROP TABLE issue_1409") - }() - - err = conn.Exec(ctx, ddl) - require.NoError(t, err) - - batch, err := conn.PrepareBatch(ctx, "INSERT INTO issue_1409") - require.NoError(t, err) - - err = batch.Append(uint32(1), "Alice", time.Date(1990, 6, 15, 0, 0, 0, 0, time.UTC), true) - require.NoError(t, err) - // Append the second row - err = batch.Append(uint32(2), "Bob", time.Date(1985, 12, 30, 0, 0, 0, 0, time.UTC), false) - require.NoError(t, err) - - err = batch.Column(0).AppendRow(uint32(3)) - require.NoError(t, err) - err = batch.Column(1).AppendRow("Charlie") - require.NoError(t, err) - err = batch.Column(2).AppendRow(time.Date(1990, 6, 15, 0, 0, 0, 0, time.UTC)) - require.NoError(t, err) - err = batch.Column(3).AppendRow(true) - require.NoError(t, err) - - // test the issue_1409 - exampleId := []uint32{4, 5, 6} - exampleName := []string{"Dave", "Eve", "Frank"} - exampleBirthDate := []time.Time{time.Date(1990, 6, 15, 0, 0, 0, 0, time.UTC), time.Date(1985, 12, 30, 0, 0, 0, 0, time.UTC), time.Date(1990, 6, 15, 0, 0, 0, 0, time.UTC)} - exampleIsActive := []bool{true, false, true} - - err = batch.Column(0).Append(exampleId) - require.NoError(t, err) - err = batch.Column(1).Append(exampleName) - require.NoError(t, err) - err = batch.Column(2).Append(exampleBirthDate) - require.NoError(t, err) - err = batch.Column(3).Append(exampleIsActive) - require.NoError(t, err) - - err = batch.Send() - require.NoError(t, err) -}