-
Notifications
You must be signed in to change notification settings - Fork 70
feat: add find field (by name) support to NestedType #194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+279
−100
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7abe6e1
feat: add case-insensitive field lookup for StructType, ListType, and…
18aef13
fix comments
9597b87
fix comments
3ef372a
fix comments
2fb136e
refactor: simplify ICEBERG_RETURN_UNEXPECTED macro implementation
2ce9d53
fix comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
| #include <vector> | ||
|
|
||
| #include "iceberg/iceberg_export.h" | ||
| #include "iceberg/result.h" | ||
| #include "iceberg/schema_field.h" | ||
| #include "iceberg/util/formattable.h" | ||
|
|
||
|
|
@@ -69,6 +70,9 @@ class ICEBERG_EXPORT PrimitiveType : public Type { | |
|
|
||
| /// \brief A data type that has child fields. | ||
| class ICEBERG_EXPORT NestedType : public Type { | ||
| protected: | ||
nullccxsy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| using SchemaFieldConstRef = std::reference_wrapper<const SchemaField>; | ||
|
|
||
| public: | ||
| bool is_primitive() const override { return false; } | ||
| bool is_nested() const override { return true; } | ||
|
|
@@ -78,20 +82,23 @@ class ICEBERG_EXPORT NestedType : public Type { | |
| /// \brief Get a field by field ID. | ||
| /// | ||
| /// \note This is O(1) complexity. | ||
| [[nodiscard]] virtual std::optional<std::reference_wrapper<const SchemaField>> | ||
| GetFieldById(int32_t field_id) const = 0; | ||
| [[nodiscard]] virtual Result<std::optional<SchemaFieldConstRef>> GetFieldById( | ||
| int32_t field_id) const = 0; | ||
| /// \brief Get a field by index. | ||
| /// | ||
| /// \note This is O(1) complexity. | ||
| [[nodiscard]] virtual std::optional<std::reference_wrapper<const SchemaField>> | ||
| GetFieldByIndex(int32_t index) const = 0; | ||
| /// \brief Get a field by name (case-sensitive). Behavior is undefined if | ||
| [[nodiscard]] virtual Result<std::optional<SchemaFieldConstRef>> GetFieldByIndex( | ||
| int32_t index) const = 0; | ||
| /// \brief Get a field by name. Return an error Status if | ||
| /// the field name is not unique; prefer GetFieldById or GetFieldByIndex | ||
| /// when possible. | ||
| /// | ||
| /// \note This is currently O(n) complexity. | ||
| [[nodiscard]] virtual std::optional<std::reference_wrapper<const SchemaField>> | ||
| GetFieldByName(std::string_view name) const = 0; | ||
| /// \note This is O(1) complexity. | ||
| [[nodiscard]] virtual Result<std::optional<SchemaFieldConstRef>> GetFieldByName( | ||
| std::string_view name, bool case_sensitive) const = 0; | ||
| /// \brief Get a field by name (case-sensitive). | ||
| [[nodiscard]] Result<std::optional<SchemaFieldConstRef>> GetFieldByName( | ||
| std::string_view name) const; | ||
| }; | ||
|
|
||
| /// \defgroup type-nested Nested Types | ||
|
|
@@ -109,18 +116,27 @@ class ICEBERG_EXPORT StructType : public NestedType { | |
| std::string ToString() const override; | ||
|
|
||
| std::span<const SchemaField> fields() const override; | ||
| std::optional<std::reference_wrapper<const SchemaField>> GetFieldById( | ||
| Result<std::optional<SchemaFieldConstRef>> GetFieldById( | ||
| int32_t field_id) const override; | ||
| std::optional<std::reference_wrapper<const SchemaField>> GetFieldByIndex( | ||
| Result<std::optional<SchemaFieldConstRef>> GetFieldByIndex( | ||
| int32_t index) const override; | ||
| std::optional<std::reference_wrapper<const SchemaField>> GetFieldByName( | ||
| std::string_view name) const override; | ||
| Result<std::optional<SchemaFieldConstRef>> GetFieldByName( | ||
| std::string_view name, bool case_sensitive) const override; | ||
nullccxsy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| using NestedType::GetFieldByName; | ||
|
|
||
| protected: | ||
| bool Equals(const Type& other) const override; | ||
| // TODO(nullccxsy): Lazy initialization has concurrency issues, need to add proper | ||
| // synchronization mechanism | ||
| Status InitFieldById() const; | ||
| Status InitFieldByName() const; | ||
| Status InitFieldByLowerCaseName() const; | ||
|
|
||
| protected: | ||
nullccxsy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| std::vector<SchemaField> fields_; | ||
| std::unordered_map<int32_t, size_t> field_id_to_index_; | ||
| mutable std::unordered_map<int32_t, SchemaFieldConstRef> field_by_id_; | ||
nullccxsy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mutable std::unordered_map<std::string_view, SchemaFieldConstRef> field_by_name_; | ||
| mutable std::unordered_map<std::string, SchemaFieldConstRef> field_by_lowercase_name_; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to wait for #180 and rebase on it to use |
||
| }; | ||
|
|
||
| /// \brief A data type representing a list of values. | ||
|
|
@@ -140,12 +156,13 @@ class ICEBERG_EXPORT ListType : public NestedType { | |
| std::string ToString() const override; | ||
|
|
||
| std::span<const SchemaField> fields() const override; | ||
| std::optional<std::reference_wrapper<const SchemaField>> GetFieldById( | ||
| Result<std::optional<SchemaFieldConstRef>> GetFieldById( | ||
| int32_t field_id) const override; | ||
| std::optional<std::reference_wrapper<const SchemaField>> GetFieldByIndex( | ||
| Result<std::optional<SchemaFieldConstRef>> GetFieldByIndex( | ||
| int32_t index) const override; | ||
| std::optional<std::reference_wrapper<const SchemaField>> GetFieldByName( | ||
| std::string_view name) const override; | ||
| Result<std::optional<SchemaFieldConstRef>> GetFieldByName( | ||
| std::string_view name, bool case_sensitive) const override; | ||
nullccxsy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| using NestedType::GetFieldByName; | ||
|
|
||
| protected: | ||
| bool Equals(const Type& other) const override; | ||
|
|
@@ -172,12 +189,13 @@ class ICEBERG_EXPORT MapType : public NestedType { | |
| std::string ToString() const override; | ||
|
|
||
| std::span<const SchemaField> fields() const override; | ||
| std::optional<std::reference_wrapper<const SchemaField>> GetFieldById( | ||
| Result<std::optional<SchemaFieldConstRef>> GetFieldById( | ||
| int32_t field_id) const override; | ||
| std::optional<std::reference_wrapper<const SchemaField>> GetFieldByIndex( | ||
| Result<std::optional<SchemaFieldConstRef>> GetFieldByIndex( | ||
| int32_t index) const override; | ||
| std::optional<std::reference_wrapper<const SchemaField>> GetFieldByName( | ||
| std::string_view name) const override; | ||
| Result<std::optional<SchemaFieldConstRef>> GetFieldByName( | ||
| std::string_view name, bool case_sensitive) const override; | ||
nullccxsy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| using NestedType::GetFieldByName; | ||
|
|
||
| protected: | ||
| bool Equals(const Type& other) const override; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.