Skip to content

Commit b5c76bb

Browse files
authored
feat(types): Rename Mac -> MAC (#868)
1 parent 1fb4eaf commit b5c76bb

File tree

6 files changed

+64
-64
lines changed

6 files changed

+64
-64
lines changed

internal/servers/destination/v0/schemav2tov3.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ func TypeV2ToV3(dataType schemav2.ValueType) arrow.DataType {
9191
case schemav2.TypeCIDRArray:
9292
return arrow.ListOf(types.ExtensionTypes.Inet)
9393
case schemav2.TypeMacAddr:
94-
return types.ExtensionTypes.Mac
94+
return types.ExtensionTypes.MAC
9595
case schemav2.TypeMacAddrArray:
96-
return arrow.ListOf(types.ExtensionTypes.Mac)
96+
return arrow.ListOf(types.ExtensionTypes.MAC)
9797
default:
9898
panic("unknown type " + typ.Name())
9999
}
@@ -227,16 +227,16 @@ func CQTypesToRecord(mem memory.Allocator, c []schemav2.CQTypes, arrowSchema *ar
227227
}
228228
case schemav2.TypeMacAddr:
229229
if c[j][i].(*schemav2.Macaddr).Status == schemav2.Present {
230-
bldr.Field(i).(*types.MacBuilder).Append(c[j][i].(*schemav2.Macaddr).Addr)
230+
bldr.Field(i).(*types.MACBuilder).Append(c[j][i].(*schemav2.Macaddr).Addr)
231231
} else {
232-
bldr.Field(i).(*types.MacBuilder).AppendNull()
232+
bldr.Field(i).(*types.MACBuilder).AppendNull()
233233
}
234234
case schemav2.TypeMacAddrArray:
235235
if c[j][i].(*schemav2.MacaddrArray).Status == schemav2.Present {
236236
listBldr := bldr.Field(i).(*array.ListBuilder)
237237
listBldr.Append(true)
238238
for _, e := range c[j][i].(*schemav2.MacaddrArray).Elements {
239-
listBldr.ValueBuilder().(*types.MacBuilder).Append(e.Addr)
239+
listBldr.ValueBuilder().(*types.MACBuilder).Append(e.Addr)
240240
}
241241
} else {
242242
bldr.Field(i).(*array.ListBuilder).AppendNull()

schema/testdata.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ func TestSourceTable(name string) *Table {
100100
},
101101
{
102102
Name: "macaddr",
103-
Type: types.ExtensionTypes.Mac,
103+
Type: types.ExtensionTypes.MAC,
104104
},
105105
{
106106
Name: "macaddr_array",
107-
Type: arrow.ListOf(types.ExtensionTypes.Mac),
107+
Type: arrow.ListOf(types.ExtensionTypes.MAC),
108108
},
109109
},
110110
}
@@ -228,24 +228,24 @@ func GenTestData(table *Table, opts GenTestDataOptions) []arrow.Record {
228228
panic(err)
229229
}
230230
bldr.Field(i).(*array.ListBuilder).ValueBuilder().(*types.InetBuilder).Append(ipnet)
231-
} else if arrow.TypeEqual(c.Type, types.ExtensionTypes.Mac) {
231+
} else if arrow.TypeEqual(c.Type, types.ExtensionTypes.MAC) {
232232
mac, err := net.ParseMAC("aa:bb:cc:dd:ee:ff")
233233
if err != nil {
234234
panic(err)
235235
}
236-
bldr.Field(i).(*types.MacBuilder).Append(mac)
237-
} else if arrow.TypeEqual(c.Type, arrow.ListOf(types.ExtensionTypes.Mac)) {
236+
bldr.Field(i).(*types.MACBuilder).Append(mac)
237+
} else if arrow.TypeEqual(c.Type, arrow.ListOf(types.ExtensionTypes.MAC)) {
238238
mac, err := net.ParseMAC("aa:bb:cc:dd:ee:ff")
239239
if err != nil {
240240
panic(err)
241241
}
242242
bldr.Field(i).(*array.ListBuilder).Append(true)
243-
bldr.Field(i).(*array.ListBuilder).ValueBuilder().(*types.MacBuilder).Append(mac)
243+
bldr.Field(i).(*array.ListBuilder).ValueBuilder().(*types.MACBuilder).Append(mac)
244244
mac, err = net.ParseMAC("11:22:33:44:55:66")
245245
if err != nil {
246246
panic(err)
247247
}
248-
bldr.Field(i).(*array.ListBuilder).ValueBuilder().(*types.MacBuilder).Append(mac)
248+
bldr.Field(i).(*array.ListBuilder).ValueBuilder().(*types.MACBuilder).Append(mac)
249249
} else {
250250
panic("unknown type: " + c.Type.String() + " column: " + c.Name)
251251
}

