From 33b529b00ed2be59716811ad57b509418b7566b4 Mon Sep 17 00:00:00 2001 From: candiduslynx Date: Mon, 15 May 2023 12:12:58 +0300 Subject: [PATCH] rename Mac -> MAC --- .../servers/destination/v0/schemav2tov3.go | 10 +-- schema/testdata.go | 14 ++-- types/extensions.go | 4 +- types/extensions_test.go | 10 +-- types/mac.go | 74 +++++++++---------- types/mac_test.go | 16 ++-- 6 files changed, 64 insertions(+), 64 deletions(-) diff --git a/internal/servers/destination/v0/schemav2tov3.go b/internal/servers/destination/v0/schemav2tov3.go index 44add268d2..087e4d20eb 100644 --- a/internal/servers/destination/v0/schemav2tov3.go +++ b/internal/servers/destination/v0/schemav2tov3.go @@ -91,9 +91,9 @@ func TypeV2ToV3(dataType schemav2.ValueType) arrow.DataType { case schemav2.TypeCIDRArray: return arrow.ListOf(types.ExtensionTypes.Inet) case schemav2.TypeMacAddr: - return types.ExtensionTypes.Mac + return types.ExtensionTypes.MAC case schemav2.TypeMacAddrArray: - return arrow.ListOf(types.ExtensionTypes.Mac) + return arrow.ListOf(types.ExtensionTypes.MAC) default: panic("unknown type " + typ.Name()) } @@ -227,16 +227,16 @@ func CQTypesToRecord(mem memory.Allocator, c []schemav2.CQTypes, arrowSchema *ar } case schemav2.TypeMacAddr: if c[j][i].(*schemav2.Macaddr).Status == schemav2.Present { - bldr.Field(i).(*types.MacBuilder).Append(c[j][i].(*schemav2.Macaddr).Addr) + bldr.Field(i).(*types.MACBuilder).Append(c[j][i].(*schemav2.Macaddr).Addr) } else { - bldr.Field(i).(*types.MacBuilder).AppendNull() + bldr.Field(i).(*types.MACBuilder).AppendNull() } case schemav2.TypeMacAddrArray: if c[j][i].(*schemav2.MacaddrArray).Status == schemav2.Present { listBldr := bldr.Field(i).(*array.ListBuilder) listBldr.Append(true) for _, e := range c[j][i].(*schemav2.MacaddrArray).Elements { - listBldr.ValueBuilder().(*types.MacBuilder).Append(e.Addr) + listBldr.ValueBuilder().(*types.MACBuilder).Append(e.Addr) } } else { bldr.Field(i).(*array.ListBuilder).AppendNull() diff --git a/schema/testdata.go b/schema/testdata.go index a9bd7b48b9..d40cd74cd3 100644 --- a/schema/testdata.go +++ b/schema/testdata.go @@ -100,11 +100,11 @@ func TestSourceTable(name string) *Table { }, { Name: "macaddr", - Type: types.ExtensionTypes.Mac, + Type: types.ExtensionTypes.MAC, }, { Name: "macaddr_array", - Type: arrow.ListOf(types.ExtensionTypes.Mac), + Type: arrow.ListOf(types.ExtensionTypes.MAC), }, }, } @@ -228,24 +228,24 @@ func GenTestData(table *Table, opts GenTestDataOptions) []arrow.Record { panic(err) } bldr.Field(i).(*array.ListBuilder).ValueBuilder().(*types.InetBuilder).Append(ipnet) - } else if arrow.TypeEqual(c.Type, types.ExtensionTypes.Mac) { + } else if arrow.TypeEqual(c.Type, types.ExtensionTypes.MAC) { mac, err := net.ParseMAC("aa:bb:cc:dd:ee:ff") if err != nil { panic(err) } - bldr.Field(i).(*types.MacBuilder).Append(mac) - } else if arrow.TypeEqual(c.Type, arrow.ListOf(types.ExtensionTypes.Mac)) { + bldr.Field(i).(*types.MACBuilder).Append(mac) + } else if arrow.TypeEqual(c.Type, arrow.ListOf(types.ExtensionTypes.MAC)) { mac, err := net.ParseMAC("aa:bb:cc:dd:ee:ff") if err != nil { panic(err) } bldr.Field(i).(*array.ListBuilder).Append(true) - bldr.Field(i).(*array.ListBuilder).ValueBuilder().(*types.MacBuilder).Append(mac) + bldr.Field(i).(*array.ListBuilder).ValueBuilder().(*types.MACBuilder).Append(mac) mac, err = net.ParseMAC("11:22:33:44:55:66") if err != nil { panic(err) } - bldr.Field(i).(*array.ListBuilder).ValueBuilder().(*types.MacBuilder).Append(mac) + bldr.Field(i).(*array.ListBuilder).ValueBuilder().(*types.MACBuilder).Append(mac) } else { panic("unknown type: " + c.Type.String() + " column: " + c.Name) } diff --git a/types/extensions.go b/types/extensions.go index f7e01d38f8..9f30f1c705 100644 --- a/types/extensions.go +++ b/types/extensions.go @@ -5,11 +5,11 @@ import "github.com/apache/arrow/go/v13/arrow" var ExtensionTypes = struct { UUID arrow.ExtensionType Inet arrow.ExtensionType - Mac arrow.ExtensionType + MAC arrow.ExtensionType JSON arrow.ExtensionType }{ UUID: NewUUIDType(), Inet: NewInetType(), - Mac: NewMacType(), + MAC: NewMACType(), JSON: NewJSONType(), } diff --git a/types/extensions_test.go b/types/extensions_test.go index a090f42afa..ff0c4393b8 100644 --- a/types/extensions_test.go +++ b/types/extensions_test.go @@ -53,18 +53,18 @@ func TestValueStrRoundTrip(t *testing.T) { }, { arr: func() arrow.Array { - b := NewMacBuilder(array.NewExtensionBuilder(mem, NewMacType())) + b := NewMACBuilder(array.NewExtensionBuilder(mem, NewMACType())) defer b.Release() b.AppendNull() - b.Append(mustParseMac("00:00:00:00:00:01")) + b.Append(mustParseMAC("00:00:00:00:00:01")) b.AppendNull() - b.Append(mustParseMac("00:00:00:00:00:02")) + b.Append(mustParseMAC("00:00:00:00:00:02")) b.AppendNull() - return b.NewMacArray() + return b.NewMACArray() }(), - builder: NewMacBuilder(array.NewExtensionBuilder(mem, NewMacType())), + builder: NewMACBuilder(array.NewExtensionBuilder(mem, NewMACType())), }, { arr: func() arrow.Array { diff --git a/types/mac.go b/types/mac.go index cb6409e51d..b02a4e8861 100644 --- a/types/mac.go +++ b/types/mac.go @@ -12,23 +12,23 @@ import ( "github.com/goccy/go-json" ) -type MacBuilder struct { +type MACBuilder struct { *array.ExtensionBuilder } -func NewMacBuilder(builder *array.ExtensionBuilder) *MacBuilder { - return &MacBuilder{ExtensionBuilder: builder} +func NewMACBuilder(builder *array.ExtensionBuilder) *MACBuilder { + return &MACBuilder{ExtensionBuilder: builder} } -func (b *MacBuilder) Append(v net.HardwareAddr) { +func (b *MACBuilder) Append(v net.HardwareAddr) { b.ExtensionBuilder.Builder.(*array.BinaryBuilder).Append(v[:]) } -func (b *MacBuilder) UnsafeAppend(v net.HardwareAddr) { +func (b *MACBuilder) UnsafeAppend(v net.HardwareAddr) { b.ExtensionBuilder.Builder.(*array.BinaryBuilder).UnsafeAppend(v[:]) } -func (b *MacBuilder) AppendValues(v []net.HardwareAddr, valid []bool) { +func (b *MACBuilder) AppendValues(v []net.HardwareAddr, valid []bool) { if len(v) != len(valid) && len(valid) != 0 { panic("len(v) != len(valid) && len(valid) != 0") } @@ -43,7 +43,7 @@ func (b *MacBuilder) AppendValues(v []net.HardwareAddr, valid []bool) { b.ExtensionBuilder.Builder.(*array.BinaryBuilder).AppendValues(data, valid) } -func (b *MacBuilder) AppendValueFromString(s string) error { +func (b *MACBuilder) AppendValueFromString(s string) error { if s == array.NullValueStr { b.AppendNull() return nil @@ -56,7 +56,7 @@ func (b *MacBuilder) AppendValueFromString(s string) error { return nil } -func (b *MacBuilder) UnmarshalOne(dec *json.Decoder) error { +func (b *MACBuilder) UnmarshalOne(dec *json.Decoder) error { t, err := dec.Token() if err != nil { return err @@ -88,7 +88,7 @@ func (b *MacBuilder) UnmarshalOne(dec *json.Decoder) error { return nil } -func (b *MacBuilder) Unmarshal(dec *json.Decoder) error { +func (b *MACBuilder) Unmarshal(dec *json.Decoder) error { for dec.More() { if err := b.UnmarshalOne(dec); err != nil { return err @@ -97,7 +97,7 @@ func (b *MacBuilder) Unmarshal(dec *json.Decoder) error { return nil } -func (b *MacBuilder) UnmarshalJSON(data []byte) error { +func (b *MACBuilder) UnmarshalJSON(data []byte) error { dec := json.NewDecoder(bytes.NewReader(data)) t, err := dec.Token() if err != nil { @@ -111,16 +111,16 @@ func (b *MacBuilder) UnmarshalJSON(data []byte) error { return b.Unmarshal(dec) } -func (b *MacBuilder) NewMacArray() *MacArray { - return b.NewExtensionArray().(*MacArray) +func (b *MACBuilder) NewMACArray() *MACArray { + return b.NewExtensionArray().(*MACArray) } -// MacArray is a simple array which is a wrapper around a BinaryArray -type MacArray struct { +// MACArray is a simple array which is a wrapper around a BinaryArray +type MACArray struct { array.ExtensionArrayBase } -func (a *MacArray) String() string { +func (a *MACArray) String() string { arr := a.Storage().(*array.Binary) o := new(strings.Builder) o.WriteString("[") @@ -139,14 +139,14 @@ func (a *MacArray) String() string { return o.String() } -func (a *MacArray) Value(i int) net.HardwareAddr { +func (a *MACArray) Value(i int) net.HardwareAddr { if a.IsNull(i) { return nil } return net.HardwareAddr(a.Storage().(*array.Binary).Value(i)) } -func (a *MacArray) ValueStr(i int) string { +func (a *MACArray) ValueStr(i int) string { switch { case a.IsNull(i): return array.NullValueStr @@ -155,7 +155,7 @@ func (a *MacArray) ValueStr(i int) string { } } -func (a *MacArray) MarshalJSON() ([]byte, error) { +func (a *MACArray) MarshalJSON() ([]byte, error) { arr := a.Storage().(*array.Binary) values := make([]any, a.Len()) for i := 0; i < a.Len(); i++ { @@ -168,7 +168,7 @@ func (a *MacArray) MarshalJSON() ([]byte, error) { return json.Marshal(values) } -func (a *MacArray) GetOneForMarshal(i int) any { +func (a *MACArray) GetOneForMarshal(i int) any { arr := a.Storage().(*array.Binary) if a.IsValid(i) { return net.HardwareAddr(arr.Value(i)).String() @@ -176,49 +176,49 @@ func (a *MacArray) GetOneForMarshal(i int) any { return nil } -// MacType is a simple extension type that represents a BinaryType -// to be used for representing mac addresses. -type MacType struct { +// MACType is a simple extension type that represents a BinaryType +// to be used for representing MAC addresses. +type MACType struct { arrow.ExtensionBase } -// NewMacType is a convenience function to create an instance of MacType +// NewMACType is a convenience function to create an instance of MACType // with the correct storage type -func NewMacType() *MacType { - return &MacType{ExtensionBase: arrow.ExtensionBase{Storage: &arrow.BinaryType{}}} +func NewMACType() *MACType { + return &MACType{ExtensionBase: arrow.ExtensionBase{Storage: &arrow.BinaryType{}}} } -// ArrayType returns TypeOf(MacArray{}) for constructing MAC arrays -func (*MacType) ArrayType() reflect.Type { - return reflect.TypeOf(MacArray{}) +// ArrayType returns TypeOf(MACArray{}) for constructing MAC arrays +func (*MACType) ArrayType() reflect.Type { + return reflect.TypeOf(MACArray{}) } -func (*MacType) ExtensionName() string { +func (*MACType) ExtensionName() string { return "mac" } -// Serialize returns "mac-serialized" for testing proper metadata passing -func (*MacType) Serialize() string { +// Serialize returns "MAC-serialized" for testing proper metadata passing +func (*MACType) Serialize() string { return "mac-serialized" } // Deserialize expects storageType to be FixedSizeBinaryType{ByteWidth: 16} and the data to be -// "mac-serialized" in order to correctly create a MacType for testing deserialize. -func (*MacType) Deserialize(storageType arrow.DataType, data string) (arrow.ExtensionType, error) { +// "MAC-serialized" in order to correctly create a MACType for testing deserialize. +func (*MACType) Deserialize(storageType arrow.DataType, data string) (arrow.ExtensionType, error) { if data != "mac-serialized" { return nil, fmt.Errorf("type identifier did not match: '%s'", data) } if !arrow.TypeEqual(storageType, &arrow.BinaryType{}) { - return nil, fmt.Errorf("invalid storage type for MacType: %s", storageType.Name()) + return nil, fmt.Errorf("invalid storage type for MACType: %s", storageType.Name()) } return NewInetType(), nil } // ExtensionEquals returns true if both extensions have the same name -func (u *MacType) ExtensionEquals(other arrow.ExtensionType) bool { +func (u *MACType) ExtensionEquals(other arrow.ExtensionType) bool { return u.ExtensionName() == other.ExtensionName() } -func (*MacType) NewBuilder(bldr *array.ExtensionBuilder) array.Builder { - return NewMacBuilder(bldr) +func (*MACType) NewBuilder(bldr *array.ExtensionBuilder) array.Builder { + return NewMACBuilder(bldr) } diff --git a/types/mac_test.go b/types/mac_test.go index 9557e6d855..cdac9f22ad 100644 --- a/types/mac_test.go +++ b/types/mac_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" ) -func mustParseMac(s string) net.HardwareAddr { +func mustParseMAC(s string) net.HardwareAddr { mac, err := net.ParseMAC(s) if err != nil { panic(err) @@ -17,23 +17,23 @@ func mustParseMac(s string) net.HardwareAddr { return mac } -func TestMacBuilder(t *testing.T) { +func TestMACBuilder(t *testing.T) { mem := memory.NewCheckedAllocator(memory.NewGoAllocator()) defer mem.AssertSize(t, 0) - b := NewMacBuilder(array.NewExtensionBuilder(mem, NewMacType())) + b := NewMACBuilder(array.NewExtensionBuilder(mem, NewMACType())) - b.Append(mustParseMac("00:00:00:00:00:01")) + b.Append(mustParseMAC("00:00:00:00:00:01")) b.AppendNull() - b.Append(mustParseMac("00:00:00:00:00:02")) + b.Append(mustParseMAC("00:00:00:00:00:02")) b.AppendNull() require.Equal(t, 4, b.Len(), "unexpected Len()") require.Equal(t, 2, b.NullN(), "unexpected NullN()") values := []net.HardwareAddr{ - mustParseMac("00:00:00:00:00:03"), - mustParseMac("00:00:00:00:00:04"), + mustParseMAC("00:00:00:00:00:03"), + mustParseMAC("00:00:00:00:00:04"), } b.AppendValues(values, nil) @@ -53,7 +53,7 @@ func TestMacBuilder(t *testing.T) { b.Release() a.Release() - b = NewMacBuilder(array.NewExtensionBuilder(mem, NewMacType())) + b = NewMACBuilder(array.NewExtensionBuilder(mem, NewMACType())) err = b.UnmarshalJSON(st) require.NoError(t, err)