You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/04/20 02:25:41 UTC

[GitHub] [arrow] zeroshade opened a new pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

zeroshade opened a new pull request #10106:
URL: https://github.com/apache/arrow/pull/10106


   Took it upon myself to implement the Map Array type for Golang and uncomment the tests appropriately.


-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r621329723



##########
File path: go/arrow/example_test.go
##########
@@ -593,3 +593,66 @@ func Example_table() {
 	// rec[3]["f1-i32"]: [16 17 18 19 20]
 	// rec[3]["f2-f64"]: [16 17 18 19 20]
 }
+
+// This example demonstrates how to create a Map Array.
+// The resulting array should be:

Review comment:
       ahh, very cool.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] WilliamWhispell commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
WilliamWhispell commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r616707015



##########
File path: go/arrow/array/builder.go
##########
@@ -277,6 +277,8 @@ func NewBuilder(mem memory.Allocator, dtype arrow.DataType) Builder {
 	case arrow.UNION:
 	case arrow.DICTIONARY:
 	case arrow.MAP:
+		typ := dtype.(*arrow.MapType)

Review comment:
       ahh thanks




-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619877235



##########
File path: go/arrow/array/array_test.go
##########
@@ -85,10 +85,16 @@ func TestMakeFromData(t *testing.T) {
 		}},
 		{name: "duration", d: &testDataType{arrow.DURATION}},
 
