Skip to content

Commit adc4817

Browse files
author
nullccxsy
committed
fix(type): fix tolower calls, add cctype header and apply code formatting
1 parent 06adc3f commit adc4817

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

src/iceberg/type.cc

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <optional>
2929
#include <ranges>
3030
#include <string_view>
31+
3132
#include <iceberg/schema_field.h>
3233

3334
#include "iceberg/exception.h"
@@ -82,8 +83,8 @@ std::optional<std::reference_wrapper<const SchemaField>> StructType::GetFieldByN
8283
if (it == field_name_to_index_.end()) return std::nullopt;
8384
return fields_[it->second];
8485
}
85-
std::optional<std::reference_wrapper<const SchemaField>> StructType::GetFieldByNameCaseInsensitive(
86-
std::string_view name) const {
86+
std::optional<std::reference_wrapper<const SchemaField>>
87+
StructType::GetFieldByNameCaseInsensitive(std::string_view name) const {
8788
InitNameToIdMapCaseInsensitive();
8889
std::string lower_name(name);
8990
std::ranges::transform(lower_name, lower_name.begin(), ::tolower);
@@ -102,16 +103,16 @@ void StructType::InitNameToIdMap() const {
102103
if (!field_name_to_index_.empty()) {
103104
return;
104105
}
105-
106+
106107
for (int i = 0; i < fields_.size(); i++) {
107-
field_name_to_index_[std::string(fields_[i].name())] = i;
108+
field_name_to_index_[std::string(fields_[i].name())] = i;
108109
}
109110
}
110111
void StructType::InitNameToIdMapCaseInsensitive() const {
111112
if (!caseinsensitive_field_name_to_index_.empty()) {
112113
return;
113114
}
114-
115+
115116
for (int i = 0; i < fields_.size(); i++) {
116117
std::string lowercase_name(fields_[i].name());
117118
std::ranges::transform(lowercase_name, lowercase_name.begin(), ::tolower);
@@ -160,13 +161,13 @@ std::optional<std::reference_wrapper<const SchemaField>> ListType::GetFieldByNam
160161
}
161162
return std::nullopt;
162163
}
163-
std::optional<std::reference_wrapper<const SchemaField>> ListType::GetFieldByNameCaseInsensitive(
164-
std::string_view name) const {
164+
std::optional<std::reference_wrapper<const SchemaField>>
165+
ListType::GetFieldByNameCaseInsensitive(std::string_view name) const {
165166
auto lower_name_view = name | std::views::transform(::tolower);
166167
auto lower_field_name = element_.name() | std::views::transform(::tolower);
167168
if (std::ranges::equal(lower_field_name, lower_name_view)) {
168169
return std::cref(element_);
169-
}
170+
}
170171
return std::nullopt;
171172
}
172173
bool ListType::Equals(const Type& other) const {
@@ -229,11 +230,11 @@ std::optional<std::reference_wrapper<const SchemaField>> MapType::GetFieldByName
229230
}
230231
return std::nullopt;
231232
}
232-
std::optional<std::reference_wrapper<const SchemaField>> MapType::GetFieldByNameCaseInsensitive(
233-
std::string_view name) const {
234-
auto lower_name_view = name | std::views::transform(::tolower);
235-
auto lower_key_view = kKeyName | std::views::transform(tolower);
236-
auto lower_value_view = kValueName | std::views::transform(tolower);
233+
std::optional<std::reference_wrapper<const SchemaField>>
234+
MapType::GetFieldByNameCaseInsensitive(std::string_view name) const {
235+
auto lower_name_view = name | std::views::transform(::tolower);
236+
auto lower_key_view = kKeyName | std::views::transform(::tolower);
237+
auto lower_value_view = kValueName | std::views::transform(::tolower);
237238
if (std::ranges::equal(lower_key_view, lower_name_view)) {
238239
return key();
239240
} else if (std::ranges::equal(lower_value_view, lower_name_view)) {

src/iceberg/type.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <string>
3333
#include <unordered_map>
3434
#include <vector>
35+
#include <cctype>
3536

3637
#include "iceberg/iceberg_export.h"
3738
#include "iceberg/schema_field.h"
@@ -194,7 +195,7 @@ class ICEBERG_EXPORT MapType : public NestedType {
194195
std::string_view name) const override;
195196
std::optional<std::reference_wrapper<const SchemaField>> GetFieldByNameCaseInsensitive(
196197
std::string_view name) const override;
197-
198+
198199
protected:
199200
bool Equals(const Type& other) const override;
200201

test/type_test.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ TEST(TypeTest, List) {
320320
ASSERT_THAT(list.GetFieldById(5), ::testing::Optional(field));
321321
ASSERT_THAT(list.GetFieldByIndex(0), ::testing::Optional(field));
322322
ASSERT_THAT(list.GetFieldByName("element"), ::testing::Optional(field));
323-
ASSERT_THAT(list.GetFieldByNameCaseInsensitive("ELEMENT"), ::testing::Optional(field));
323+
ASSERT_THAT(list.GetFieldByNameCaseInsensitive("ELEMENT"),
324+
::testing::Optional(field));
324325

325326
ASSERT_EQ(std::nullopt, list.GetFieldById(0));
326327
ASSERT_EQ(std::nullopt, list.GetFieldByIndex(1));
@@ -355,7 +356,6 @@ TEST(TypeTest, Map) {
355356
ASSERT_THAT(map.GetFieldByNameCaseInsensitive("KEY"), ::testing::Optional(key));
356357
ASSERT_THAT(map.GetFieldByNameCaseInsensitive("VALUE"), ::testing::Optional(value));
357358

358-
359359
ASSERT_EQ(std::nullopt, map.GetFieldById(0));
360360
ASSERT_EQ(std::nullopt, map.GetFieldByIndex(2));
361361
ASSERT_EQ(std::nullopt, map.GetFieldByIndex(-1));
@@ -396,8 +396,10 @@ TEST(TypeTest, Struct) {
396396
ASSERT_THAT(struct_.GetFieldByIndex(1), ::testing::Optional(field2));
397397
ASSERT_THAT(struct_.GetFieldByName("foo"), ::testing::Optional(field1));
398398
ASSERT_THAT(struct_.GetFieldByName("bar"), ::testing::Optional(field2));
399-
ASSERT_THAT(struct_.GetFieldByNameCaseInsensitive("FOO"), ::testing::Optional(field1));
400-
ASSERT_THAT(struct_.GetFieldByNameCaseInsensitive("Bar"), ::testing::Optional(field2));
399+
ASSERT_THAT(struct_.GetFieldByNameCaseInsensitive("FOO"),
400+
::testing::Optional(field1));
401+
ASSERT_THAT(struct_.GetFieldByNameCaseInsensitive("Bar"),
402+
::testing::Optional(field2));
401403

402404
ASSERT_EQ(std::nullopt, struct_.GetFieldById(0));
403405
ASSERT_EQ(std::nullopt, struct_.GetFieldByIndex(2));

0 commit comments

Comments
 (0)