@@ -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 )
@@ -157,11 +219,11 @@ type LocationsWriter struct {
157219 MappingBuildID * BinaryDictionaryRunEndBuilder
158220 Lines * array.ListBuilder
159221 Line * array.StructBuilder
160- LineNumber * array.Int64Builder
222+ LineNumber * array.Uint64Builder
161223 FunctionName * array.BinaryDictionaryBuilder
162224 FunctionSystemName * array.BinaryDictionaryBuilder
163225 FunctionFilename * BinaryDictionaryRunEndBuilder
164- FunctionStartLine * array.Int64Builder
226+ FunctionStartLine * array.Uint64Builder
165227}
166228
167229func (w * LocationsWriter ) NewRecord (stacktraceIDs * array.Binary ) arrow.Record {
@@ -208,7 +270,7 @@ type SampleWriter struct {
208270 PeriodUnit * BinaryDictionaryRunEndBuilder
209271 Temporality * BinaryDictionaryRunEndBuilder
210272 Period * Int64RunEndBuilder
211- Duration * Int64RunEndBuilder
273+ Duration * Uint64RunEndBuilder
212274 Timestamp * Int64RunEndBuilder
213275}
214276
@@ -305,7 +367,7 @@ var (
305367 Name : "lines" ,
306368 Type : arrow .ListOf (arrow .StructOf ([]arrow.Field {{
307369 Name : "line" ,
308- Type : arrow .PrimitiveTypes .Int64 ,
370+ Type : arrow .PrimitiveTypes .Uint64 ,
309371 }, {
310372 Name : "function_name" ,
311373 Type : & arrow.DictionaryType {IndexType : arrow .PrimitiveTypes .Uint32 , ValueType : arrow .BinaryTypes .Binary },
@@ -320,7 +382,7 @@ var (
320382 ),
321383 }, {
322384 Name : "function_start_line" ,
323- Type : arrow .PrimitiveTypes .Int64 ,
385+ Type : arrow .PrimitiveTypes .Uint64 ,
324386 }}... )),
325387 }}... )),
326388 }
@@ -393,7 +455,7 @@ var (
393455
394456 DurationField = arrow.Field {
395457 Name : "duration" ,
396- Type : arrow .RunEndEncodedOf (arrow .PrimitiveTypes .Int32 , arrow .PrimitiveTypes .Int64 ),
458+ Type : arrow .RunEndEncodedOf (arrow .PrimitiveTypes .Int32 , arrow .PrimitiveTypes .Uint64 ),
397459 }
398460
399461 TimestampField = arrow.Field {
@@ -493,11 +555,11 @@ func NewLocationsWriter(mem memory.Allocator) *LocationsWriter {
493555
494556 lines := locations .FieldBuilder (7 ).(* array.ListBuilder )
495557 line := lines .ValueBuilder ().(* array.StructBuilder )
496- lineNumber := line .FieldBuilder (0 ).(* array.Int64Builder )
558+ lineNumber := line .FieldBuilder (0 ).(* array.Uint64Builder )
497559 functionName := line .FieldBuilder (1 ).(* array.BinaryDictionaryBuilder )
498560 functionSystemName := line .FieldBuilder (2 ).(* array.BinaryDictionaryBuilder )
499561 functionFilename := binaryDictionaryRunEndBuilder (line .FieldBuilder (3 ))
500- functionStartLine := line .FieldBuilder (4 ).(* array.Int64Builder )
562+ functionStartLine := line .FieldBuilder (4 ).(* array.Uint64Builder )
501563
502564 return & LocationsWriter {
503565 IsComplete : isComplete ,
@@ -530,7 +592,7 @@ func NewSampleWriter(mem memory.Allocator) *SampleWriter {
530592 periodUnit := binaryDictionaryRunEndBuilder (array .NewBuilder (mem , PeriodUnitField .Type ))
531593 temporality := binaryDictionaryRunEndBuilder (array .NewBuilder (mem , TemporalityField .Type ))
532594 period := int64RunEndBuilder (array .NewBuilder (mem , PeriodField .Type ))
533- duration := int64RunEndBuilder (array .NewBuilder (mem , DurationField .Type ))
595+ duration := uint64RunEndBuilder (array .NewBuilder (mem , DurationField .Type ))
534596 timestamp := int64RunEndBuilder (array .NewBuilder (mem , TimestampField .Type ))
535597
536598 return & SampleWriter {
0 commit comments