nullccxsy commented on code in PR #180:
URL: https://github.com/apache/iceberg-cpp/pull/180#discussion_r2291753393


##########
src/iceberg/schema.cc:
##########
@@ -44,4 +80,172 @@ bool Schema::Equals(const Schema& other) const {
   return schema_id_ == other.schema_id_ && fields_ == other.fields_;
 }
 
+Result<std::optional<std::reference_wrapper<const SchemaField>>> 
Schema::FindFieldByName(
+    std::string_view name, bool case_sensitive) const {
+  if (case_sensitive) {
+    ICEBERG_RETURN_UNEXPECTED(InitNameToIndexMap());
+    auto it = name_to_index_.find(std::string(name));
+    if (it == name_to_index_.end()) return std::nullopt;
+    return full_schemafield_[it->second];
+  }
+  ICEBERG_RETURN_UNEXPECTED(InitLowerCaseNameToIndexMap());
+  std::string lower_name(name);
+  std::ranges::transform(lower_name, lower_name.begin(), ::tolower);
+  auto it = lowercase_name_to_index_.find(lower_name);
+  if (it == lowercase_name_to_index_.end()) return std::nullopt;
+  return full_schemafield_[it->second];
+}
+
+Result<std::optional<std::reference_wrapper<const SchemaField>>> 
Schema::FindFieldByName(
+    std::string_view name) const {
+  return FindFieldByName(name, /*case_sensitive*/ true);
+}
+
+Result<Status> Schema::InitIdToIndexMap() const {
+  if (!id_to_index_.empty()) {
+    return {};
+  }
+  bool has_init = !full_schemafield_.empty();

Review Comment:
   do you mean Status IdVisitor::Visit(const Type& type, 
std::unordered_map<int32_t, std::reference_wrapper<const SchemaField>>& 
id_to_schemafield) ? 



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to