Skip to content

Commit

Permalink
apacheGH-40494: [Go] add support for protobuf messages (apache#40496)
Browse files Browse the repository at this point in the history
### Rationale for this change

Support for protobuf messages

### What changes are included in this PR?

Ability to create a schema from a protobuf message
Ability to create a record from a protobuf message
Some customisations

### Are these changes tested?

Yes, couple of unit tests included

### Are there any user-facing changes?

No

* GitHub Issue: apache#40494

Lead-authored-by: Tom Scott-Coombes <[email protected]>
Co-authored-by: Tom Scott-Coombes <[email protected]>
Co-authored-by: Matt Topol <[email protected]>
Co-authored-by: tscottcoombes1 <[email protected]>
Signed-off-by: Matt Topol <[email protected]>
  • Loading branch information
2 people authored and vibhatha committed Jun 5, 2024
1 parent 185d804 commit 9d66dc2
Show file tree
Hide file tree
Showing 9 changed files with 1,802 additions and 1 deletion.
1 change: 1 addition & 0 deletions dev/release/rat_exclude_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ go.work.sum
go/go.sum
go/arrow/Gopkg.lock
go/arrow/flight/gen/flight/*.pb.go
go/arrow/util/util_message/*.pb.go
go/arrow/internal/cpu/*
go/arrow/type_string.go
go/arrow/cdata/test/go.sum
Expand Down
2 changes: 1 addition & 1 deletion go/arrow/datatype_nested.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ func DenseUnionFromArrays(children []Array, fields []string, codes []UnionTypeCo
}

// DenseUnionOf is equivalent to UnionOf(arrow.DenseMode, fields, typeCodes),
// constructing a SparseUnionType from a list of fields and type codes.
// constructing a DenseUnionType from a list of fields and type codes.
//
// If len(fields) != len(typeCodes) this will panic. They are allowed to be
// of length 0.
Expand Down
25 changes: 25 additions & 0 deletions go/arrow/util/messages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!---
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.
-->

How to generate the .pb.go files

```
cd go/arrow/util/
protoc -I ./ --go_out=./messages ./messages/types.proto
```
56 changes: 56 additions & 0 deletions go/arrow/util/messages/types.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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.

syntax = "proto3";
import "google/protobuf/any.proto";

option go_package = "../util_message";

message ExampleMessage {
string field1 = 1;
}

message AllTheTypes {
string str = 1;
int32 int32 = 2;
int64 int64 = 3;
sint32 sint32 = 4;
sint64 sin64 = 5;
uint32 uint32 = 6;
uint64 uint64 = 7;
fixed32 fixed32 = 8;
fixed64 fixed64 = 9;
sfixed32 sfixed32 = 10;
bool bool = 11;
bytes bytes = 12;
double double = 13;
ExampleEnum enum = 14;
ExampleMessage message = 15;
oneof oneof {
string oneofstring = 16;
ExampleMessage oneofmessage = 17;
}
google.protobuf.Any any = 18;
map<int32, string> simple_map = 19;
map<string, ExampleMessage> complex_map = 20;
repeated string simple_list = 21;
repeated ExampleMessage complex_list = 22;

enum ExampleEnum {
OPTION_0 = 0;
OPTION_1 = 1;
}
}
Loading

0 comments on commit 9d66dc2

Please sign in to comment.