types/extensions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import "github.com/apache/arrow/go/v13/arrow"
55
var ExtensionTypes = struct {
66
UUID arrow.ExtensionType
77
Inet arrow.ExtensionType
8-
Mac arrow.ExtensionType
8+
MAC arrow.ExtensionType
99
JSON arrow.ExtensionType
1010
}{
1111
UUID: NewUUIDType(),
1212
Inet: NewInetType(),
13-
Mac: NewMacType(),
13+
MAC: NewMACType(),
1414
JSON: NewJSONType(),
1515
}

types/extensions_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ func TestValueStrRoundTrip(t *testing.T) {
5353
},
5454
{
5555
arr: func() arrow.Array {
56-
b := NewMacBuilder(array.NewExtensionBuilder(mem, NewMacType()))
56+
b := NewMACBuilder(array.NewExtensionBuilder(mem, NewMACType()))
5757
defer b.Release()
5858

5959
b.AppendNull()
60-
b.Append(mustParseMac("00:00:00:00:00:01"))
60+
b.Append(mustParseMAC("00:00:00:00:00:01"))
6161
b.AppendNull()
62-
b.Append(mustParseMac("00:00:00:00:00:02"))
62+
b.Append(mustParseMAC("00:00:00:00:00:02"))
6363
b.AppendNull()
6464

65-
return b.NewMacArray()
65+
return b.NewMACArray()
6666
}(),
67-
builder: NewMacBuilder(array.NewExtensionBuilder(mem, NewMacType())),
67+
builder: NewMACBuilder(array.NewExtensionBuilder(mem, NewMACType())),
6868
},
6969
{
7070
arr: func() arrow.Array {

types/mac.go

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ import (
1212
"github.com/goccy/go-json"
1313
)
1414

15-
type MacBuilder struct {
15+
type MACBuilder struct {
1616
*array.ExtensionBuilder
1717
}
1818

19-
func NewMacBuilder(builder *array.ExtensionBuilder) *MacBuilder {
20-
return &MacBuilder{ExtensionBuilder: builder}
19+
func NewMACBuilder(builder *array.ExtensionBuilder) *MACBuilder {
20+
return &MACBuilder{ExtensionBuilder: builder}
2121
}
2222

23-
func (b *MacBuilder) Append(v net.HardwareAddr) {
23+
func (b *MACBuilder) Append(v net.HardwareAddr) {
2424
b.ExtensionBuilder.Builder.(*array.BinaryBuilder).Append(v[:])
2525
}
2626

27-
func (b *MacBuilder) UnsafeAppend(v net.HardwareAddr) {
27+
func (b *MACBuilder) UnsafeAppend(v net.HardwareAddr) {
2828
b.ExtensionBuilder.Builder.(*array.BinaryBuilder).UnsafeAppend(v[:])
2929
}
3030

31-
func (b *MacBuilder) AppendValues(v []net.HardwareAddr, valid []bool) {
31+
func (b *MACBuilder) AppendValues(v []net.HardwareAddr, valid []bool) {
3232
if len(v) != len(valid) && len(valid) != 0 {
3333
panic("len(v) != len(valid) && len(valid) != 0")
3434
}
@@ -43,7 +43,7 @@ func (b *MacBuilder) AppendValues(v []net.HardwareAddr, valid []bool) {
4343
b.ExtensionBuilder.Builder.(*array.BinaryBuilder).AppendValues(data, valid)
4444
}
4545

46-
func (b *MacBuilder) AppendValueFromString(s string) error {
46+
func (b *MACBuilder) AppendValueFromString(s string) error {
4747
if s == array.NullValueStr {
4848
b.AppendNull()
4949
return nil
@@ -56,7 +56,7 @@ func (b *MacBuilder) AppendValueFromString(s string) error {
5656
return nil
5757
}
5858

59-
func (b *MacBuilder) UnmarshalOne(dec *json.Decoder) error {
59+
func (b *MACBuilder) UnmarshalOne(dec *json.Decoder) error {
6060
t, err := dec.Token()
6161
if err != nil {
6262
return err
@@ -88,7 +88,7 @@ func (b *MacBuilder) UnmarshalOne(dec *json.Decoder) error {
8888
return nil
8989
}
9090

91-
func (b *MacBuilder) Unmarshal(dec *json.Decoder) error {
91+
func (b *MACBuilder) Unmarshal(dec *json.Decoder) error {
9292
for dec.More() {
9393
if err := b.UnmarshalOne(dec); err != nil {
9494
return err
@@ -97,7 +97,7 @@ func (b *MacBuilder) Unmarshal(dec *json.Decoder) error {
9797
return nil
9898
}
9999

100-
func (b *MacBuilder) UnmarshalJSON(data []byte) error {
100+
func (b *MACBuilder) UnmarshalJSON(data []byte) error {
101101
dec := json.NewDecoder(bytes.NewReader(data))
102102
t, err := dec.Token()
103103
if err != nil {
@@ -111,16 +111,16 @@ func (b *MacBuilder) UnmarshalJSON(data []byte) error {
111111
return b.Unmarshal(dec)
112112
}
113113

114-
func (b *MacBuilder) NewMacArray() *MacArray {
115-
return b.NewExtensionArray().(*MacArray)
114+
func (b *MACBuilder) NewMACArray() *MACArray {
115+
return b.NewExtensionArray().(*MACArray)
116116
}
117117

118-
// MacArray is a simple array which is a wrapper around a BinaryArray
119-
type MacArray struct {
118+
// MACArray is a simple array which is a wrapper around a BinaryArray
119+
type MACArray struct {
120120
array.ExtensionArrayBase
121121
}
122122

123-
func (a *MacArray) String() string {
123+
func (a *MACArray) String() string {
124124
arr := a.Storage().(*array.Binary)
125125
o := new(strings.Builder)
126126
o.WriteString("[")
@@ -139,14 +139,14 @@ func (a *MacArray) String() string {
139139
return o.String()
140140
}
141141

142-
func (a *MacArray) Value(i int) net.HardwareAddr {
142+
func (a *MACArray) Value(i int) net.HardwareAddr {
143143
if a.IsNull(i) {
144144
return nil
145145
}
146146
return net.HardwareAddr(a.Storage().(*array.Binary).Value(i))
147147
}
148148

149-
func (a *MacArray) ValueStr(i int) string {
149+
func (a *MACArray) ValueStr(i int) string {
150150
switch {
151151
case a.IsNull(i):
152152
return array.NullValueStr
@@ -155,7 +155,7 @@ func (a *MacArray) ValueStr(i int) string {
155155
}
156156
}
157157

158-
func (a *MacArray) MarshalJSON() ([]byte, error) {
158+
func (a *MACArray) MarshalJSON() ([]byte, error) {
159159
arr := a.Storage().(*array.Binary)
160160
values := make([]any, a.Len())
161161
for i := 0; i < a.Len(); i++ {
@@ -168,57 +168,57 @@ func (a *MacArray) MarshalJSON() ([]byte, error) {
168168
return json.Marshal(values)
169169
}
170170

171-
func (a *MacArray) GetOneForMarshal(i int) any {
171+
func (a *MACArray) GetOneForMarshal(i int) any {
172172
arr := a.Storage().(*array.Binary)
173173
if a.IsValid(i) {
174174
return net.HardwareAddr(arr.Value(i)).String()
175175
}
176176
return nil
177177
}
178178

179-
// MacType is a simple extension type that represents a BinaryType
180-
// to be used for representing mac addresses.
181-
type MacType struct {
179+
// MACType is a simple extension type that represents a BinaryType
180+
// to be used for representing MAC addresses.
181+
type MACType struct {
182182
arrow.ExtensionBase
183183
}
184184

185-
// NewMacType is a convenience function to create an instance of MacType
185+
// NewMACType is a convenience function to create an instance of MACType
186186
// with the correct storage type
187-
func NewMacType() *MacType {
188-
return &MacType{ExtensionBase: arrow.ExtensionBase{Storage: &arrow.BinaryType{}}}
187+
func NewMACType() *MACType {
188+
return &MACType{ExtensionBase: arrow.ExtensionBase{Storage: &arrow.BinaryType{}}}
189189
}
190190

191-
// ArrayType returns TypeOf(MacArray{}) for constructing MAC arrays
192-
func (*MacType) ArrayType() reflect.Type {
193-
return reflect.TypeOf(MacArray{})
191+
// ArrayType returns TypeOf(MACArray{}) for constructing MAC arrays
192+
func (*MACType) ArrayType() reflect.Type {
193+
return reflect.TypeOf(MACArray{})
194194
}
195195

196-
func (*MacType) ExtensionName() string {
196+
func (*MACType) ExtensionName() string {
197197
return "mac"
198198
}
199199

200-
// Serialize returns "mac-serialized" for testing proper metadata passing
201-
func (*MacType) Serialize() string {
200+
// Serialize returns "MAC-serialized" for testing proper metadata passing
201+
func (*MACType) Serialize() string {
202202
return "mac-serialized"
203203
}
204204

205205
// Deserialize expects storageType to be FixedSizeBinaryType{ByteWidth: 16} and the data to be
206-
// "mac-serialized" in order to correctly create a MacType for testing deserialize.
207-
func (*MacType) Deserialize(storageType arrow.DataType, data string) (arrow.ExtensionType, error) {
206+
// "MAC-serialized" in order to correctly create a MACType for testing deserialize.
207+
func (*MACType) Deserialize(storageType arrow.DataType, data string) (arrow.ExtensionType, error) {
208208
if data != "mac-serialized" {
209209
return nil, fmt.Errorf("type identifier did not match: '%s'", data)
210210
}
211211
if !arrow.TypeEqual(storageType, &arrow.BinaryType{}) {
212-
return nil, fmt.Errorf("invalid storage type for MacType: %s", storageType.Name())
212+
return nil, fmt.Errorf("invalid storage type for MACType: %s", storageType.Name())
213213
}
214214
return NewInetType(), nil
215215
}
216216

217217
// ExtensionEquals returns true if both extensions have the same name
218-
func (u *MacType) ExtensionEquals(other arrow.ExtensionType) bool {
218+
func (u *MACType) ExtensionEquals(other arrow.ExtensionType) bool {
219219
return u.ExtensionName() == other.ExtensionName()
220220
}
221221

222-
func (*MacType) NewBuilder(bldr *array.ExtensionBuilder) array.Builder {
223-
return NewMacBuilder(bldr)
222+
func (*MACType) NewBuilder(bldr *array.ExtensionBuilder) array.Builder {
223+
return NewMACBuilder(bldr)
224224
}

types/mac_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@ import (
99
"github.com/stretchr/testify/require"
1010
)
1111

12-
func mustParseMac(s string) net.HardwareAddr {
12+
func mustParseMAC(s string) net.HardwareAddr {
1313
mac, err := net.ParseMAC(s)
1414
if err != nil {
1515
panic(err)
1616
}
1717
return mac
1818
}
1919

20-
func TestMacBuilder(t *testing.T) {
20+
func TestMACBuilder(t *testing.T) {
2121
mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
2222
defer mem.AssertSize(t, 0)
2323

24-
b := NewMacBuilder(array.NewExtensionBuilder(mem, NewMacType()))
24+
b := NewMACBuilder(array.NewExtensionBuilder(mem, NewMACType()))
2525

26-
b.Append(mustParseMac("00:00:00:00:00:01"))
26+
b.Append(mustParseMAC("00:00:00:00:00:01"))
2727
b.AppendNull()
28-
b.Append(mustParseMac("00:00:00:00:00:02"))
28+
b.Append(mustParseMAC("00:00:00:00:00:02"))
2929
b.AppendNull()
3030

3131
require.Equal(t, 4, b.Len(), "unexpected Len()")
3232
require.Equal(t, 2, b.NullN(), "unexpected NullN()")
3333

3434
values := []net.HardwareAddr{
35-
mustParseMac("00:00:00:00:00:03"),
36-
mustParseMac("00:00:00:00:00:04"),
35+
mustParseMAC("00:00:00:00:00:03"),
36+
mustParseMAC("00:00:00:00:00:04"),
3737
}
3838
b.AppendValues(values, nil)
3939

@@ -53,7 +53,7 @@ func TestMacBuilder(t *testing.T) {
5353
b.Release()
5454
a.Release()
5555

56-
b = NewMacBuilder(array.NewExtensionBuilder(mem, NewMacType()))
56+
b = NewMACBuilder(array.NewExtensionBuilder(mem, NewMACType()))
5757
err = b.UnmarshalJSON(st)
5858
require.NoError(t, err)
5959

0 commit comments

Comments
 (0)