3030
3131namespace iceberg {
3232
33- Result<std::optional<std::reference_wrapper< const SchemaField>>>
34- NestedType::GetFieldByName ( std::string_view name) const {
35- return GetFieldByName (name, true );
33+ Result<std::optional<SchemaFieldConstRef>> NestedType::GetFieldByName (
34+ std::string_view name) const {
35+ return GetFieldByName (name, /* case_sensitive= */ true );
3636}
3737
3838StructType::StructType (std::vector<SchemaField> fields) : fields_(std::move(fields)) {}
@@ -48,22 +48,22 @@ std::string StructType::ToString() const {
4848 return repr;
4949}
5050std::span<const SchemaField> StructType::fields () const { return fields_; }
51- Result<std::optional<std::reference_wrapper< const SchemaField> >> StructType::GetFieldById (
51+ Result<std::optional<SchemaFieldConstRef >> StructType::GetFieldById (
5252 int32_t field_id) const {
5353 ICEBERG_RETURN_UNEXPECTED (InitFieldById ());
5454 auto it = field_by_id_.find (field_id);
5555 if (it == field_by_id_.end ()) return std::nullopt ;
5656 return it->second ;
5757}
58- Result<std::optional<std::reference_wrapper< const SchemaField>>>
59- StructType::GetFieldByIndex ( int32_t index) const {
58+ Result<std::optional<SchemaFieldConstRef>> StructType::GetFieldByIndex (
59+ int32_t index) const {
6060 if (index < 0 || static_cast <size_t >(index) >= fields_.size ()) {
61- return std:: nullopt ;
61+ return InvalidArgument ( " index {} is out of range[0, {}) " , index, fields_. size ()) ;
6262 }
6363 return fields_[index];
6464}
65- Result<std::optional<std::reference_wrapper< const SchemaField>>>
66- StructType::GetFieldByName ( std::string_view name, bool case_sensitive) const {
65+ Result<std::optional<SchemaFieldConstRef>> StructType::GetFieldByName (
66+ std::string_view name, bool case_sensitive) const {
6767 if (case_sensitive) {
6868 ICEBERG_RETURN_UNEXPECTED (InitFieldByName ());
6969 auto it = field_by_name_.find (name);
@@ -93,8 +93,8 @@ Status StructType::InitFieldById() const {
9393 for (const auto & field : fields_) {
9494 auto it = field_by_id_.try_emplace (field.field_id (), field);
9595 if (!it.second ) {
96- return NotAllowed (" Duplicate field id found: {} (prev name: {}, curr name: {})" ,
97- field.field_id (), it.first ->second .get ().name (), field.name ());
96+ return InvalidSchema (" Duplicate field id found: {} (prev name: {}, curr name: {})" ,
97+ field.field_id (), it.first ->second .get ().name (), field.name ());
9898 }
9999 }
100100 return {};
@@ -106,9 +106,9 @@ Status StructType::InitFieldByName() const {
106106 for (const auto & field : fields_) {
107107 auto it = field_by_name_.try_emplace (field.name (), field);
108108 if (!it.second ) {
109- return NotAllowed (" Duplicate field name found: {} (prev id: {}, curr id: {})" ,
110- it.first ->first , it.first ->second .get ().field_id (),
111- field.field_id ());
109+ return InvalidSchema (" Duplicate field name found: {} (prev id: {}, curr id: {})" ,
110+ it.first ->first , it.first ->second .get ().field_id (),
111+ field.field_id ());
112112 }
113113 }
114114 return {};
@@ -121,9 +121,9 @@ Status StructType::InitFieldByLowerCaseName() const {
121121 auto it =
122122 field_by_lowercase_name_.try_emplace (StringUtils::ToLower (field.name ()), field);
123123 if (!it.second ) {
124- return NotAllowed (" Duplicate field name found: {} (prev id: {}, curr id: {})" ,
125- it.first ->first , it.first ->second .get ().field_id (),
126- field.field_id ());
124+ return InvalidSchema (" Duplicate field name found: {} (prev id: {}, curr id: {})" ,
125+ it.first ->first , it.first ->second .get ().field_id (),
126+ field.field_id ());
127127 }
128128 }
129129 return {};
@@ -149,29 +149,28 @@ std::string ListType::ToString() const {
149149 return repr;
150150}
151151std::span<const SchemaField> ListType::fields () const { return {&element_, 1 }; }
152- Result<std::optional<std::reference_wrapper< const SchemaField> >> ListType::GetFieldById (
152+ Result<std::optional<SchemaFieldConstRef >> ListType::GetFieldById (
153153 int32_t field_id) const {
154154 if (field_id == element_.field_id ()) {
155155 return std::cref (element_);
156156 }
157157 return std::nullopt ;
158158}
159- Result<std::optional<std::reference_wrapper<const SchemaField>>>
160- ListType::GetFieldByIndex (int index) const {
159+ Result<std::optional<SchemaFieldConstRef>> ListType::GetFieldByIndex (int index) const {
161160 if (index == 0 ) {
162161 return std::cref (element_);
163162 }
164- return std:: nullopt ;
163+ return InvalidArgument ( " index {} is out of range[0, {}) " , index, 1 ) ;
165164}
166- Result<std::optional<std::reference_wrapper< const SchemaField> >> ListType::GetFieldByName (
165+ Result<std::optional<SchemaFieldConstRef >> ListType::GetFieldByName (
167166 std::string_view name, bool case_sensitive) const {
168167 if (case_sensitive) {
169- if (name == element_. name () ) {
168+ if (name == kElementName ) {
170169 return std::cref (element_);
171170 }
172171 return std::nullopt ;
173172 }
174- if (StringUtils::ToLower (name) == StringUtils::ToLower (element_. name ()) ) {
173+ if (StringUtils::ToLower (name) == kElementName ) {
175174 return std::cref (element_);
176175 }
177176 return std::nullopt ;
@@ -209,25 +208,23 @@ std::string MapType::ToString() const {
209208 return repr;
210209}
211210std::span<const SchemaField> MapType::fields () const { return fields_; }
212- Result<std::optional<std::reference_wrapper<const SchemaField>>> MapType::GetFieldById (
213- int32_t field_id) const {
211+ Result<std::optional<SchemaFieldConstRef>> MapType::GetFieldById (int32_t field_id) const {
214212 if (field_id == key ().field_id ()) {
215213 return key ();
216214 } else if (field_id == value ().field_id ()) {
217215 return value ();
218216 }
219217 return std::nullopt ;
220218}
221- Result<std::optional<std::reference_wrapper<const SchemaField>>> MapType::GetFieldByIndex (
222- int32_t index) const {
219+ Result<std::optional<SchemaFieldConstRef>> MapType::GetFieldByIndex (int32_t index) const {
223220 if (index == 0 ) {
224221 return key ();
225222 } else if (index == 1 ) {
226223 return value ();
227224 }
228- return std:: nullopt ;
225+ return InvalidArgument ( " index {} is out of range[0, {}) " , index, 2 ) ;
229226}
230- Result<std::optional<std::reference_wrapper< const SchemaField> >> MapType::GetFieldByName (
227+ Result<std::optional<SchemaFieldConstRef >> MapType::GetFieldByName (
231228 std::string_view name, bool case_sensitive) const {
232229 if (case_sensitive) {
233230 if (name == kKeyName ) {
@@ -237,9 +234,9 @@ Result<std::optional<std::reference_wrapper<const SchemaField>>> MapType::GetFie
237234 }
238235 return std::nullopt ;
239236 }
240- if (StringUtils::ToLower (name) == StringUtils::ToLower ( kKeyName ) ) {
237+ if (StringUtils::ToLower (name) == kKeyName ) {
241238 return key ();
242- } else if (StringUtils::ToLower (name) == StringUtils::ToLower ( kValueName ) ) {
239+ } else if (StringUtils::ToLower (name) == kValueName ) {
243240 return value ();
244241 }
245242 return std::nullopt ;
0 commit comments