Skip to content

Commit ec8982d

Browse files
Merge pull request #1083 from nikandfor/main
feat(proto): ColArr.RowLen
2 parents 264694f + 6fe8fe8 commit ec8982d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

proto/col_arr.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ func (c *ColArr[T]) Infer(t ColumnType) error {
8080
return nil
8181
}
8282

83+
// RowLen returns i-th row array length.
84+
func (c ColArr[T]) RowLen(i int) int {
85+
var start int
86+
if i > 0 {
87+
start = int(c.Offsets[i-1])
88+
}
89+
90+
end := int(c.Offsets[i])
91+
92+
return end - start
93+
}
94+
8395
// RowAppend appends i-th row to target and returns it.
8496
func (c ColArr[T]) RowAppend(i int, target []T) []T {
8597
var start int

proto/col_arr_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ func TestColArrOfStr(t *testing.T) {
7474
require.Equal(t, col.Rows(), dec.Rows())
7575
require.Equal(t, ColumnType("Array(String)"), dec.Type())
7676
require.Equal(t, []string{"foo", "bar", "foo", "foo", "baz"}, dec.Row(0))
77+
require.Equal(t, 5, dec.RowLen(0))
7778
require.Equal(t, []string{"foo", "baz"}, dec.Row(1))
79+
require.Equal(t, 2, dec.RowLen(1))
7880
})
7981
t.Run("EOF", func(t *testing.T) {
8082
r := NewReader(bytes.NewReader(nil))
@@ -109,7 +111,9 @@ func TestArrOfLowCordStr(t *testing.T) {
109111
require.Equal(t, col.Rows(), dec.Rows())
110112
require.Equal(t, ColumnType("Array(LowCardinality(String))"), dec.Type())
111113
require.Equal(t, []string{"foo", "bar", "foo", "foo", "baz"}, dec.Row(0))
114+
require.Equal(t, 5, dec.RowLen(0))
112115
require.Equal(t, []string{"foo", "baz"}, dec.Row(1))
116+
require.Equal(t, 2, dec.RowLen(1))
113117
})
114118
t.Run("EOF", func(t *testing.T) {
115119
r := NewReader(bytes.NewReader(nil))

0 commit comments

Comments
 (0)