]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
1 | // Licensed to the Apache Software Foundation (ASF) under one |
2 | // or more contributor license agreements. See the NOTICE file | |
3 | // distributed with this work for additional information | |
4 | // regarding copyright ownership. The ASF licenses this file | |
5 | // to you under the Apache License, Version 2.0 (the | |
6 | // "License"); you may not use this file except in compliance | |
7 | // with the License. You may obtain a copy of the License at | |
8 | // | |
9 | // http://www.apache.org/licenses/LICENSE-2.0 | |
10 | // | |
11 | // Unless required by applicable law or agreed to in writing, software | |
12 | // distributed under the License is distributed on an "AS IS" BASIS, | |
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | // See the License for the specific language governing permissions and | |
15 | // limitations under the License. | |
16 | ||
17 | package array | |
18 | ||
19 | import ( | |
20 | "fmt" | |
21 | "strings" | |
22 | ||
23 | "github.com/apache/arrow/go/v6/arrow" | |
24 | ) | |
25 | ||
26 | {{range .In}} | |
27 | ||
28 | // A type which represents an immutable sequence of {{or .QualifiedType .Type}} values. | |
29 | type {{.Name}} struct { | |
30 | array | |
31 | values []{{or .QualifiedType .Type}} | |
32 | } | |
33 | ||
34 | // New{{.Name}}Data creates a new {{.Name}}. | |
35 | func New{{.Name}}Data(data *Data) *{{.Name}} { | |
36 | a := &{{.Name}}{} | |
37 | a.refCount = 1 | |
38 | a.setData(data) | |
39 | return a | |
40 | } | |
41 | ||
42 | // Reset resets the array for re-use. | |
43 | func (a *{{.Name}}) Reset(data *Data) { | |
44 | a.setData(data) | |
45 | } | |
46 | ||
47 | // Value returns the value at the specified index. | |
48 | func (a *{{.Name}}) Value(i int) {{or .QualifiedType .Type}} { return a.values[i] } | |
49 | ||
50 | // Values returns the values. | |
51 | func (a *{{.Name}}) {{.Name}}Values() []{{or .QualifiedType .Type}} { return a.values } | |
52 | ||
53 | // String returns a string representation of the array. | |
54 | func (a *{{.Name}}) String() string { | |
55 | o := new(strings.Builder) | |
56 | o.WriteString("[") | |
57 | for i, v := range a.values { | |
58 | if i > 0 { | |
59 | fmt.Fprintf(o, " ") | |
60 | } | |
61 | switch { | |
62 | case a.IsNull(i): | |
63 | o.WriteString("(null)") | |
64 | default: | |
65 | fmt.Fprintf(o, "%v", v) | |
66 | } | |
67 | } | |
68 | o.WriteString("]") | |
69 | return o.String() | |
70 | } | |
71 | ||
72 | func (a *{{.Name}}) setData(data *Data) { | |
73 | a.array.setData(data) | |
74 | vals := data.buffers[1] | |
75 | if vals != nil { | |
76 | a.values = arrow.{{.Name}}Traits.CastFromBytes(vals.Bytes()) | |
77 | beg := a.array.data.offset | |
78 | end := beg + a.array.data.length | |
79 | a.values = a.values[beg:end] | |
80 | } | |
81 | } | |
82 | ||
83 | func arrayEqual{{.Name}}(left, right *{{.Name}}) bool { | |
84 | for i := 0; i < left.Len(); i++ { | |
85 | if left.IsNull(i) { | |
86 | continue | |
87 | } | |
88 | if left.Value(i) != right.Value(i) { | |
89 | return false | |
90 | } | |
91 | } | |
92 | return true | |
93 | } | |
94 | ||
95 | {{end}} |