Skip to content

Commit

Permalink
Merge pull request #213 from ClickHouse/feat/arrayable-col-fixed-str
Browse files Browse the repository at this point in the history
feat(proto): add missed Array() methods
  • Loading branch information
ernado authored Nov 22, 2022
2 parents 33c3e04 + 33d8891 commit 20b7501
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions proto/col_datetime64.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ func (c ColDateTime64) Raw() *ColDateTime64Raw {
return &ColDateTime64Raw{ColDateTime64: c}
}

func (c *ColDateTime64) Array() *ColArr[time.Time] {
return &ColArr[time.Time]{Data: c}
}

var (
_ ColumnOf[DateTime64] = (*ColDateTime64Raw)(nil)
_ Inferable = (*ColDateTime64Raw)(nil)
Expand Down
7 changes: 7 additions & 0 deletions proto/col_fixed_str.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,10 @@ func (c *ColFixedStr) DecodeColumn(r *Reader, rows int) error {
}
return nil
}

// Array returns new Array(FixedString).
func (c *ColFixedStr) Array() *ColArr[[]byte] {
return &ColArr[[]byte]{
Data: c,
}
}
27 changes: 27 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,33 @@ func TestClient_Query(t *testing.T) {
require.Equal(t, data, gotData)
})
})
t.Run("ArrayFixedStr", func(t *testing.T) {
t.Parallel()
conn := Conn(t)
require.NoError(t, conn.Do(ctx, Query{
Body: "CREATE TABLE test_table (v Array(FixedString(10))) ENGINE = Memory",
}), "create table")

v := (&proto.ColFixedStr{Size: 10}).Array()

v.Append([][]byte{
bytes.Repeat([]byte("a"), 10),
bytes.Repeat([]byte("b"), 10),
bytes.Repeat([]byte("c"), 10),
})
v.Append([][]byte{
bytes.Repeat([]byte("d"), 10),
bytes.Repeat([]byte("e"), 10),
bytes.Repeat([]byte("f"), 10),
})

require.NoError(t, conn.Do(ctx, Query{
Body: "INSERT INTO test_table VALUES",
Input: []proto.InputColumn{
{Name: "v", Data: v},
},
}), "insert")
})
t.Run("ArrayLowCardinality", func(t *testing.T) {
t.Parallel()
conn := Conn(t)
Expand Down

0 comments on commit 20b7501

Please sign in to comment.