+		{name: "map", d: &testDataType{arrow.MAP}, child: []*array.Data{
+			array.NewData(&testDataType{arrow.STRUCT}, 0, make([]*memory.Buffer, 4), []*array.Data{

Review comment:
       nit: this is probably consistent with other code here, but literal comments like
   
   `/*elementByteWidth=*/4` could make this more readable.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619877679



##########
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:
       docs for Retain and release?




-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r621332442



##########
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.

Review comment:
       thanks, I didn't realize the examples end up on the docs page, I think that is sufficient from now on.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619876807



##########
File path: go/arrow/array/map.go
##########
@@ -0,0 +1,232 @@
+// 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 ahve 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)

Review comment:
       it isn't.  To my knowledge the keySorted doesn't have strong semantics other than to indicate the keys follow some logical ordering.

##########
File path: go/arrow/array/array_test.go
##########
@@ -85,10 +85,16 @@ func TestMakeFromData(t *testing.T) {
 		}},
 		{name: "duration", d: &testDataType{arrow.DURATION}},
 
+		{name: "map", d: &testDataType{arrow.MAP}, child: []*array.Data{
+			array.NewData(&testDataType{arrow.STRUCT}, 0, make([]*memory.Buffer, 4), []*array.Data{

Review comment:
       nit: this is probably consistent with other code here, but literal comments like
   
   `/*elementByteWidth=*/4` could make this more readable.

##########
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:
       nit: might be worth commenting on the somewhat lack of semantics of keySored and linking to the spec.

##########
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:
       docs for Retain and release?

##########
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:
       might be worth noting keysSorted is not enforced here?

##########
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:
       docs for Retain and Release.

##########
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:
       docs for Cap and NullN?

##########
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.

Review comment:
       since Maps are relatively complex to work with, it might pay to give a simple usage example here.

##########
File path: go/arrow/datatype_nested.go
##########
@@ -148,6 +148,40 @@ func (t *StructType) FieldByName(name string) (Field, bool) {
 	return t.fields[i], true
 }
 
+type MapType struct {
+	value      *ListType
+	KeysSorted bool
+}
+
+func MapOf(key, item DataType) *MapType {
+	if key == nil || item == nil {
+		panic("arrow: nil key or item type for MapType")
+	}
+
+	return &MapType{value: ListOf(StructOf(Field{Name: "key", Type: key}, Field{Name: "value", Type: item, Nullable: true}))}

Review comment:
       does StructOf provide a name?

##########
File path: go/arrow/datatype_nested.go
##########
@@ -148,6 +148,40 @@ func (t *StructType) FieldByName(name string) (Field, bool) {
 	return t.fields[i], true
 }
 
+type MapType struct {
+	value      *ListType
+	KeysSorted bool
+}
+
+func MapOf(key, item DataType) *MapType {
+	if key == nil || item == nil {
+		panic("arrow: nil key or item type for MapType")
+	}
+
+	return &MapType{value: ListOf(StructOf(Field{Name: "key", Type: key}, Field{Name: "value", Type: item, Nullable: true}))}

Review comment:
       does "key" and "value" hardcoded here have any implications for reading maps that name this differentlcy.

##########
File path: go/arrow/example_test.go
##########
@@ -593,3 +593,66 @@ func Example_table() {
 	// rec[3]["f1-i32"]: [16 17 18 19 20]
 	// rec[3]["f2-f64"]: [16 17 18 19 20]
 }
+
+// This example demonstrates how to create a Map Array.
+// The resulting array should be:

Review comment:
       should the comment at the end of the method be moved up here?  Maybe provide a reference here instead of documentation of usage I mentioned above.

##########
File path: go/arrow/internal/arrjson/arrjson.go
##########
@@ -52,15 +52,16 @@ type Field struct {
 }
 
 type dataType struct {
-	Name      string `json:"name"`
-	Signed    bool   `json:"isSigned,omitempty"`
-	BitWidth  int    `json:"bitWidth,omitempty"`
-	Precision string `json:"precision,omitempty"`
-	ByteWidth int    `json:"byteWidth,omitempty"`
-	ListSize  int32  `json:"listSize,omitempty"`
-	Unit      string `json:"unit,omitempty"`
-	TimeZone  string `json:"timezone,omitempty"`
-	Scale     int    `json:"scale,omitempty"` // for Decimal128
+	Name       string `json:"name"`

Review comment:
       this is just whitespace adjustment?

##########
File path: go/arrow/internal/arrjson/arrjson_test.go
##########
@@ -3101,4 +3102,640 @@ func makeDurationsWantJSONs() string {
 
 func makeDecimal128sWantJSONs() string {
 	return `` // FIXME(fredgan): implement full decimal128 JSON support
-}
\ No newline at end of file
+}
+
+func makeMapsWantJSONs() string {
+	return `{

Review comment:
       for testing purposes would it make sense to use a shorter example?




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



[GitHub] [arrow] WilliamWhispell commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
WilliamWhispell commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r616629187



##########
File path: go/arrow/array/builder.go
##########
@@ -277,6 +277,8 @@ func NewBuilder(mem memory.Allocator, dtype arrow.DataType) Builder {
 	case arrow.UNION:
 	case arrow.DICTIONARY:
 	case arrow.MAP:
+		typ := dtype.(*arrow.MapType)

Review comment:
       Looks like in this change, you're only adding map support, but here you are changing union and dictionary to use the map builder. I'm not sure in this context the difference between map and dictionary.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] WilliamWhispell commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
WilliamWhispell commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r616639139



##########
File path: go/arrow/array/map_test.go
##########
@@ -0,0 +1,151 @@
+// 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_test
+
+import (
+	"testing"
+
+	"github.com/apache/arrow/go/arrow"
+	"github.com/apache/arrow/go/arrow/array"
+	"github.com/apache/arrow/go/arrow/memory"
+	"github.com/stretchr/testify/assert"
+)
+
+func TestMapArray(t *testing.T) {
+	pool := memory.NewCheckedAllocator(memory.NewGoAllocator())
+	defer pool.AssertSize(t, 0)
+
+	var (
+		arr, equalArr, unequalArr *array.Map
+
+		equalValid     = []bool{true, true, true, true, true, true, true}
+		equalOffsets   = []int32{0, 1, 2, 5, 6, 7, 8, 10}
+		equalKeys      = []string{"a", "a", "a", "b", "c", "a", "a", "a", "a", "b"}
+		equalValues    = []int32{1, 2, 3, 4, 5, 2, 2, 2, 5, 6}
+		unequalValid   = []bool{true, true, true}
+		unequalOffsets = []int32{0, 1, 4, 7}
+		unequalKeys    = []string{"a", "a", "b", "c", "a", "b", "c"}
+		unequalValues  = []int32{1, 2, 2, 2, 3, 4, 5}
+	)
+
+	bldr := array.NewMapBuilder(pool, arrow.BinaryTypes.String, arrow.PrimitiveTypes.Int32, false)
+	defer bldr.Release()
+
+	kb := bldr.KeyBuilder().(*array.StringBuilder)
+	ib := bldr.ItemBuilder().(*array.Int32Builder)
+
+	bldr.AppendValues(equalOffsets, equalValid)
+	for _, k := range equalKeys {
+		kb.Append(k)
+	}
+	ib.AppendValues(equalValues, nil)
+
+	assert.Equal(t, len(equalValid), bldr.Len())
+	assert.Zero(t, bldr.NullN())
+
+	arr = bldr.NewMapArray()
+	defer arr.Release()
+
+	bldr.AppendValues(equalOffsets, equalValid)
+	for _, k := range equalKeys {
+		kb.Append(k)
+	}
+	ib.AppendValues(equalValues, nil)
+
+	equalArr = bldr.NewMapArray()
+	defer equalArr.Release()
+
+	bldr.AppendValues(unequalOffsets, unequalValid)
+	for _, k := range unequalKeys {
+		kb.Append(k)
+	}
+	ib.AppendValues(unequalValues, nil)
+
+	unequalArr = bldr.NewMapArray()
+	defer unequalArr.Release()
+
+	assert.True(t, array.ArrayEqual(arr, arr))
+	assert.True(t, array.ArrayEqual(arr, equalArr))
+	assert.True(t, array.ArrayEqual(equalArr, arr))
+	assert.False(t, array.ArrayEqual(equalArr, unequalArr))
+	assert.False(t, array.ArrayEqual(unequalArr, equalArr))
+
+	// assert.True(t, array.ArraySliceEqual(arr, 0, 1, unequalArr, 0, 1))

Review comment:
       why are these commented out?




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#issuecomment-826909143


   @emkornfield I've added comments and docs as requested and responded to the questions. Lemme know if there's anything else needed.


-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619877896



##########
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:
       docs for Cap and NullN?




-- 
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:
users@infra.apache.org



[GitHub] [arrow] ggodik commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
ggodik commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r616735374



##########
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")

Review comment:
       are the panics necessary here ? is this common in arrow/go ?




-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield commented on pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield commented on pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#issuecomment-827709028


   @zeroshade I think this needs a rebase since the merge of the Decimal128 PR.


-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619878822



##########
File path: go/arrow/datatype_nested.go
##########
@@ -148,6 +148,40 @@ func (t *StructType) FieldByName(name string) (Field, bool) {
 	return t.fields[i], true
 }
 
+type MapType struct {
+	value      *ListType
+	KeysSorted bool
+}
+
+func MapOf(key, item DataType) *MapType {
+	if key == nil || item == nil {
+		panic("arrow: nil key or item type for MapType")
+	}
+
+	return &MapType{value: ListOf(StructOf(Field{Name: "key", Type: key}, Field{Name: "value", Type: item, Nullable: true}))}

Review comment:
       does "key" and "value" hardcoded here have any implications for reading maps that name this differentlcy.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619878143



##########
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.

Review comment:
       since Maps are relatively complex to work with, it might pay to give a simple usage example here.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] quinnj commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
quinnj commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619372303



##########
File path: go/arrow/array/map.go
##########
@@ -0,0 +1,232 @@
+// 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 ahve 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)

Review comment:
       Yeah, I don't see anywhere in the spec docs or cod that mentions `keysSorted` with regards to comparison




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r616744995



##########
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")

Review comment:
       yea, just following the pattern that is used elsewhere. Until the version tags are added properly as part of the release process here I can't change that because it would require adding "error" returns that would be breaking changes in order to get rid of the panics.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619893431



##########
File path: go/arrow/datatype_nested.go
##########
@@ -148,6 +148,40 @@ func (t *StructType) FieldByName(name string) (Field, bool) {
 	return t.fields[i], true
 }
 
+type MapType struct {
+	value      *ListType
+	KeysSorted bool
+}
+
+func MapOf(key, item DataType) *MapType {
+	if key == nil || item == nil {
+		panic("arrow: nil key or item type for MapType")
+	}
+
+	return &MapType{value: ListOf(StructOf(Field{Name: "key", Type: key}, Field{Name: "value", Type: item, Nullable: true}))}

Review comment:
       Ok, I confirmed that the names hardcoded here do not affect reading maps that name it differently. The assumption, as per the spec, is always that the first field is the keys and the second field is the values.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619890493



##########
File path: go/arrow/datatype_nested.go
##########
@@ -148,6 +148,40 @@ func (t *StructType) FieldByName(name string) (Field, bool) {
 	return t.fields[i], true
 }
 
+type MapType struct {
+	value      *ListType
+	KeysSorted bool
+}
+
+func MapOf(key, item DataType) *MapType {
+	if key == nil || item == nil {
+		panic("arrow: nil key or item type for MapType")
+	}
+
+	return &MapType{value: ListOf(StructOf(Field{Name: "key", Type: key}, Field{Name: "value", Type: item, Nullable: true}))}

Review comment:
       the current implementation of `StructOf` does not provide a name for the resulting struct, it only creates a datatype, rather than a Field. The DataType can then be used to create a Field and thus Name the struct.
   
   The same is true for the current implementation of `ListOf` here. The result is a `DataType` not a field and thus doesn't have a name.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619879144



##########
File path: go/arrow/internal/arrjson/arrjson.go
##########
@@ -52,15 +52,16 @@ type Field struct {
 }
 
 type dataType struct {
-	Name      string `json:"name"`
-	Signed    bool   `json:"isSigned,omitempty"`
-	BitWidth  int    `json:"bitWidth,omitempty"`
-	Precision string `json:"precision,omitempty"`
-	ByteWidth int    `json:"byteWidth,omitempty"`
-	ListSize  int32  `json:"listSize,omitempty"`
-	Unit      string `json:"unit,omitempty"`
-	TimeZone  string `json:"timezone,omitempty"`
-	Scale     int    `json:"scale,omitempty"` // for Decimal128
+	Name       string `json:"name"`

Review comment:
       this is just whitespace adjustment?




-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619878746



##########
File path: go/arrow/datatype_nested.go
##########
@@ -148,6 +148,40 @@ func (t *StructType) FieldByName(name string) (Field, bool) {
 	return t.fields[i], true
 }
 
+type MapType struct {
+	value      *ListType
+	KeysSorted bool
+}
+
+func MapOf(key, item DataType) *MapType {
+	if key == nil || item == nil {
+		panic("arrow: nil key or item type for MapType")
+	}
+
+	return &MapType{value: ListOf(StructOf(Field{Name: "key", Type: key}, Field{Name: "value", Type: item, Nullable: true}))}

Review comment:
       does StructOf provide a name?




-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619879329



##########
File path: go/arrow/internal/arrjson/arrjson_test.go
##########
@@ -3101,4 +3102,640 @@ func makeDurationsWantJSONs() string {
 
 func makeDecimal128sWantJSONs() string {
 	return `` // FIXME(fredgan): implement full decimal128 JSON support
-}
\ No newline at end of file
+}
+
+func makeMapsWantJSONs() string {
+	return `{

Review comment:
       for testing purposes would it make sense to use a shorter example?




-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619877852



##########
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:
       docs for Retain and Release.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r621331814



##########
File path: go/arrow/example_test.go
##########
@@ -593,3 +593,66 @@ func Example_table() {
 	// rec[3]["f1-i32"]: [16 17 18 19 20]
 	// rec[3]["f2-f64"]: [16 17 18 19 20]
 }
+
+// This example demonstrates how to create a Map Array.
+// The resulting array should be:

Review comment:
       The other cool aspect of this is that it shows up in the go docs too as an example like the examples on the pkg.go.dev docs [here](https://pkg.go.dev/github.com/apache/arrow/go/arrow#example-package-FixedSizeListArray) 😄 




-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619877771



##########
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:
       might be worth noting keysSorted is not enforced here?




-- 
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:
users@infra.apache.org



[GitHub] [arrow] WilliamWhispell commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
WilliamWhispell commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r616639481



##########
File path: go/arrow/array/map_test.go
##########
@@ -0,0 +1,151 @@
+// 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_test
+
+import (
+	"testing"
+
+	"github.com/apache/arrow/go/arrow"
+	"github.com/apache/arrow/go/arrow/array"
+	"github.com/apache/arrow/go/arrow/memory"
+	"github.com/stretchr/testify/assert"
+)
+
+func TestMapArray(t *testing.T) {
+	pool := memory.NewCheckedAllocator(memory.NewGoAllocator())
+	defer pool.AssertSize(t, 0)
+
+	var (
+		arr, equalArr, unequalArr *array.Map
+
+		equalValid     = []bool{true, true, true, true, true, true, true}
+		equalOffsets   = []int32{0, 1, 2, 5, 6, 7, 8, 10}
+		equalKeys      = []string{"a", "a", "a", "b", "c", "a", "a", "a", "a", "b"}
+		equalValues    = []int32{1, 2, 3, 4, 5, 2, 2, 2, 5, 6}
+		unequalValid   = []bool{true, true, true}
+		unequalOffsets = []int32{0, 1, 4, 7}
+		unequalKeys    = []string{"a", "a", "b", "c", "a", "b", "c"}
+		unequalValues  = []int32{1, 2, 2, 2, 3, 4, 5}
+	)
+
+	bldr := array.NewMapBuilder(pool, arrow.BinaryTypes.String, arrow.PrimitiveTypes.Int32, false)
+	defer bldr.Release()
+
+	kb := bldr.KeyBuilder().(*array.StringBuilder)
+	ib := bldr.ItemBuilder().(*array.Int32Builder)
+
+	bldr.AppendValues(equalOffsets, equalValid)
+	for _, k := range equalKeys {
+		kb.Append(k)
+	}
+	ib.AppendValues(equalValues, nil)
+
+	assert.Equal(t, len(equalValid), bldr.Len())
+	assert.Zero(t, bldr.NullN())
+
+	arr = bldr.NewMapArray()
+	defer arr.Release()
+
+	bldr.AppendValues(equalOffsets, equalValid)
+	for _, k := range equalKeys {
+		kb.Append(k)
+	}
+	ib.AppendValues(equalValues, nil)
+
+	equalArr = bldr.NewMapArray()
+	defer equalArr.Release()
+
+	bldr.AppendValues(unequalOffsets, unequalValid)
+	for _, k := range unequalKeys {
+		kb.Append(k)
+	}
+	ib.AppendValues(unequalValues, nil)
+
+	unequalArr = bldr.NewMapArray()
+	defer unequalArr.Release()
+
+	assert.True(t, array.ArrayEqual(arr, arr))
+	assert.True(t, array.ArrayEqual(arr, equalArr))
+	assert.True(t, array.ArrayEqual(equalArr, arr))
+	assert.False(t, array.ArrayEqual(equalArr, unequalArr))
+	assert.False(t, array.ArrayEqual(unequalArr, equalArr))
+
+	// assert.True(t, array.ArraySliceEqual(arr, 0, 1, unequalArr, 0, 1))

Review comment:
       why are these commented out?




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#issuecomment-825782614


   bump for reviews and hopefully merges


-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619899414



##########
File path: go/arrow/array/array_test.go
##########
@@ -85,10 +85,16 @@ func TestMakeFromData(t *testing.T) {
 		}},
 		{name: "duration", d: &testDataType{arrow.DURATION}},
 
+		{name: "map", d: &testDataType{arrow.MAP}, child: []*array.Data{
+			array.NewData(&testDataType{arrow.STRUCT}, 0, make([]*memory.Buffer, 4), []*array.Data{

Review comment:
       added comments for literals




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#issuecomment-822924120


   Tagging @emkornfield @sbinet for visibility


-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#issuecomment-827813914


   @emkornfield all set with the rebase here now and all tests passed still, huzzah


-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r616682988



##########
File path: go/arrow/array/map.go
##########
@@ -0,0 +1,232 @@
+// 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 ahve no nulls")

Review comment:
       fixed




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r616674653



##########
File path: go/arrow/array/builder.go
##########
@@ -277,6 +277,8 @@ func NewBuilder(mem memory.Allocator, dtype arrow.DataType) Builder {
 	case arrow.UNION:
 	case arrow.DICTIONARY:
 	case arrow.MAP:
+		typ := dtype.(*arrow.MapType)

Review comment:
       you're still thinking in C++ context. Go doesn't automatically fallthrough like C++, this *only* modifies the Map case, it doesn't change anything about Union or Dictionary.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r616683122



##########
File path: go/arrow/array/map.go
##########
@@ -0,0 +1,232 @@
+// 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 ahve 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() }
+func (b *MapBuilder) NullN() int { return b.listBuilder.NullN() }
+
+// Append adds a new Map element to the array, calling Append(false) is
+// equivalent to calling AppendNull.
+func (b *MapBuilder) Append(v bool) {
+	b.adjustStructBuilderLen()
+	b.listBuilder.Append(v)
+}
+
+// AppendNull adds a null map entry to the array.
+func (b *MapBuilder) AppendNull() {
+	b.adjustStructBuilderLen()

Review comment:
       done




-- 
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:
users@infra.apache.org



[GitHub] [arrow] WilliamWhispell commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
WilliamWhispell commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r616630446



##########
File path: go/arrow/array/map.go
##########
@@ -0,0 +1,232 @@
+// 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 ahve no nulls")

Review comment:
       typo




-- 
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:
users@infra.apache.org



[GitHub] [arrow] WilliamWhispell commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
WilliamWhispell commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r616634964



##########
File path: go/arrow/array/map.go
##########
@@ -0,0 +1,232 @@
+// 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 ahve 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() }
+func (b *MapBuilder) NullN() int { return b.listBuilder.NullN() }
+
+// Append adds a new Map element to the array, calling Append(false) is
+// equivalent to calling AppendNull.
+func (b *MapBuilder) Append(v bool) {
+	b.adjustStructBuilderLen()
+	b.listBuilder.Append(v)
+}
+
+// AppendNull adds a null map entry to the array.
+func (b *MapBuilder) AppendNull() {
+	b.adjustStructBuilderLen()

Review comment:
       Could be b.Append(false)




-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r621336278



##########
File path: go/arrow/datatype_nested.go
##########
@@ -148,6 +148,40 @@ func (t *StructType) FieldByName(name string) (Field, bool) {
 	return t.fields[i], true
 }
 
+type MapType struct {
+	value      *ListType
+	KeysSorted bool
+}
+
+func MapOf(key, item DataType) *MapType {
+	if key == nil || item == nil {
+		panic("arrow: nil key or item type for MapType")
+	}
+
+	return &MapType{value: ListOf(StructOf(Field{Name: "key", Type: key}, Field{Name: "value", Type: item, Nullable: true}))}

Review comment:
       +1, thanks.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619899539



##########
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.

Review comment:
       added an example.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619891483



##########
File path: go/arrow/internal/arrjson/arrjson_test.go
##########
@@ -3101,4 +3102,640 @@ func makeDurationsWantJSONs() string {
 
 func makeDecimal128sWantJSONs() string {
 	return `` // FIXME(fredgan): implement full decimal128 JSON support
-}
\ No newline at end of file
+}
+
+func makeMapsWantJSONs() string {
+	return `{

Review comment:
       because these tests are generated from the `arrdata` record batches that's why this ends up this large. The reason why those records are the size they are is to ensure that we're properly testing handling multiple chunks with a map and multiple records.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619890930



##########
File path: go/arrow/example_test.go
##########
@@ -593,3 +593,66 @@ func Example_table() {
 	// rec[3]["f1-i32"]: [16 17 18 19 20]
 	// rec[3]["f2-f64"]: [16 17 18 19 20]
 }
+
+// This example demonstrates how to create a Map Array.
+// The resulting array should be:

Review comment:
       By putting the comment at the end of the method here in that format this example actually gets run as a test when running tests and confirms that the output of running this method matches the output comment at the end of the method. moving the comment at the end of the method would disable that benefit. 




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#issuecomment-827716298


   @emkornfield yup, i was already doing the rebase when you commented haha. I've pushed the rebase


-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619876807



##########
File path: go/arrow/array/map.go
##########
@@ -0,0 +1,232 @@
+// 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 ahve 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)

Review comment:
       it isn't.  To my knowledge the keySorted doesn't have strong semantics other than to indicate the keys follow some logical ordering.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619890319



##########
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.

Review comment:
       I used the example_test file to provide a simple usage example which would show up in the generated docs on pkg.go.dev, I figured that was more directly useful than putting one here, but i can also add one here too.

##########
File path: go/arrow/datatype_nested.go
##########
@@ -148,6 +148,40 @@ func (t *StructType) FieldByName(name string) (Field, bool) {
 	return t.fields[i], true
 }
 
+type MapType struct {
+	value      *ListType
+	KeysSorted bool
+}
+
+func MapOf(key, item DataType) *MapType {
+	if key == nil || item == nil {
+		panic("arrow: nil key or item type for MapType")
+	}
+
+	return &MapType{value: ListOf(StructOf(Field{Name: "key", Type: key}, Field{Name: "value", Type: item, Nullable: true}))}

Review comment:
       the current implementation of `StructOf` does not provide a name for the resulting struct, it only creates a datatype, rather than a Field. The DataType can then be used to create a Field and thus Name the struct.
   
   The same is true for the current implementation of `ListOf` here. The result is a `DataType` not a field and thus doesn't have a name.

##########
File path: go/arrow/datatype_nested.go
##########
@@ -148,6 +148,40 @@ func (t *StructType) FieldByName(name string) (Field, bool) {
 	return t.fields[i], true
 }
 
+type MapType struct {
+	value      *ListType
+	KeysSorted bool
+}
+
+func MapOf(key, item DataType) *MapType {
+	if key == nil || item == nil {
+		panic("arrow: nil key or item type for MapType")
+	}
+
+	return &MapType{value: ListOf(StructOf(Field{Name: "key", Type: key}, Field{Name: "value", Type: item, Nullable: true}))}

Review comment:
       I'll double check but I don't believe I enforce these names having to be named this way during reading. That said, naming them this way is how the spec describes it should be done.

##########
File path: go/arrow/example_test.go
##########
@@ -593,3 +593,66 @@ func Example_table() {
 	// rec[3]["f1-i32"]: [16 17 18 19 20]
 	// rec[3]["f2-f64"]: [16 17 18 19 20]
 }
+
+// This example demonstrates how to create a Map Array.
+// The resulting array should be:

Review comment:
       By putting the comment at the end of the method here in that format this example actually gets run as a test when running tests and confirms that the output of running this method matches the output comment at the end of the method. moving the comment at the end of the method would disable that benefit. 

##########
File path: go/arrow/internal/arrjson/arrjson.go
##########
@@ -52,15 +52,16 @@ type Field struct {
 }
 
 type dataType struct {
-	Name      string `json:"name"`
-	Signed    bool   `json:"isSigned,omitempty"`
-	BitWidth  int    `json:"bitWidth,omitempty"`
-	Precision string `json:"precision,omitempty"`
-	ByteWidth int    `json:"byteWidth,omitempty"`
-	ListSize  int32  `json:"listSize,omitempty"`
-	Unit      string `json:"unit,omitempty"`
-	TimeZone  string `json:"timezone,omitempty"`
-	Scale     int    `json:"scale,omitempty"` // for Decimal128
+	Name       string `json:"name"`

Review comment:
       `KeysSorted` was added to the struct which is why the whitespace got adjusted

##########
File path: go/arrow/internal/arrjson/arrjson_test.go
##########
@@ -3101,4 +3102,640 @@ func makeDurationsWantJSONs() string {
 
 func makeDecimal128sWantJSONs() string {
 	return `` // FIXME(fredgan): implement full decimal128 JSON support
-}
\ No newline at end of file
+}
+
+func makeMapsWantJSONs() string {
+	return `{

Review comment:
       because these tests are generated from the `arrdata` record batches that's why this ends up this large. The reason why those records are the size they are is to ensure that we're properly testing handling multiple chunks with a map and multiple records.

##########
File path: go/arrow/datatype_nested.go
##########
@@ -148,6 +148,40 @@ func (t *StructType) FieldByName(name string) (Field, bool) {
 	return t.fields[i], true
 }
 
+type MapType struct {
+	value      *ListType
+	KeysSorted bool
+}
+
+func MapOf(key, item DataType) *MapType {
+	if key == nil || item == nil {
+		panic("arrow: nil key or item type for MapType")
+	}
+
+	return &MapType{value: ListOf(StructOf(Field{Name: "key", Type: key}, Field{Name: "value", Type: item, Nullable: true}))}

Review comment:
       Ok, I confirmed that the names hardcoded here do not affect reading maps that name it differently. The assumption, as per the spec, is always that the first field is the keys and the second field is the values.

##########
File path: go/arrow/array/array_test.go
##########
@@ -85,10 +85,16 @@ func TestMakeFromData(t *testing.T) {
 		}},
 		{name: "duration", d: &testDataType{arrow.DURATION}},
 
+		{name: "map", d: &testDataType{arrow.MAP}, child: []*array.Data{
+			array.NewData(&testDataType{arrow.STRUCT}, 0, make([]*memory.Buffer, 4), []*array.Data{

Review comment:
       added comments for literals

##########
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

##########
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.

Review comment:
       added an example.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619877428



##########
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:
       nit: might be worth commenting on the somewhat lack of semantics of keySored and linking to the spec.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r616684275



##########
File path: go/arrow/array/map.go
##########
@@ -0,0 +1,232 @@
+// 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 ahve 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)

Review comment:
       Currently they would not, and as far as I can tell that seems consistent with other implementations. Someone else can tell me if i'm wrong there.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield closed pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield closed pull request #10106:
URL: https://github.com/apache/arrow/pull/10106


   


-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619890704



##########
File path: go/arrow/datatype_nested.go
##########
@@ -148,6 +148,40 @@ func (t *StructType) FieldByName(name string) (Field, bool) {
 	return t.fields[i], true
 }
 
+type MapType struct {
+	value      *ListType
+	KeysSorted bool
+}
+
+func MapOf(key, item DataType) *MapType {
+	if key == nil || item == nil {
+		panic("arrow: nil key or item type for MapType")
+	}
+
+	return &MapType{value: ListOf(StructOf(Field{Name: "key", Type: key}, Field{Name: "value", Type: item, Nullable: true}))}

Review comment:
       I'll double check but I don't believe I enforce these names having to be named this way during reading. That said, naming them this way is how the spec describes it should be done.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] github-actions[bot] commented on pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#issuecomment-822924052


   https://issues.apache.org/jira/browse/ARROW-5640


-- 
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:
users@infra.apache.org



[GitHub] [arrow] WilliamWhispell commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
WilliamWhispell commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r616632364



##########
File path: go/arrow/array/map.go
##########
@@ -0,0 +1,232 @@
+// 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 ahve 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)

Review comment:
       Would maps with the same key values, but in different orders be considered equal?




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619890319



##########
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.

Review comment:
       I used the example_test file to provide a simple usage example which would show up in the generated docs on pkg.go.dev, I figured that was more directly useful than putting one here, but i can also add one here too.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r616683513



##########
File path: go/arrow/array/map_test.go
##########
@@ -0,0 +1,151 @@
+// 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_test
+
+import (
+	"testing"
+
+	"github.com/apache/arrow/go/arrow"
+	"github.com/apache/arrow/go/arrow/array"
+	"github.com/apache/arrow/go/arrow/memory"
+	"github.com/stretchr/testify/assert"
+)
+
+func TestMapArray(t *testing.T) {
+	pool := memory.NewCheckedAllocator(memory.NewGoAllocator())
+	defer pool.AssertSize(t, 0)
+
+	var (
+		arr, equalArr, unequalArr *array.Map
+
+		equalValid     = []bool{true, true, true, true, true, true, true}
+		equalOffsets   = []int32{0, 1, 2, 5, 6, 7, 8, 10}
+		equalKeys      = []string{"a", "a", "a", "b", "c", "a", "a", "a", "a", "b"}
+		equalValues    = []int32{1, 2, 3, 4, 5, 2, 2, 2, 5, 6}
+		unequalValid   = []bool{true, true, true}
+		unequalOffsets = []int32{0, 1, 4, 7}
+		unequalKeys    = []string{"a", "a", "b", "c", "a", "b", "c"}
+		unequalValues  = []int32{1, 2, 2, 2, 3, 4, 5}
+	)
+
+	bldr := array.NewMapBuilder(pool, arrow.BinaryTypes.String, arrow.PrimitiveTypes.Int32, false)
+	defer bldr.Release()
+
+	kb := bldr.KeyBuilder().(*array.StringBuilder)
+	ib := bldr.ItemBuilder().(*array.Int32Builder)
+
+	bldr.AppendValues(equalOffsets, equalValid)
+	for _, k := range equalKeys {
+		kb.Append(k)
+	}
+	ib.AppendValues(equalValues, nil)
+
+	assert.Equal(t, len(equalValid), bldr.Len())
+	assert.Zero(t, bldr.NullN())
+
+	arr = bldr.NewMapArray()
+	defer arr.Release()
+
+	bldr.AppendValues(equalOffsets, equalValid)
+	for _, k := range equalKeys {
+		kb.Append(k)
+	}
+	ib.AppendValues(equalValues, nil)
+
+	equalArr = bldr.NewMapArray()
+	defer equalArr.Release()
+
+	bldr.AppendValues(unequalOffsets, unequalValid)
+	for _, k := range unequalKeys {
+		kb.Append(k)
+	}
+	ib.AppendValues(unequalValues, nil)
+
+	unequalArr = bldr.NewMapArray()
+	defer unequalArr.Release()
+
+	assert.True(t, array.ArrayEqual(arr, arr))
+	assert.True(t, array.ArrayEqual(arr, equalArr))
+	assert.True(t, array.ArrayEqual(equalArr, arr))
+	assert.False(t, array.ArrayEqual(equalArr, unequalArr))
+	assert.False(t, array.ArrayEqual(unequalArr, equalArr))
+
+	// assert.True(t, array.ArraySliceEqual(arr, 0, 1, unequalArr, 0, 1))

Review comment:
       forgot to uncomment when testing something. :) Uncommented now.




-- 
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:
users@infra.apache.org



[GitHub] [arrow] zeroshade commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
zeroshade commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619891102



##########
File path: go/arrow/internal/arrjson/arrjson.go
##########
@@ -52,15 +52,16 @@ type Field struct {
 }
 
 type dataType struct {
-	Name      string `json:"name"`
-	Signed    bool   `json:"isSigned,omitempty"`
-	BitWidth  int    `json:"bitWidth,omitempty"`
-	Precision string `json:"precision,omitempty"`
-	ByteWidth int    `json:"byteWidth,omitempty"`
-	ListSize  int32  `json:"listSize,omitempty"`
-	Unit      string `json:"unit,omitempty"`
-	TimeZone  string `json:"timezone,omitempty"`
-	Scale     int    `json:"scale,omitempty"` // for Decimal128
+	Name       string `json:"name"`

Review comment:
       `KeysSorted` was added to the struct which is why the whitespace got adjusted




-- 
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:
users@infra.apache.org



[GitHub] [arrow] emkornfield commented on a change in pull request #10106: ARROW-5640: [Go] Implement Arrow Map Array

Posted by GitBox <gi...@apache.org>.
emkornfield commented on a change in pull request #10106:
URL: https://github.com/apache/arrow/pull/10106#discussion_r619878992



##########
File path: go/arrow/example_test.go
##########
@@ -593,3 +593,66 @@ func Example_table() {
 	// rec[3]["f1-i32"]: [16 17 18 19 20]
 	// rec[3]["f2-f64"]: [16 17 18 19 20]
 }
+
+// This example demonstrates how to create a Map Array.
+// The resulting array should be:

Review comment:
       should the comment at the end of the method be moved up here?  Maybe provide a reference here instead of documentation of usage I mentioned above.




-- 
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:
users@infra.apache.org