Skip to content

Commit

Permalink
Index options API
Browse files Browse the repository at this point in the history
  • Loading branch information
andreyaksenov committed Jul 6, 2023
1 parent 6c889b2 commit 4df28c1
Show file tree
Hide file tree
Showing 17 changed files with 370 additions and 313 deletions.
13 changes: 10 additions & 3 deletions doc/code_snippets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,26 @@ To test all the examples, go to the `doc/code_snippets` folder and execute the `
.rocks/bin/luatest
```

To run a specific example with tests, use the `luatest` command with the `-c` option, for example:
To test the examples from the specified directory, pass its relative path to the `luatest` command:

```shell
.rocks/bin/luatest test/transactions
```

To test a specific example with the `stdout` output enabled, use the `luatest` command with the `-c` option, for example:

```shell
.rocks/bin/luatest -c test/http_client/get_test.lua
```

You can also run the `httpbin` service locally using Docker:
Note that the HTTP client samples (placed in `test/http_client`) use the `httpbin` service.
You can run `httpbin` locally using Docker to stabilize test results:

```shell
docker run -p 80:80 kennethreitz/httpbin
```

In this case, replace `https://httpbin.org` links with `http://127.0.0.1` to test the examples.
In this case, you need to replace `https://httpbin.org` links with `http://127.0.0.1`.


## Referencing code snippets
Expand Down
9 changes: 4 additions & 5 deletions doc/concepts/data_model/indexes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ while an ``‘integer’`` index contains *any* integer values.

The default field type is ``'unsigned'`` and the default index type is TREE.
Although ``'nil'`` is not a legal indexed field type, indexes may contain `nil`
:ref:`as a non-default option <box_space-is_nullable>`.
:ref:`as a non-default option <key_part_is_nullable>`.

To learn more about field types, check the
:ref:`Field type details <index_box_field_type_details>` section and the more elaborate
:ref:`Details about index field types <details_about_index_field_types>` in the reference.
:ref:`Field type details <index_box_field_type_details>` section.

.. container:: table

Expand Down Expand Up @@ -92,7 +91,7 @@ To learn more about field types, check the
- TREE, BITSET, or HASH
* - ``'varbinary'``
- :ref:`varbinary <index-box_bin>`
- TREE, HASH, or BITSET (since version 2.7)
- TREE, HASH, or BITSET (since version :doc:`2.7.1 </release/2.7.1>`)
* - ``'uuid'``
- :ref:`uuid <index-box_uuid>`
- TREE or HASH
Expand Down Expand Up @@ -153,7 +152,7 @@ We give an overview of index features in the following table:
- \+
- \+

* - :ref:`is_nullable <box_space-is_nullable>`
* - :ref:`is_nullable <key_part_is_nullable>`
- \+
- \-
- \-
Expand Down
76 changes: 60 additions & 16 deletions doc/concepts/data_model/value_store.rst
Original file line number Diff line number Diff line change
Expand Up @@ -188,31 +188,43 @@ Example: ``nil``.

.. _index-box_boolean:

**boolean**. A boolean is either ``true`` or ``false``.
**boolean**

A boolean is either ``true`` or ``false``.

Example: ``true``.

.. _index-box_integer:

**integer**. The Tarantool integer type is for integers between
**integer**

The Tarantool integer type is for integers between
-9223372036854775808 and 18446744073709551615, which is about 18 quintillion.
This type corresponds to the number type in Lua and to the integer type in MsgPack.

Example: ``-2^63``.

.. _index-box_unsigned:

**unsigned**. The Tarantool unsigned type is for integers between
**unsigned**

The Tarantool unsigned type is for integers between
0 and 18446744073709551615. So it is a subset of integer.

Example: ``123456``.

.. _index-box_double:

**double**. The double field type exists
**double**

The double field type exists
mainly to be equivalent to Tarantool/SQL's
:ref:`DOUBLE data type <sql_data_type_double>`.
In `msgpuck.h <https://github.com/rtsisyk/msgpuck>`_ (Tarantool's interface to MsgPack),
the storage type is ``MP_DOUBLE`` and the size of the encoded value is always 9 bytes.
In Lua, fields of the double type can only contain non-integer numeric values and
cdata values with double floating-point numbers.

Examples: ``1.234``, ``-44``, ``1.447e+44``.

To avoid using the wrong kind of values inadvertently, use
Expand All @@ -222,6 +234,7 @@ For example, instead of
use
``ffi = require('ffi') ...``
:samp:`{space_object}:insert`:code:`({ffi.cast('double',`:samp:`{value}`:code:`)})`.

Example:

.. code-block:: tarantoolsession
Expand All @@ -243,7 +256,9 @@ Tarantool/SQL does

.. _index-box_number:

**number**. The Tarantool number field may have both
**number**

The Tarantool number field may have both
integer and floating-point values, although in Lua a ``number``
is a double-precision floating-point.

Expand All @@ -262,15 +277,20 @@ In this case, the number will be stored as `cdata`_.

.. _index-box_decimal:

**decimal**. The Tarantool decimal type is stored as a :ref:`MsgPack ext <msgpack_ext-decimal>` (Extension).
**decimal**

The Tarantool decimal type is stored as a :ref:`MsgPack ext <msgpack_ext-decimal>` (Extension).
Values with the decimal type are not floating-point values although
they may contain decimal points.
They are exact with up to 38 digits of precision.

Example: a value returned by a function in the :ref:`decimal <decimal>` module.

.. _index-box_datetime:

**datetime**. Introduced in :tarantool-release:`2.10.0`.
**datetime**

Introduced in :tarantool-release:`2.10.0`.
The Tarantool ``datetime`` type facilitates operations with date and time,
accounting for leap years or the varying number of days in a month.
It is stored as a :ref:`MsgPack ext <msgpack_ext-datetime>` (Extension).
Expand All @@ -280,7 +300,10 @@ For more information, see :doc:`Module datetime </reference/reference_lua/dateti

.. _index-box_interval:

**interval**. Introduced in :tarantool-release:`2.10.0`.
**interval**

**Since:** :tarantool-release:`2.10.0`

The Tarantool ``interval`` type represents periods of time.
They can be added to or subtracted from ``datetime`` values or each other.
Operations with this data type use code from `c-dt <https://github.com/tarantool/c-dt>`_, a third-party library.
Expand All @@ -289,7 +312,9 @@ For more information, see :doc:`Module datetime </reference/reference_lua/dateti

.. _index-box_string:

**string**. A string is a variable-length sequence of bytes, usually represented with
**string**

A string is a variable-length sequence of bytes, usually represented with
alphanumeric characters inside single quotes. In both Lua and MsgPack, strings
are treated as binary data, with no attempts to determine a string's
character set or to perform any string conversion -- unless there is an optional
Expand All @@ -299,19 +324,25 @@ collation rules applied.
For example, numbers are ordered by their point on the number line, so 2345 is
greater than 500; meanwhile, strings are ordered by the encoding of the first
byte, then the encoding of the second byte, and so on, so ``'2345'`` is less than ``'500'``.

Example: ``'A, B, C'``.

.. _index-box_bin:

**bin**. A bin (binary) value is not directly supported by Lua but there is
**bin**

A bin (binary) value is not directly supported by Lua but there is
a Tarantool type ``varbinary`` which is encoded as MsgPack binary.
For an (advanced) example showing how to insert varbinary into a database,
see the Cookbook Recipe for :ref:`ffi_varbinary_insert <cookbook-ffi_varbinary_insert>`.

Example: ``"\65 \66 \67"``.

.. _index-box_uuid:

**uuid**. The Tarantool uuid type is used for
**uuid**

The Tarantool uuid type is used for
:ref:`Universally Unique Identifiers <uuid-module>`.
Since version :doc:`2.4.1 </release/2.4.1>` Tarantool stores
``uuid`` values as a :ref:`MsgPack ext <msgpack_ext-uuid>` (Extension).
Expand All @@ -320,31 +351,44 @@ Example: ``64d22e4d-ac92-4a23-899a-e5934af5479``.

.. _index-box_array:

**array**. An array is represented in Lua with ``{...}`` (`braces <https://www.lua.org/pil/11.1.html>`_).
**array**

An array is represented in Lua with ``{...}`` (`braces <https://www.lua.org/pil/11.1.html>`_).
Examples: lists of numbers representing points in geometric figures:
``{10, 11}``, ``{3, 5, 9, 10}``.

**table**. Lua tables with string keys are stored as MsgPack maps;
**table**

Lua tables with string keys are stored as MsgPack maps;
Lua tables with integer keys starting with 1 are stored as MsgPack arrays.
Nils may not be used in Lua tables; the workaround is to use
:ref:`box.NULL <box-null>`.

Example: a ``box.space.tester:select()`` request will return a Lua table.

**tuple**. A tuple is a light reference to a MsgPack array stored in the database.
**tuple**

A tuple is a light reference to a MsgPack array stored in the database.
It is a special type (cdata) to avoid conversion to a Lua table on retrieval.
A few functions may return tables with multiple tuples. For tuple examples,
see :ref:`box.tuple <box_tuple>`.

.. _index-box_scalar:

**scalar**. Values in a scalar field can be boolean, integer, unsigned, double,
**scalar**

Values in a scalar field can be boolean, integer, unsigned, double,
number, decimal, string, uuid, or varbinary; but not array, map, or tuple.

Examples: ``true``, ``1``, ``'xxx'``.

.. _index-box_any:

**any**. Values in a field of this type can be boolean, integer, unsigned, double,
**any**

Values in a field of this type can be boolean, integer, unsigned, double,
number, decimal, string, uuid, varbinary, array, map, or tuple.

Examples: ``true``, ``1``, ``'xxx'``, ``{box.NULL, 0}``.

Examples of insert requests with different field types:
Expand Down
2 changes: 1 addition & 1 deletion doc/how-to/db/indexes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Be careful! Using ``select()`` for huge spaces hangs your instance.

An index definition may also include identifiers of tuple fields
and their expected **types**. See allowed indexed field types in section
:ref:`Details about indexed field types <details_about_index_field_types>`:
:ref:`Details about indexed field types <index-box_indexed-field-types>`:

.. cssclass:: highlight
.. parsed-literal::
Expand Down
2 changes: 1 addition & 1 deletion doc/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Here are some of Tarantool's key characteristics:

* **Advanced indexing**: :ref:`composite indexes <concepts-data_model_indexes>`,
:ref:`locale support <index-collation>`,
indexing by :ref:`nested fields and arrays <details_about_index_field_types>`
indexing by :ref:`nested fields and arrays <index-box_indexed-field-types>`

* **Compute close to data**: :ref:`Lua server <concepts-application_server>`
and Just-In-Time compiler on board
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/reference_lua/box_index/parts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ index_object:parts()
.. data:: parts

An array describing the index fields. To learn more about the index field
types, refer to :ref:`this table <box_space-index_field_types>`.
types, refer to :ref:`this table <index-box_indexed-field-types>`.

:rtype: table

Expand Down
Loading

0 comments on commit 4df28c1

Please sign in to comment.