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


##########
src/iceberg/type.cc:
##########
@@ -105,23 +149,29 @@ std::string ListType::ToString() const {
   return repr;
 }
 std::span<const SchemaField> ListType::fields() const { return {&element_, 1}; 
}
-std::optional<std::reference_wrapper<const SchemaField>> 
ListType::GetFieldById(
+Result<std::optional<std::reference_wrapper<const SchemaField>>> 
ListType::GetFieldById(
     int32_t field_id) const {
   if (field_id == element_.field_id()) {
     return std::cref(element_);
   }
   return std::nullopt;
 }
-std::optional<std::reference_wrapper<const SchemaField>> 
ListType::GetFieldByIndex(
-    int index) const {
+Result<std::optional<std::reference_wrapper<const SchemaField>>>
+ListType::GetFieldByIndex(int index) const {
   if (index == 0) {
     return std::cref(element_);
   }
   return std::nullopt;
 }
-std::optional<std::reference_wrapper<const SchemaField>> 
ListType::GetFieldByName(
-    std::string_view name) const {
-  if (name == element_.name()) {
+Result<std::optional<std::reference_wrapper<const SchemaField>>> 
ListType::GetFieldByName(
+    std::string_view name, bool case_sensitive) const {
+  if (case_sensitive) {
+    if (name == element_.name()) {
+      return std::cref(element_);
+    }
+    return std::nullopt;
+  }
+  if (StringUtils::ToLower(name) == StringUtils::ToLower(element_.name())) {

Review Comment:
   You can take a look at this code in `schema.java` — it converts all names to 
lowercase before querying. Therefore, even if the name is "KEY", it should 
still be searchable. Here, type.h reuses the functionality from schema to 
support select function.
   ```
   public NestedField caseInsensitiveFindField(String name) {
       Preconditions.checkArgument(!name.isEmpty(), "Invalid column name: 
(empty)");
       Integer id = lazyLowerCaseNameToId().get(name.toLowerCase(Locale.ROOT));
       if (id != null) {
         return lazyIdToField().get(id);
       }
       return null;
    }
   ```



-- 
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: issues-unsubscr...@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to