You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@thrift.apache.org by "slachiewicz (via GitHub)" <gi...@apache.org> on 2026/09/01 23:20:02 UTC

[PR] THRIFT-2063: Generate Go maps with container keys as entry slices [thrift]

slachiewicz opened a new pull request, #3778:
URL: https://github.com/apache/thrift/pull/3778

   Go maps cannot be keyed by a slice or a map, so the Go generator aborted on any thrift `map` keyed by a `list`, `set`, `map`, or a typedef of one of those. This change generates such fields as `[]thrift.MapEntry[K, V]`, a slice of key/value pairs written to the wire in slice order. Key uniqueness is not enforced, which matches how thrift sets are already represented as slices in Go. Maps whose keys were already representable keep their current Go type, so existing generated code is unchanged.
   
   The Go test Makefiles no longer strip `CrazyNesting.list_field` from `ThriftTest.thrift`, and the cross-test client, server and stress binaries build against the full IDL. Struct-keyed maps still generate as `map[*K]V`; changing that is left for a separate ticket because it alters working output.
   
   Verified: `go test ./gopath/src/tests ./gopath/src/dontexportrwtest` in lib/go/test and `go test ./...` in lib/go/thrift → ok; `go build`/`go vet` on all generated test packages → clean.
   
   - [x] Did you create an [Apache Jira](https://issues.apache.org/jira/projects/THRIFT/issues/) ticket?
   - [x] If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
   - [x] Did you squash your changes to a single commit?
   - [x] Did you do your best to avoid breaking changes?
   - [ ] If your change does not involve any code, include `[skip ci]` anywhere in the commit message to free up build resources.
   
   *This change was created with AI assistance.*
   


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

To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org

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


Re: [PR] THRIFT-2063: Generate Go maps with container keys as entry slices [thrift]

Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on PR #3778:
URL: https://github.com/apache/thrift/pull/3778#issuecomment-5502579577

   looks good to me besides the `is_map_entry_slice` name. although I'm not sure splitting the generated map types is going to be a good idea longer term. cc @dcelasun for second opinion


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

To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org

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


Re: [PR] THRIFT-2063: Generate Go maps with container keys as entry slices [thrift]

Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy merged PR #3778:
URL: https://github.com/apache/thrift/pull/3778


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

To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org

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


Re: [PR] THRIFT-2063: Generate Go maps with container keys as entry slices [thrift]

Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on code in PR #3778:
URL: https://github.com/apache/thrift/pull/3778#discussion_r3909596997


##########
compiler/cpp/src/thrift/generate/t_go_generator.cc:
##########
@@ -4484,16 +4567,35 @@ string t_go_generator::type_to_enum(t_type* type) {
   throw "INVALID TYPE IN type_to_enum: " + type->get_name();
 }
 
+/**
+ * Returns true when the map cannot be a Go map because its key type is a
+ * container (list, set or map, possibly behind a typedef). Such maps are
+ * represented as a slice of thrift.MapEntry.
+ */
+bool t_go_generator::is_map_entry_slice(t_type* type) {

Review Comment:
   the name is misleading, we return true not only for slices, but also for maps and sets. call it `is_map_entry_container` or something like that instead?



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

To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org

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


Re: [PR] THRIFT-2063: Generate Go maps with container keys as entry slices [thrift]

Posted by "slachiewicz (via GitHub)" <gi...@apache.org>.
slachiewicz commented on code in PR #3778:
URL: https://github.com/apache/thrift/pull/3778#discussion_r3912002264


##########
lib/go/thrift/map_entry.go:
##########
@@ -0,0 +1,32 @@
+/*
+ * 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 thrift
+
+// MapEntry is one key/value pair of a Thrift map whose key type cannot be a
+// Go map key: list, set and map keys, and typedefs resolving to one of those.
+//
+// The generator represents such a field as []MapEntry[K, V]. Entries are
+// written to the wire in slice order. Uniqueness of keys is not enforced on
+// read or write, which mirrors how this library represents Thrift sets as
+// slices.

Review Comment:
   Updated in 5fb0eeb: the comment now states the INVALID_DATA write check and that reads do not check duplicates.
   
   *This comment was created with AI assistance.*



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

To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org

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


Re: [PR] THRIFT-2063: Generate Go maps with container keys as entry slices [thrift]

Posted by "slachiewicz (via GitHub)" <gi...@apache.org>.
slachiewicz commented on PR #3778:
URL: https://github.com/apache/thrift/pull/3778#issuecomment-5507179606

   Copilot's second finding was real and pre-existing: the generated map `Equals` skipped the `ok` check, so maps with different key sets compared equal when the zero value matched, and the new write check then rejected map-keyed entries such as `{a:0}` and `{b:0}`. Fixed in 14165b1 with tests for both cases.
   
   *This comment was created with AI assistance.*


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

To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org

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


Re: [PR] THRIFT-2063: Generate Go maps with container keys as entry slices [thrift]

Posted by "slachiewicz (via GitHub)" <gi...@apache.org>.
slachiewicz commented on PR #3778:
URL: https://github.com/apache/thrift/pull/3778#issuecomment-5502202741

   Corrected. The generated writer now runs the same pairwise key check that sets use and returns INVALID_DATA on a duplicate key; covered by TestContainerKeyWriteRejectsDuplicateKeys. PR description updated to match.
   
   *This comment was created with AI assistance.*


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

To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org

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


Re: [PR] THRIFT-2063: Generate Go maps with container keys as entry slices [thrift]

Posted by "slachiewicz (via GitHub)" <gi...@apache.org>.
slachiewicz commented on PR #3778:
URL: https://github.com/apache/thrift/pull/3778#issuecomment-5505961067

   A real-world IDL that hits this: Apache Hive's `hive_metastore.thrift` (tag `rel/release-4.2.1`) declares `SkewedInfo.skewedColValueLocationMaps` as `map<list<string>, string>`, and the released Go generator aborts on the whole file:
   
   ```
   [FAILURE:generation:1] Error: Cannot produce a valid type for a Go map key: []string - aborting.
   ```
   
   A pure-Go metastore client currently has to strip that field from the IDL before generating. With this branch's compiler the pristine IDL generates, and the field becomes `[]thrift.MapEntry[[]string, string]`.
   
   Verified: `thrift -r --gen go -out gen hive_metastore.thrift` (built from this PR's head) → exit 0; `go build ./gen/...` against this branch's `lib/go` → clean.
   
   The only other thing that keeps that IDL from building for Go is unrelated to this change: three fields literally named `isSetQueryParallelism`, `isSetDefaultPoolPath` and `isSetSchedulingPolicy` collide with the generated `IsSetX()` accessors. I will file that separately.
   
   *This comment was created with AI assistance.*
   


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

To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org

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


Re: [PR] THRIFT-2063: Generate Go maps with container keys as entry slices [thrift]

Posted by "slachiewicz (via GitHub)" <gi...@apache.org>.
slachiewicz commented on PR #3778:
URL: https://github.com/apache/thrift/pull/3778#issuecomment-5506337587

   On the two-representation point: Go has no hashable form for a list, set or map key, so the only single representation would be to emit every map as an entry slice, which changes the type of every existing generated field. The per-key-type split keeps generated code for today's IDLs byte-identical and is confined to one predicate in the generator. There is precedent for the Go representation following what Go can express rather than the Thrift kind: `set` has always generated as a slice while `map` generates as a map. If a uniform slice representation is wanted later, it fits as a generator option layered on the same entry type without changing this default. Happy to go either way if you and @dcelasun prefer the option now.
   
   *This comment was created with AI assistance.*


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

To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org

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


Re: [PR] THRIFT-2063: Generate Go maps with container keys as entry slices [thrift]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3778:
URL: https://github.com/apache/thrift/pull/3778#discussion_r3909322683


##########
lib/go/test/Makefile.am:
##########
@@ -61,16 +61,18 @@ gopath: $(THRIFT) $(THRIFTTEST) \
 				ConflictArgNamesTest.thrift \
 				ConstOptionalFieldImport.thrift \
 				ConstOptionalField.thrift \
+	ContainerKeyTest.thrift \
 				ProcessorMiddlewareTest.thrift \
 				ClientMiddlewareExceptionTest.thrift \
 				ValidateTest.thrift \
 				ForwardType.thrift \
 				StringParseAllocationTest.thrift

Review Comment:
   `ContainerKeyTest.thrift` is listed twice in the `gopath` prerequisite list (once around line 39 and again here). The duplicate entry is redundant and makes the dependency list harder to maintain.



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

To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org

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


Re: [PR] THRIFT-2063: Generate Go maps with container keys as entry slices [thrift]

Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on PR #3778:
URL: https://github.com/apache/thrift/pull/3778#issuecomment-5501993924

   >Key uniqueness is not enforced, which matches how thrift sets are already represented as slices in Go
   
   this is not true. while go sets don't guarantee uniqueness at wire level, it's checked at write time and duplicates will cause a write failure.


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

To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org

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


Re: [PR] THRIFT-2063: Generate Go maps with container keys as entry slices [thrift]

Posted by "slachiewicz (via GitHub)" <gi...@apache.org>.
slachiewicz commented on code in PR #3778:
URL: https://github.com/apache/thrift/pull/3778#discussion_r3911930137


##########
compiler/cpp/src/thrift/generate/t_go_generator.cc:
##########
@@ -4484,16 +4567,35 @@ string t_go_generator::type_to_enum(t_type* type) {
   throw "INVALID TYPE IN type_to_enum: " + type->get_name();
 }
 
+/**
+ * Returns true when the map cannot be a Go map because its key type is a
+ * container (list, set or map, possibly behind a typedef). Such maps are
+ * represented as a slice of thrift.MapEntry.
+ */
+bool t_go_generator::is_map_entry_slice(t_type* type) {

Review Comment:
   Renamed to `is_container_keyed_map`: it answers whether the map's key is a list, set or map, which is what the call sites branch on. Pushed as a separate commit (f07ab0b).
   
   *This comment was created with AI assistance.*



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

To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org

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


Re: [PR] THRIFT-2063: Generate Go maps with container keys as entry slices [thrift]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3778:
URL: https://github.com/apache/thrift/pull/3778#discussion_r3909488224


##########
lib/go/thrift/map_entry.go:
##########
@@ -0,0 +1,32 @@
+/*
+ * 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 thrift
+
+// MapEntry is one key/value pair of a Thrift map whose key type cannot be a
+// Go map key: list, set and map keys, and typedefs resolving to one of those.
+//
+// The generator represents such a field as []MapEntry[K, V]. Entries are
+// written to the wire in slice order. Uniqueness of keys is not enforced on
+// read or write, which mirrors how this library represents Thrift sets as
+// slices.

Review Comment:
   The MapEntry doc comment says key uniqueness is not enforced on read or write, but the Go generator emits an INVALID_DATA protocol exception when writing a container-keyed map with duplicate keys (and the README/tests reflect that behavior). The comment should be updated to match the actual semantics so users aren't surprised by serialization failures.



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

To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org

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


Re: [PR] THRIFT-2063: Generate Go maps with container keys as entry slices [thrift]

Posted by "slachiewicz (via GitHub)" <gi...@apache.org>.
slachiewicz commented on PR #3778:
URL: https://github.com/apache/thrift/pull/3778#issuecomment-5506285844

   Filed the accessor collision as THRIFT-6176.


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

To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org

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


Re: [PR] THRIFT-2063: Generate Go maps with container keys as entry slices [thrift]

Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on PR #3778:
URL: https://github.com/apache/thrift/pull/3778#issuecomment-5512448786

   I don't think an uniformed slice implementation for maps is better, it's definitely better to use builtin map whenever we can :sweat_smile:


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

To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org

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