Implement open_cursor() with minimal features#14
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an initial Table.select() implementation to iterate over table record IDs using a Groonga table cursor, with a small test to validate basic behavior. This is a foundational API addition intended to be extended later with query/search and additional options.
Changes:
- Add
Table.select()generator that opens a Groonga table cursor and yields record IDs. - Expose Groonga table cursor APIs in
grn_table.pxdfor Cython usage. - Add a new test verifying
select()returns IDs in expected order for a simple table.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| testing/test_table.py | Adds a basic test asserting select() yields record IDs [1, 2]. |
| grnpy/table.pyx | Implements Table.select() using grn_table_cursor_open/next/close. |
| grnpy/grn_table.pxd | Declares Groonga table cursor types/constants/functions needed by select(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return id | ||
|
|
||
| # TODO: Searching using `query` and adding options (e.g. `limit`). | ||
| def select(self): |
There was a problem hiding this comment.
We should not use select for grn_table_cursor_open() based API.
We should use it for grn_table_select().
There was a problem hiding this comment.
Since it was an iterator rather than a select, I changed the name.
| ctypedef struct grn_table_cursor: | ||
| pass | ||
|
|
||
| cdef int BY_ID "GRN_CURSOR_BY_ID" |
There was a problem hiding this comment.
Can we define this in grn_table_cursor not grn_table?
| def set(self, grn_id id, value): | ||
| self._set_value(id, value) | ||
|
|
||
| def __iter__(self): |
There was a problem hiding this comment.
Can we specify options such as offset and limit with this API?
How about with table.open_cursor as cursor or something?
| cdef Context context | ||
| if self._cursor is NULL: | ||
| return | ||
| context = self._context | ||
| grn_table_cursor_close(context.unwrap(), self._cursor) | ||
| self._cursor = NULL |
Getting the other field values will be implemented later.
Getting the other field values will be implemented later.