Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tarantool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
tarantool
Commits
72cc0d8f
Commit
72cc0d8f
authored
8 years ago
by
lenkis
Browse files
Options
Downloads
Patches
Plain Diff
Fixes #1539 Fix formatting in code samples
Fixed Lua code block formatting in box_index.rst
parent
620b89f4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/sphinx/book/box/box_index.rst
+46
-31
46 additions, 31 deletions
doc/sphinx/book/box/box_index.rst
with
46 additions
and
31 deletions
doc/sphinx/book/box/box_index.rst
+
46
−
31
View file @
72cc0d8f
...
...
@@ -354,12 +354,16 @@ API is a direct binding to corresponding methods of index objects of type
that the search will return tuples where the first value
is greater than or equal to 'XY'. The conditional statement
within the loop ensures that the looping will stop when the
first two letters are not 'XY'. |br|
:codenormal:`for _,tuple in box.space.t.index.primary:pairs("XY",{iterator = "GE"}) do` |br|
|nbsp| |nbsp| :codenormal:`if (string.sub(tuple[1], 1, 2) ~= "XY") then break end` |br|
|nbsp| |nbsp| :codenormal:`print(tuple)` |br|
|nbsp| |nbsp| :codenormal:`end` |br|
first two letters are not 'XY'.
.. code-block:: lua
for tuple in
box.space.t.index.primary:pairs("XY",{iterator = "GE"}) do
if (string.sub(tuple[1], 1, 2) ~= "XY") then break end
print(tuple)
end
**Third Example of index pairs():**
This Lua code finds all the tuples whose primary key values are
...
...
@@ -370,11 +374,15 @@ API is a direct binding to corresponding methods of index objects of type
that the search will return tuples where the first value
is greater than or equal to 1000. The conditional statement
within the loop ensures that the looping will stop when the
first value is greater than 1999. |br|
:codenormal:`for _,tuple in box.space.t2.index.primary:pairs(1000,{iterator = "GE"}) do` |br|
|nbsp| |nbsp| :codenormal:`if (tuple[1] > 1999) then break end` |br|
|nbsp| |nbsp| :codenormal:`print(tuple)` |br|
|nbsp| |nbsp| :codenormal:`end` |br|
first value is greater than 1999.
.. code-block:: lua
for tuple in
box.space.t2.index.primary:pairs(1000,{iterator = "GE"}) do
if (tuple[1] > 1999) then break end
print(tuple)
end
.. _index_object_select:
...
...
@@ -834,26 +842,30 @@ Lua functions `os.date()`_ and `string.sub()`_.
=================================================================
Here is an example that shows how to build one's own iterator.
The paged_iter function is an "iterator function", which will only be
The
:func:`
paged_iter
`
function is an "iterator function", which will only be
understood by programmers who have read the Lua
manual section
`Iterators and Closures <https://www.lua.org/pil/7.1.html>`_.
It does paginated retrievals, that is, it returns 10
tuples at a time from a table named "t", whose
primary key was defined with :codenormal:`create_index('primary',{parts={1,'STR'}})`. |br|
|nbsp| |nbsp| :codenormal:`function paged_iter(search_key, tuples_per_page)` |br|
|nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`local iterator_string = "GE"` |br|
|nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`return function ()` |br|
|nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`local page = box.space.t.index[0]:select(search_key,` |br|
|nbsp| |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`{iterator = iterator_string, limit=tuples_per_page})` |br|
|nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`if #page == 0 then return nil end` |br|
|nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`search_key = page[#page][1]` |br|
|nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`iterator_string = "GT"` |br|
|nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`return page` |br|
|nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`end` |br|
|nbsp| |nbsp| :codenormal:`end`
Programmers who use paged_iter do not need to know
primary key was defined with
:codenormal:`create_index('primary',{parts={1,'STR'}})`.
.. code-block:: lua
function paged_iter(search_key, tuples_per_page)
local iterator_string = "GE"
return function ()
local page = box.space.t.index[0]:select(search_key,
{iterator = iterator_string, limit=tuples_per_page})
if #page == 0 then return nil end
search_key = page[#page][1]
iterator_string = "GT"
return page
end
end
Programmers who use :func:`paged_iter` do not need to know
why it works, they only need to know that, if they
call it within a loop, they will get 10 tuples
at a time until there are no more tuples. In this
...
...
@@ -861,11 +873,14 @@ example the tuples are merely printed, a page at a time.
But it should be simple to change the functionality,
for example by yielding after each retrieval, or
by breaking when the tuples fail to match some
additional criteria. |br|
|nbsp| |nbsp| :codenormal:`for page in paged_iter("X", 10) do` |br|
|nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`print("New Page. Number Of Tuples = " .. #page)` |br|
|nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`for i=1,#page,1 do print(page[i]) end` |br|
|nbsp| |nbsp| :codenormal:`end`
additional criteria.
.. code-block:: lua
for page in paged_iter("X", 10) do
print("New Page. Number Of Tuples = " .. #page)
for i=1,#page,1 do print(page[i]) end
end
.. _RTREE:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment