@@ -5,12 +5,70 @@ import (
55 "slices"
66 "unsafe"
77
8- "github.com/apache/arrow/go/v16 /arrow"
9- "github.com/apache/arrow/go/v16 /arrow/array"
10- "github.com/apache/arrow/go/v16 /arrow/memory"
8+ "github.com/apache/arrow/go/v18 /arrow"
9+ "github.com/apache/arrow/go/v18 /arrow/array"
10+ "github.com/apache/arrow/go/v18 /arrow/memory"
1111 "golang.org/x/exp/maps"
1212)
1313
14+ func stringRunEndBuilder (arr array.Builder ) * StringRunEndBuilder {
15+ ree := arr .(* array.RunEndEncodedBuilder )
16+ sb := ree .ValueBuilder ().(* array.StringBuilder )
17+ return & StringRunEndBuilder {
18+ ree : ree ,
19+ sb : sb ,
20+ }
21+ }
22+
23+ type StringRunEndBuilder struct {
24+ ree * array.RunEndEncodedBuilder
25+ sb * array.StringBuilder
26+ }
27+
28+ func (b * StringRunEndBuilder ) Release () {
29+ b .ree .Release ()
30+ }
31+
32+ func (b * StringRunEndBuilder ) NewArray () arrow.Array {
33+ return b .ree .NewArray ()
34+ }
35+
36+ func (b * StringRunEndBuilder ) Len () int {
37+ return b .ree .Len ()
38+ }
39+
40+ func (b * StringRunEndBuilder ) EnsureLength (l int ) {
41+ for b .ree .Len () < l {
42+ b .AppendNull ()
43+ }
44+ }
45+
46+ func (b * StringRunEndBuilder ) AppendNull () {
47+ b .ree .AppendNull ()
48+ }
49+
50+ func (b * StringRunEndBuilder ) AppendString (v string ) {
51+ if b .sb .Len () > 0 &&
52+ ! b .sb .IsNull (b .sb .Len ()- 1 ) &&
53+ v == b .sb .Value (int (b .sb .Len ()- 1 )) {
54+ b .ree .ContinueRun (1 )
55+ return
56+ }
57+ b .ree .Append (1 )
58+ b .sb .Append (v )
59+ }
60+
61+ func (b * StringRunEndBuilder ) AppendStringN (v string , n uint64 ) {
62+ if b .sb .Len () > 0 &&
63+ ! b .sb .IsNull (b .sb .Len ()- 1 ) &&
64+ v == b .sb .Value (int (b .sb .Len ()- 1 )) {
65+ b .ree .ContinueRun (n )
66+ return
67+ }
68+ b .ree .Append (n )
69+ b .sb .Append (v )
70+ }
71+
1472func binaryDictionaryRunEndBuilder (arr array.Builder ) * BinaryDictionaryRunEndBuilder {
1573 ree := arr .(* array.RunEndEncodedBuilder )
1674 bd := ree .ValueBuilder ().(* array.BinaryDictionaryBuilder )
@@ -105,6 +163,10 @@ func (b *Uint64RunEndBuilder) NewArray() arrow.Array {
105163 return b .ree .NewArray ()
106164}
107165
166+ func (b * Uint64RunEndBuilder ) Append (v uint64 ) {
167+ b .AppendN (v , 1 )
168+ }
169+
108170func (b * Uint64RunEndBuilder ) AppendN (v uint64 , n uint64 ) {
109171 if b .ub .Len () > 0 && v == b .ub .Value (b .ub .Len ()- 1 ) {
110172 b .ree .ContinueRun (n )
@@ -209,7 +271,7 @@ type SampleWriter struct {
209271 PeriodUnit * BinaryDictionaryRunEndBuilder
210272 Temporality * BinaryDictionaryRunEndBuilder
211273 Period * Int64RunEndBuilder
212- Duration * Int64RunEndBuilder
274+ Duration * Uint64RunEndBuilder
213275 Timestamp * Int64RunEndBuilder
214276}
215277
@@ -306,7 +368,7 @@ var (
306368 Name : "lines" ,
307369 Type : arrow .ListOf (arrow .StructOf ([]arrow.Field {{
308370 Name : "line" ,
309- Type : arrow .PrimitiveTypes .Int64 ,
371+ Type : arrow .PrimitiveTypes .Uint64 ,
310372 }, {
311373 Name : "column" ,
312374 Type : arrow .PrimitiveTypes .Uint64 ,
@@ -324,7 +386,7 @@ var (
324386 ),
325387 }, {
326388 Name : "function_start_line" ,
327- Type : arrow .PrimitiveTypes .Int64 ,
389+ Type : arrow .PrimitiveTypes .Uint64 ,
328390 }}... )),
329391 }}... )),
330392 }
@@ -397,7 +459,7 @@ var (
397459
398460 DurationField = arrow.Field {
399461 Name : "duration" ,
400- Type : arrow .RunEndEncodedOf (arrow .PrimitiveTypes .Int32 , arrow .PrimitiveTypes .Int64 ),
462+ Type : arrow .RunEndEncodedOf (arrow .PrimitiveTypes .Int32 , arrow .PrimitiveTypes .Uint64 ),
401463 }
402464
403465 TimestampField = arrow.Field {
@@ -536,7 +598,7 @@ func NewSampleWriter(mem memory.Allocator) *SampleWriter {
536598 periodUnit := binaryDictionaryRunEndBuilder (array .NewBuilder (mem , PeriodUnitField .Type ))
537599 temporality := binaryDictionaryRunEndBuilder (array .NewBuilder (mem , TemporalityField .Type ))
538600 period := int64RunEndBuilder (array .NewBuilder (mem , PeriodField .Type ))
539- duration := int64RunEndBuilder (array .NewBuilder (mem , DurationField .Type ))
601+ duration := uint64RunEndBuilder (array .NewBuilder (mem , DurationField .Type ))
540602 timestamp := int64RunEndBuilder (array .NewBuilder (mem , TimestampField .Type ))
541603
542604 return & SampleWriter {
0 commit comments