jvanstraten commented on code in PR #12852:
URL: https://github.com/apache/arrow/pull/12852#discussion_r870817041


##########
cpp/src/arrow/engine/substrait/extension_set.cc:
##########
@@ -174,31 +134,51 @@ Result<ExtensionSet> 
ExtensionSet::Make(std::vector<util::string_view> uris,
 }
 
 Result<ExtensionSet::TypeRecord> ExtensionSet::DecodeType(uint32_t anchor) 
const {
-  if (anchor >= types_.size() || types_[anchor].id.empty()) {
+  if (types_.find(anchor) == types_.end() || types_.at(anchor).id.empty()) {
     return Status::Invalid("User defined type reference ", anchor,
                            " did not have a corresponding anchor in the 
extension set");
   }
-  return types_[anchor];
+  return types_.at(anchor);

Review Comment:
   I haven't looked at the PR again as of yet, but this struck me as an odd 
take in my e-mail feed. Assuming types_ is now a map of some kind, keep in mind 
that if the key does not exist, an uninitialized value is silently *added to 
the map* and then returned by mutable reference, to make x[y] = z work at the 
expense of sanity in all other use cases. Both [] and at() are bad if there's a 
real possibility of this occurring (I didn't check), but I'd much rather get an 
unhandled exception than pants-on-head crazy behavior. For vectors there'd be a 
minor performance benefit to [] over at(), but that also doesn't apply to maps 
AFAIK.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to