-
Notifications
You must be signed in to change notification settings - Fork 12
iterator: cleanup iterator module and implement cass_iterator_type #230
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
Conversation
query_result.rs needed to import metadata structs just because iterator methods were defined here. I also removed the commented CassIterator methods. I don't see a purpose of having this comment. I'll do the same for other types as well in later commit.
658e47c
to
657ca19
Compare
657ca19
to
07cd160
Compare
v1.1: Fixed the typo in the comment |
07cd160
to
185a92b
Compare
scylla-rust-wrapper/src/iterator.rs
Outdated
#[no_mangle] | ||
pub unsafe extern "C" fn cass_iterator_type(iterator: *mut CassIterator) -> CassIteratorType { | ||
let iter = BoxFFI::as_ref(iterator); | ||
|
||
// TODO: Adjust CassIterator enum hierarchy (done later in this PR). | ||
match iter { | ||
CassIterator::CassResultIterator(_) => CassIteratorType::CASS_ITERATOR_TYPE_RESULT, | ||
CassIterator::CassRowIterator(_) => CassIteratorType::CASS_ITERATOR_TYPE_ROW, | ||
CassIterator::CassCollectionIterator(_) => CassIteratorType::CASS_ITERATOR_TYPE_COLLECTION, | ||
CassIterator::CassMapIterator(_) => CassIteratorType::CASS_ITERATOR_TYPE_MAP, | ||
CassIterator::CassUdtIterator(_) => CassIteratorType::CASS_ITERATOR_TYPE_USER_TYPE_FIELD, | ||
CassIterator::CassSchemaMetaIterator(_) => { | ||
CassIteratorType::CASS_ITERATOR_TYPE_KEYSPACE_META | ||
} | ||
CassIterator::CassKeyspaceMetaTableIterator(_) => { | ||
CassIteratorType::CASS_ITERATOR_TYPE_TABLE_META | ||
} | ||
CassIterator::CassKeyspaceMetaUserTypeIterator(_) => { | ||
CassIteratorType::CASS_ITERATOR_TYPE_TYPE_META | ||
} | ||
CassIterator::CassKeyspaceMetaViewIterator(_) => { | ||
CassIteratorType::CASS_ITERATOR_TYPE_MATERIALIZED_VIEW_META | ||
} | ||
CassIterator::CassTableMetaIterator(_) => CassIteratorType::CASS_ITERATOR_TYPE_COLUMN_META, | ||
CassIterator::CassViewMetaIterator(_) => CassIteratorType::CASS_ITERATOR_TYPE_COLUMN_META, | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit: "iterator: implement cass_iterator_type"
What does it mean that it needs to be adjusted? I've read the commit message, I've read the code, and I don't know what it means.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned in my other comment, I want to adjust CassIterator
enum hierarchy so each variant corresponds to the variant in CassIteratorType
enum. I'll put this information in the code comment and commit message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Later commits explained that it is about naming of the variants.
I don't think this commit needs to mention that. Naming change is unrelated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Later commits explained that it is about naming of the variants. I don't think this commit needs to mention that. Naming change is unrelated.
Not only the naming, but structure as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"iterator: add CassTupleIterator variant "
Commit message says that we need a way to distinguish iterator over tuple from iterator over other collection, but does not explain why. Please explain - it is not obvious to me at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because from user's perspective these are two different kinds of iterators. One created from cass_iterator_from_collection
, and the other created from cass_iterator_from_tuple
. In our case, the underlying structure is the same, but for the user these are not the same. Why? Because there is CASS_ITERATOR_TYPE_COLLETION
and CASS_ITERATOR_TYPE_TUPLE
. This is the exact reason why we need to distinguish them - to return corresponding CassIteratorType
in cass_iterator_type
method.
I'll put more context to the commit message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit: "iterator: introduce CassColumnMeta iterator "
Again, why should we do this? Is there some difference in behavior between those iterators? Does it allow some nice code cleanups?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of this new variant seems inconsistent.
We have CassKeyspaceMetaTableIterator, which iterator over Tables in a Keyspace metadata.
There are 2 other similar variants (for udts and views).
We have CassTableMetaIterator, which iterates over stuff (columns) in a Table
We have CassViewMetaIterator, which iterates over stuff (columns) in a View
Now you introduce CassColumnsMetaIterator - interpreting the name the same as others, I would assume it iterates over some stuff in Column, but it iterates over columns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit: "iterator: introduce CassColumnMeta iterator "
Again, why should we do this? Is there some difference in behavior between those iterators? Does it allow some nice code cleanups?
Notice that before this PR we used CassIterator::CassTableMetaIterator
for two things:
- as you noticed, to iterate over columns metadata (
cass_iterator_columns_from_table_meta
) - to iterate over materialized views meta (
cass_iterator_materialized_views_from_table_meta
)
But there is other way to create an iterator over columns. Namely cass_iterator_columns_from_materialized_view_meta
.
And now, both iterators cass_iterator_columns_from_table_meta
and cass_iterator_columns_from_materialized_view_meta
should return CASS_ITERATOR_TYPE_COLUMN_META
when cass_iterator_type
is called on them.
This is why I introduce the additional layer (CassIterator::CassColumnsMetaIterator
). I want CassIterator
top-level hierarchy directly correspond to CassIteratorType
enum variants.
scylla-rust-wrapper/src/iterator.rs
Outdated
CassKeyspaceMetaUserTypeIterator(CassKeyspaceMetaIterator<'result_or_schema>), | ||
CassKeyspaceMetaViewIterator(CassKeyspaceMetaIterator<'result_or_schema>), | ||
CassMaterializedViewsMetaIterator(CassMaterializedViewsMetaIterator<'result_or_schema>), | ||
CassColumnsMetaIterator(CassColumnsMetaIterator<'result_or_schema>), | ||
CassTableMetaIterator(CassTableMetaIterator<'result_or_schema>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto about inconsistent naming.
// Iterators derived from CassResult. | ||
// Naming convention of the variants: the name of the collection. | ||
/// Iterator over rows in a result. | ||
Result(CassResultIterator<'result_or_schema>), | ||
/// Iterator over columns (values) in a row. | ||
Row(CassRowIterator<'result_or_schema>), | ||
/// Iterator over values in a collection. | ||
Collection(CassCollectionIterator<'result_or_schema>), | ||
/// Iterator over key-value pairs in a map. | ||
Map(CassMapIterator<'result_or_schema>), | ||
/// Iterator over values in a tuple. | ||
Tuple(CassCollectionIterator<'result_or_schema>), | ||
|
||
// Iterators derived from CassSchemaMeta. | ||
// Naming convention of the variants: name of item in the collection (plural). | ||
/// Iterator over fields in UDT. | ||
UdtFields(CassUdtIterator<'result_or_schema>), | ||
/// Iterator over keyspaces in schema metadata. | ||
KeyspacesMeta(CassSchemaMetaIterator<'result_or_schema>), | ||
/// Iterator over tables in keyspace metadata. | ||
TablesMeta(CassKeyspaceMetaIterator<'result_or_schema>), | ||
/// Iterator over UDTs in keyspace metadata. | ||
UserTypes(CassKeyspaceMetaIterator<'result_or_schema>), | ||
/// Iterator over materialized views in either keyspace or table metadata. | ||
MaterializedViewsMeta(CassMaterializedViewsMetaIterator<'result_or_schema>), | ||
/// Iterator over columns metadata in either table or view metadata. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... ok so you try fix the consistency here, after introducing inconsistency before.
Previously we had one naming convention, now we have too. Why can't we have one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming conventions are derived from CassColumnType
enum variants. I don't know why, but this is the convention chosen by cpp-driver. For result-derived iterators, it's the name of the collection we iterate over. For schema-based iterators, it's the name of the items in the collection we iterate over.
As a side note, it took me a while to notice the difference. When I first saw that iterator returned from cass_iterator_from_result
is CASS_ITERATOR_TYPE_RESULT
, I assumed that iterator returned from cass_iterator_keyspaces_from_schema_meta
, will be CASS_ITERATOR_TYPE_SCHEMA_META
or sth like that. But no, its type is CASS_ITERATOR_TYPE_KEYSPACE_META
(because we iterate over keyspaces metadata from schema metadata).
It still needs to be adjusted, but we need to adjust CassIterator enum hierarchy first to fix it. In the end, I want CassIterator enum top-level hierarchy directly correspond to CassIteratorType enum hierarchy. For example, notice that we currently don't return `CASS_ITERATOR_TYPE_TUPLE`. This is because iterator created from tuple is currently hidden under `CassIterator::CassCollectionIterator`.
cass_iterator_from_tuple creates a CassCollectionIterator, to reuse its logic. We need to have a way to distinguish such iterator from iterator created by `cass_iterator_from_collection`. Thanks to that, we can now return `CASS_ITERATOR_TYPE_TUPLE` from `cass_iterator_type` for iterator that was created via `cass_iterator_from_tuple`.
Iterator over columns metadata can be created from either materialized view metadata or table metadata. Let's express this relationship by introducing an additional enum. Thanks to that, all iterators that are of type `CASS_ITERATOR_TYPE_COLUMN_META` are placed under one enum.
Iterator over materialized views can be created from either keyspace metadata or table metadata. Let's express this relationship by introducing an additional enum. Thanks to that, all iterators that are of type `CASS_ITERATOR_TYPE_MATERIALIZED_VIEW_META` are placed under one enum.
These variants were moved to other enums.
The variant naming conventions come from CASS_ITERATOR_TYPE values that correspond to each variant. I also ditched the `Cass` prefix and `Iterator` suffix for variant names. These are redundant.
185a92b
to
89a106c
Compare
v1.2: Adjusted commit messages so they better explain why |
This PR mostly does some cleanups/small refactors. In addition, it implements
cass_iterator_type
method.Fixes: #47
Pre-review checklist
[ ] I have implemented Rust unit tests for the features/changes introduced.[ ] I have enabled appropriate tests in.github/workflows/build.yml
ingtest_filter
.[ ] I have enabled appropriate tests in.github/workflows/cassandra.yml
ingtest_filter
.