@@ -24,7 +24,7 @@ import (
2424 "github.com/apache/arrow/go/arrow/memory"
2525)
2626
27- // A type which represents the memory and metadata for an Arrow array.
27+ // Data is a type which represents the memory and metadata for an Arrow array.
2828type Data struct {
2929 refCount int64
3030 dtype arrow.DataType
@@ -35,6 +35,7 @@ type Data struct {
3535 childData []* Data // TODO(sgc): managed by ListArray, StructArray and UnionArray types
3636}
3737
38+ // NewData creates a new Data.
3839func NewData (dtype arrow.DataType , length int , buffers []* memory.Buffer , childData []* Data , nulls , offset int ) * Data {
3940 for _ , b := range buffers {
4041 if b != nil {
@@ -59,6 +60,42 @@ func NewData(dtype arrow.DataType, length int, buffers []*memory.Buffer, childDa
5960 }
6061}
6162
63+ // Reset sets the Data for re-use.
64+ func (d * Data ) Reset (dtype arrow.DataType , length int , buffers []* memory.Buffer , childData []* Data , nulls , offset int ) {
65+ // Retain new buffers before releasing existing buffers in-case they're the same ones to prevent accidental premature
66+ // release.
67+ for _ , b := range buffers {
68+ if b != nil {
69+ b .Retain ()
70+ }
71+ }
72+ for _ , b := range d .buffers {
73+ if b != nil {
74+ b .Release ()
75+ }
76+ }
77+ d .buffers = buffers
78+
79+ // Retain new children data before releasing existing children data in-case they're the same ones to prevent accidental
80+ // premature release.
81+ for _ , d := range childData {
82+ if d != nil {
83+ d .Retain ()
84+ }
85+ }
86+ for _ , d := range d .childData {
87+ if d != nil {
88+ d .Release ()
89+ }
90+ }
91+ d .childData = childData
92+
93+ d .dtype = dtype
94+ d .length = length
95+ d .nulls = nulls
96+ d .offset = offset
97+ }
98+
6299// Retain increases the reference count by 1.
63100// Retain may be called simultaneously from multiple goroutines.
64101func (d * Data ) Retain () {
@@ -85,10 +122,19 @@ func (d *Data) Release() {
85122 }
86123}
87124
88- func (d * Data ) DataType () arrow.DataType { return d .dtype }
89- func (d * Data ) NullN () int { return d .nulls }
90- func (d * Data ) Len () int { return d .length }
91- func (d * Data ) Offset () int { return d .offset }
125+ // DataType returns the DataType of the data.
126+ func (d * Data ) DataType () arrow.DataType { return d .dtype }
127+
128+ // NullN returns the number of nulls.
129+ func (d * Data ) NullN () int { return d .nulls }
130+
131+ // Len returns the length.
132+ func (d * Data ) Len () int { return d .length }
133+
134+ // Offset returns the offset.
135+ func (d * Data ) Offset () int { return d .offset }
136+
137+ // Buffers returns the buffers.
92138func (d * Data ) Buffers () []* memory.Buffer { return d .buffers }
93139
94140// NewSliceData returns a new slice that shares backing data with the input.
0 commit comments