Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions ch/chschema/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ func (c *UUIDColumn) ReadFrom(rd *chproto.Reader, numRow int) error {
c.AllocForReading(numRow)

for i := range c.Column {
err := rd.UUID(c.Column[i][:])
if err != nil {
if err := rd.UUID(c.Column[i][:]); err != nil {
return err
}
}
Expand Down Expand Up @@ -557,3 +556,41 @@ func (c BFloat16HistColumn) WriteTo(wr *chproto.Writer) error {
}
return nil
}

//------------------------------------------------------------------------------

type MapStringStringColumn struct {
ColumnOf[map[string]string]
}

var _ Columnar = (*MapStringStringColumn)(nil)

func NewMapStringStringColumn() Columnar {
return new(MapStringStringColumn)
}

func (c MapStringStringColumn) Type() reflect.Type {
return mapStringStringType
}

func (c *MapStringStringColumn) ReadFrom(rd *chproto.Reader, numRow int) error {
c.AllocForReading(numRow)

for i := range c.Column {
// TODO: implement
if err := rd.UUID(c.Column[i][:]); err != nil {
return err
}
}

return nil
}

func (c MapStringStringColumn) WriteTo(wr *chproto.Writer) error {
for i := range c.Column {
v := c.Column[i]
// TODO: implement
wr.Write(v)
}
return nil
}
5 changes: 5 additions & 0 deletions ch/chschema/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ var (

sliceUint64Type = reflect.TypeOf((*[]uint64)(nil)).Elem()
sliceFloat32Type = reflect.TypeOf((*[]float32)(nil)).Elem()

mapStringStringType = reflect.TypeOf((*map[string]string)(nil)).Elem()
)

var chTypes = [...]string{
Expand Down Expand Up @@ -177,6 +179,9 @@ func ColumnFactory(chType string, typ reflect.Type) NewColumnFunc {
case "Array(Array(Bool))":
return NewArrayArrayStringColumn

case "Map(String, String)":
return NewMapStringStringColumn

case chtype.Any:
return nil
}
Expand Down
5 changes: 5 additions & 0 deletions ch/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ func TestClickhouse(t *testing.T) {

tests := []func(ctx context.Context, t *testing.T, db *ch.DB){
testWhereBytes,
testMapStringString,
}
for _, fn := range tests {
t.Run(funcName(fn), func(t *testing.T) {
Expand Down Expand Up @@ -352,6 +353,10 @@ func testWhereBytes(ctx context.Context, t *testing.T, db *ch.DB) {
require.Equal(t, data.Bytes, got.Bytes)
}

func testMapStringString(ctx context.Context, t *testing.T, db *ch.DB) {
// TODO: add test
}

type Event struct {
ch.CHModel `ch:"goch_events,partition:toYYYYMM(created_at)"`

Expand Down