zeroshade commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619899454



##########
File path: go/arrow/array/map.go
##########
@@ -0,0 +1,231 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package array // import "github.com/apache/arrow/go/arrow/array"
+
+import (
+       "github.com/apache/arrow/go/arrow"
+       "github.com/apache/arrow/go/arrow/memory"
+)
+
+// Map represents an immutable sequence of Key/Value structs. It is a
+// logical type that is implemented as a List<Struct: key, value>.
+type Map struct {
+       *List
+       keys, items Interface
+}
+
+// NewMapData returns a new Map array value, from data
+func NewMapData(data *Data) *Map {
+       a := &Map{List: &List{}}
+       a.refCount = 1
+       a.setData(data)
+       return a
+}
+
+// KeysSorted checks the datatype that was used to construct this array and
+// returns the KeysSorted boolean value used to denote if the key array is
+// sorted for each list element.

Review comment:
       added comments expanding on the keysorted lack of semantics

##########
File path: go/arrow/array/map.go
##########
@@ -0,0 +1,231 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package array // import "github.com/apache/arrow/go/arrow/array"
+
+import (
+       "github.com/apache/arrow/go/arrow"
+       "github.com/apache/arrow/go/arrow/memory"
+)
+
+// Map represents an immutable sequence of Key/Value structs. It is a
+// logical type that is implemented as a List<Struct: key, value>.
+type Map struct {
+       *List
+       keys, items Interface
+}
+
+// NewMapData returns a new Map array value, from data
+func NewMapData(data *Data) *Map {
+       a := &Map{List: &List{}}
+       a.refCount = 1
+       a.setData(data)
+       return a
+}
+
+// KeysSorted checks the datatype that was used to construct this array and
+// returns the KeysSorted boolean value used to denote if the key array is
+// sorted for each list element.
+func (a *Map) KeysSorted() bool { return 
a.DataType().(*arrow.MapType).KeysSorted }
+
+func (a *Map) validateData(data *Data) {
+       if len(data.childData) != 1 || data.childData[0] == nil {
+               panic("arrow/array: expected one child array for map array")
+       }
+
+       if data.childData[0].dtype.ID() != arrow.STRUCT {
+               panic("arrow/array: map array child should be struct type")
+       }
+
+       if data.childData[0].NullN() != 0 {
+               panic("arrow/array: map array child array should have no nulls")
+       }
+
+       if len(data.childData[0].childData) != 2 {
+               panic("arrow/array: map array child array should have two 
fields")
+       }
+
+       if data.childData[0].childData[0].NullN() != 0 {
+               panic("arrow/array: map array keys array should have no nulls")
+       }
+}
+
+func (a *Map) setData(data *Data) {
+       a.validateData(data)
+
+       a.List.setData(data)
+       a.keys = MakeFromData(data.childData[0].childData[0])
+       a.items = MakeFromData(data.childData[0].childData[1])
+}
+
+// Keys returns the full Array of Key values, equivalent to grabbing
+// the key field of the child struct.
+func (a *Map) Keys() Interface { return a.keys }
+
+// Items returns the full Array of Item values, equivalent to grabbing
+// the Value field (the second field) of the child struct.
+func (a *Map) Items() Interface { return a.items }
+
+func (a *Map) Retain() {

Review comment:
       added

##########
File path: go/arrow/array/map.go
##########
@@ -0,0 +1,231 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package array // import "github.com/apache/arrow/go/arrow/array"
+
+import (
+       "github.com/apache/arrow/go/arrow"
+       "github.com/apache/arrow/go/arrow/memory"
+)
+
+// Map represents an immutable sequence of Key/Value structs. It is a
+// logical type that is implemented as a List<Struct: key, value>.
+type Map struct {
+       *List
+       keys, items Interface
+}
+
+// NewMapData returns a new Map array value, from data
+func NewMapData(data *Data) *Map {
+       a := &Map{List: &List{}}
+       a.refCount = 1
+       a.setData(data)
+       return a
+}
+
+// KeysSorted checks the datatype that was used to construct this array and
+// returns the KeysSorted boolean value used to denote if the key array is
+// sorted for each list element.
+func (a *Map) KeysSorted() bool { return 
a.DataType().(*arrow.MapType).KeysSorted }
+
+func (a *Map) validateData(data *Data) {
+       if len(data.childData) != 1 || data.childData[0] == nil {
+               panic("arrow/array: expected one child array for map array")
+       }
+
+       if data.childData[0].dtype.ID() != arrow.STRUCT {
+               panic("arrow/array: map array child should be struct type")
+       }
+
+       if data.childData[0].NullN() != 0 {
+               panic("arrow/array: map array child array should have no nulls")
+       }
+
+       if len(data.childData[0].childData) != 2 {
+               panic("arrow/array: map array child array should have two 
fields")
+       }
+
+       if data.childData[0].childData[0].NullN() != 0 {
+               panic("arrow/array: map array keys array should have no nulls")
+       }
+}
+
+func (a *Map) setData(data *Data) {
+       a.validateData(data)
+
+       a.List.setData(data)
+       a.keys = MakeFromData(data.childData[0].childData[0])
+       a.items = MakeFromData(data.childData[0].childData[1])
+}
+
+// Keys returns the full Array of Key values, equivalent to grabbing
+// the key field of the child struct.
+func (a *Map) Keys() Interface { return a.keys }
+
+// Items returns the full Array of Item values, equivalent to grabbing
+// the Value field (the second field) of the child struct.
+func (a *Map) Items() Interface { return a.items }
+
+func (a *Map) Retain() {
+       a.List.Retain()
+       a.keys.Retain()
+       a.items.Retain()
+}
+
+func (a *Map) Release() {
+       a.List.Release()
+       a.keys.Release()
+       a.items.Release()
+}
+
+func arrayEqualMap(left, right *Map) bool {
+       // since Map is implemented using a list, we can just use arrayEqualList
+       return arrayEqualList(left.List, right.List)
+}
+
+type MapBuilder struct {
+       listBuilder *ListBuilder
+
+       etype                   arrow.DataType
+       keytype, itemtype       arrow.DataType
+       keyBuilder, itemBuilder Builder
+       keysSorted              bool
+}
+
+// NewMapBuilder returns a builder, using the provided memory allocator.
+// The created Map builder will create a map array whose keys will be a 
non-nullable
+// array of type `keytype` and whose mapped items will be a nullable array of 
itemtype.
+func NewMapBuilder(mem memory.Allocator, keytype, itemtype arrow.DataType, 
keysSorted bool) *MapBuilder {

Review comment:
       done.

##########
File path: go/arrow/array/map.go
##########
@@ -0,0 +1,231 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package array // import "github.com/apache/arrow/go/arrow/array"
+
+import (
+       "github.com/apache/arrow/go/arrow"
+       "github.com/apache/arrow/go/arrow/memory"
+)
+
+// Map represents an immutable sequence of Key/Value structs. It is a
+// logical type that is implemented as a List<Struct: key, value>.
+type Map struct {
+       *List
+       keys, items Interface
+}
+
+// NewMapData returns a new Map array value, from data
+func NewMapData(data *Data) *Map {
+       a := &Map{List: &List{}}
+       a.refCount = 1
+       a.setData(data)
+       return a
+}
+
+// KeysSorted checks the datatype that was used to construct this array and
+// returns the KeysSorted boolean value used to denote if the key array is
+// sorted for each list element.
+func (a *Map) KeysSorted() bool { return 
a.DataType().(*arrow.MapType).KeysSorted }
+
+func (a *Map) validateData(data *Data) {
+       if len(data.childData) != 1 || data.childData[0] == nil {
+               panic("arrow/array: expected one child array for map array")
+       }
+
+       if data.childData[0].dtype.ID() != arrow.STRUCT {
+               panic("arrow/array: map array child should be struct type")
+       }
+
+       if data.childData[0].NullN() != 0 {
+               panic("arrow/array: map array child array should have no nulls")
+       }
+
+       if len(data.childData[0].childData) != 2 {
+               panic("arrow/array: map array child array should have two 
fields")
+       }
+
+       if data.childData[0].childData[0].NullN() != 0 {
+               panic("arrow/array: map array keys array should have no nulls")
+       }
+}
+
+func (a *Map) setData(data *Data) {
+       a.validateData(data)
+
+       a.List.setData(data)
+       a.keys = MakeFromData(data.childData[0].childData[0])
+       a.items = MakeFromData(data.childData[0].childData[1])
+}
+
+// Keys returns the full Array of Key values, equivalent to grabbing
+// the key field of the child struct.
+func (a *Map) Keys() Interface { return a.keys }
+
+// Items returns the full Array of Item values, equivalent to grabbing
+// the Value field (the second field) of the child struct.
+func (a *Map) Items() Interface { return a.items }
+
+func (a *Map) Retain() {
+       a.List.Retain()
+       a.keys.Retain()
+       a.items.Retain()
+}
+
+func (a *Map) Release() {
+       a.List.Release()
+       a.keys.Release()
+       a.items.Release()
+}
+
+func arrayEqualMap(left, right *Map) bool {
+       // since Map is implemented using a list, we can just use arrayEqualList
+       return arrayEqualList(left.List, right.List)
+}
+
+type MapBuilder struct {
+       listBuilder *ListBuilder
+
+       etype                   arrow.DataType
+       keytype, itemtype       arrow.DataType
+       keyBuilder, itemBuilder Builder
+       keysSorted              bool
+}
+
+// NewMapBuilder returns a builder, using the provided memory allocator.
+// The created Map builder will create a map array whose keys will be a 
non-nullable
+// array of type `keytype` and whose mapped items will be a nullable array of 
itemtype.
+func NewMapBuilder(mem memory.Allocator, keytype, itemtype arrow.DataType, 
keysSorted bool) *MapBuilder {
+       etype := arrow.MapOf(keytype, itemtype)
+       etype.KeysSorted = keysSorted
+       listBldr := NewListBuilder(mem, etype.ValueType())
+       keyBldr := listBldr.ValueBuilder().(*StructBuilder).FieldBuilder(0)
+       keyBldr.Retain()
+       itemBldr := listBldr.ValueBuilder().(*StructBuilder).FieldBuilder(1)
+       itemBldr.Retain()
+       return &MapBuilder{
+               listBuilder: listBldr,
+               keyBuilder:  keyBldr,
+               itemBuilder: itemBldr,
+               etype:       etype,
+               keytype:     keytype,
+               itemtype:    itemtype,
+               keysSorted:  keysSorted,
+       }
+}
+
+func (b *MapBuilder) Retain() {

Review comment:
       added

##########
File path: go/arrow/array/map.go
##########
@@ -0,0 +1,231 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package array // import "github.com/apache/arrow/go/arrow/array"
+
+import (
+       "github.com/apache/arrow/go/arrow"
+       "github.com/apache/arrow/go/arrow/memory"
+)
+
+// Map represents an immutable sequence of Key/Value structs. It is a
+// logical type that is implemented as a List<Struct: key, value>.
+type Map struct {
+       *List
+       keys, items Interface
+}
+
+// NewMapData returns a new Map array value, from data
+func NewMapData(data *Data) *Map {
+       a := &Map{List: &List{}}
+       a.refCount = 1
+       a.setData(data)
+       return a
+}
+
+// KeysSorted checks the datatype that was used to construct this array and
+// returns the KeysSorted boolean value used to denote if the key array is
+// sorted for each list element.
+func (a *Map) KeysSorted() bool { return 
a.DataType().(*arrow.MapType).KeysSorted }
+
+func (a *Map) validateData(data *Data) {
+       if len(data.childData) != 1 || data.childData[0] == nil {
+               panic("arrow/array: expected one child array for map array")
+       }
+
+       if data.childData[0].dtype.ID() != arrow.STRUCT {
+               panic("arrow/array: map array child should be struct type")
+       }
+
+       if data.childData[0].NullN() != 0 {
+               panic("arrow/array: map array child array should have no nulls")
+       }
+
+       if len(data.childData[0].childData) != 2 {
+               panic("arrow/array: map array child array should have two 
fields")
+       }
+
+       if data.childData[0].childData[0].NullN() != 0 {
+               panic("arrow/array: map array keys array should have no nulls")
+       }
+}
+
+func (a *Map) setData(data *Data) {
+       a.validateData(data)
+
+       a.List.setData(data)
+       a.keys = MakeFromData(data.childData[0].childData[0])
+       a.items = MakeFromData(data.childData[0].childData[1])
+}
+
+// Keys returns the full Array of Key values, equivalent to grabbing
+// the key field of the child struct.
+func (a *Map) Keys() Interface { return a.keys }
+
+// Items returns the full Array of Item values, equivalent to grabbing
+// the Value field (the second field) of the child struct.
+func (a *Map) Items() Interface { return a.items }
+
+func (a *Map) Retain() {
+       a.List.Retain()
+       a.keys.Retain()
+       a.items.Retain()
+}
+
+func (a *Map) Release() {
+       a.List.Release()
+       a.keys.Release()
+       a.items.Release()
+}
+
+func arrayEqualMap(left, right *Map) bool {
+       // since Map is implemented using a list, we can just use arrayEqualList
+       return arrayEqualList(left.List, right.List)
+}
+
+type MapBuilder struct {
+       listBuilder *ListBuilder
+
+       etype                   arrow.DataType
+       keytype, itemtype       arrow.DataType
+       keyBuilder, itemBuilder Builder
+       keysSorted              bool
+}
+
+// NewMapBuilder returns a builder, using the provided memory allocator.
+// The created Map builder will create a map array whose keys will be a 
non-nullable
+// array of type `keytype` and whose mapped items will be a nullable array of 
itemtype.
+func NewMapBuilder(mem memory.Allocator, keytype, itemtype arrow.DataType, 
keysSorted bool) *MapBuilder {
+       etype := arrow.MapOf(keytype, itemtype)
+       etype.KeysSorted = keysSorted
+       listBldr := NewListBuilder(mem, etype.ValueType())
+       keyBldr := listBldr.ValueBuilder().(*StructBuilder).FieldBuilder(0)
+       keyBldr.Retain()
+       itemBldr := listBldr.ValueBuilder().(*StructBuilder).FieldBuilder(1)
+       itemBldr.Retain()
+       return &MapBuilder{
+               listBuilder: listBldr,
+               keyBuilder:  keyBldr,
+               itemBuilder: itemBldr,
+               etype:       etype,
+               keytype:     keytype,
+               itemtype:    itemtype,
+               keysSorted:  keysSorted,
+       }
+}
+
+func (b *MapBuilder) Retain() {
+       b.listBuilder.Retain()
+       b.keyBuilder.Retain()
+       b.itemBuilder.Retain()
+}
+
+func (b *MapBuilder) Release() {
+       b.listBuilder.Release()
+       b.keyBuilder.Release()
+       b.itemBuilder.Release()
+}
+
+// Len returns the current number of Maps that are in the builder
+func (b *MapBuilder) Len() int { return b.listBuilder.Len() }
+
+func (b *MapBuilder) Cap() int   { return b.listBuilder.Cap() }

Review comment:
       added




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to