Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions internal/servers/destination/v0/schemav2tov3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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()
Expand Down
14 changes: 7 additions & 7 deletions schema/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
},
}
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions types/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
10 changes: 5 additions & 5 deletions types/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
74 changes: 37 additions & 37 deletions types/mac.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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("[")
Expand All @@ -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
Expand All @@ -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++ {
Expand All @@ -168,57 +168,57 @@ 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()
}
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)
}
16 changes: 8 additions & 8 deletions types/mac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ 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)
}
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)

Expand All @@ -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)

Expand Down