diff --git a/doc/sphinx/book/box/index.rst b/doc/sphinx/book/box/index.rst index 368dcf76fa43820a76d4b5e276bb239402fec1f2..a4481d185118f487bb45c998e23df1b139920239 100644 --- a/doc/sphinx/book/box/index.rst +++ b/doc/sphinx/book/box/index.rst @@ -112,7 +112,7 @@ all other indexes are called “secondary†indexes. An index definition may include identifiers of tuple fields and their expected types. The allowed types for indexed fields are NUM -(64-bit unsigned integer between -9,223,372,036,854,775,807 and +(unsigned integer between 0 and 18,446,744,073,709,551,615), or STR (string, any sequence of octets), or ARRAY (a series of numbers for use with :ref:`RTREE indexes <RTREE>`. Take our example, which has the request: @@ -120,7 +120,7 @@ Take our example, which has the request: i = s:create_index('primary', {type = 'hash', parts = {1, 'NUM'}}) The effect is that, for all tuples in tester, -field number 1 must exist and must be a 64-bit integer. +field number 1 must exist and must contain an unsigned integer. Space definitions and index definitions are stored permanently in system spaces. It is possible to add, drop, or alter the @@ -157,19 +157,24 @@ Tarantool can work with numbers, strings, booleans, tables, and userdata. .. _table: http://www.lua.org/pil/2.5.html .. _userdata: http://www.lua.org/pil/28.1.html -In Lua a "number" is double-precision floating-point; -however, for database storage Tarantool uses MsgPack rules, -and MsgPack allows for both integer and floating-point values. -So Tarantool will store a number as a float if the value -contains a decimal point, and otherwise will store as an integer. -Tarantool can store signed numbers, but not in indexed fields --- when a field has a 'NUM' index, the values must be unsigned -64-bit integers. Large numbers can be entered with exponential -notation, for example 9e99. Large integers greater than -100,000,000,000,000 (1e14) should be entered with the -:func:`tonumber64 <tonumber64>` -function. Storage is variable-length, so the smallest number +In Lua a "number" is double-precision floating-point, +but Tarantool allows both integer and floating-point values. +Tarantool will try to store a number as floating-point if +the value contains a decimal point or is very large (greater than 100 quadrillion = 1e14), +otherwise Tarantool will store it as an integer. +To ensure that even very large numbers will be treated as +integers, use the :func:`tonumber64 <tonumber64>` +function, or the LL (Long Long) suffix, or the ULL +(Unsigned Long Long) suffix. Here are examples of numbers +using regular notation, exponential notation, the ULL suffix, +and the tonumber64 function: +-55, -2.7e+20, 100000000000000ULL, tonumber64('18446744073709551615'). + +For database storage Tarantool uses MsgPack rules. +Storage is variable-length, so the smallest number requires only one byte but the largest number requires nine bytes. +When a field has a 'NUM' index, all values must be unsigned +integers between 0 and 18,446,744,073,709,551,615. A "string" is a variable-length sequence of bytes, usually represented with alphanumeric characters inside single quotes. diff --git a/doc/sphinx/reference/json.rst b/doc/sphinx/reference/json.rst index c1d5c20d3e60cbd2f4c600e3156ebf415521201d..977827293ed7189e2674bc741f9b73705f107fb3 100644 --- a/doc/sphinx/reference/json.rst +++ b/doc/sphinx/reference/json.rst @@ -16,31 +16,31 @@ The json package provides JSON manipulation routines. It is based on the :return: the original value reformatted as a JSON string. :rtype: string - .. code-block:: lua - - tarantool> json=require('json') - --- - ... - tarantool> json.encode(123) - --- - - '123' - ... - tarantool> json.encode({123}) - --- - - '[123]' - ... - tarantool> json.encode({123, 234, 345}) - --- - - '[123,234,345]' - ... - tarantool> json.encode({abc = 234, cde = 345}) - --- - - '{"cde":345,"abc":234}' - ... - tarantool> json.encode({hello = {'world'}}) - --- - - '{"hello":["world"]}' - ... + | EXAMPLE + | + | :codenormal:`tarantool>` :codebold:`json=require('json')` + | :codenormal:`---` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`json.encode(123)` + | :codenormal:`---` + | :codenormal:`- '123'` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`json.encode({123})` + | :codenormal:`---` + | :codenormal:`- '[123]'` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`json.encode({123, 234, 345})` + | :codenormal:`---` + | :codenormal:`- '[123,234,345]'` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`json.encode({abc = 234, cde = 345})` + | :codenormal:`---` + | :codenormal:`- '{"cde":345,"abc":234}'` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`json.encode({hello = {'world'}})` + | :codenormal:`---` + | :codenormal:`- '{"hello":["world"]}'` + | :codenormal:`...` .. function:: decode(string) @@ -50,23 +50,23 @@ The json package provides JSON manipulation routines. It is based on the :return: the original contents formatted as a Lua table. :rtype: table - .. code-block:: lua - - tarantool> json=require('json') - --- - ... - tarantool> json.decode('123') - --- - - 123 - ... - tarantool> json.decode('[123, "hello"]')[2] - --- - - hello - ... - tarantool> json.decode('{"hello": "world"}').hello - --- - - world - ... + | EXAMPLE + | + | :codenormal:`tarantool>` :codebold:`json=require('json')` + | :codenormal:`---` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`json.decode('123')` + | :codenormal:`---` + | :codenormal:`- 123` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`json.decode('[123, "hello"]')[2]` + | :codenormal:`---` + | :codenormal:`- hello` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`json.decode('{"hello": "world"}').hello` + | :codenormal:`---` + | :codenormal:`- world` + | :codenormal:`...` .. _json-null: @@ -74,26 +74,26 @@ The json package provides JSON manipulation routines. It is based on the A value comparable to Lua "nil" which may be useful as a placeholder in a tuple. - .. code-block:: lua - - tarantool> -- When nil is assigned to a Lua-table field, the field is null - tarantool> {nil, 'a', 'b'} - - - null - - a - - b - ... - tarantool> -- When json.NULL is assigned to a Lua-table field, the field is json.NULL - tarantool> {json.NULL, 'a', 'b'} - --- - - - null - - a - - b - ... - tarantool> -- When json.NULL is assigned to a JSON field, the field is null - tarantool> json.encode({field2 = json.NULL, field1 = 'a', field3 = 'c'}) - --- - - '{"field2":null,"field1":"a","field3":"c"}' - ... + | EXAMPLE + | + | :codenormal:`tarantool>` :codebold:`-- When nil is assigned to a Lua-table field, the field is null` + | :codenormal:`tarantool>` :codebold:`{nil, 'a', 'b'}` + | :codenormal:`- - null` + | :codenormal:`- a` + | :codenormal:`- b` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`-- When json.NULL is assigned to a Lua-table field, the field is json.NULL` + | :codenormal:`tarantool>` :codebold:`{json.NULL, 'a', 'b'}` + | :codenormal:`---` + | :codenormal:`- - null` + | :codenormal:`- a` + | :codenormal:`- b` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`-- When json.NULL is assigned to a JSON field, the field is null` + | :codenormal:`tarantool>` :codebold:`json.encode({field2 = json.NULL, field1 = 'a', field3 = 'c'})` + | :codenormal:`---` + | :codenormal:`- '{"field2":null,"field1":"a","field3":"c"}'` + | :codenormal:`...` .. _Lua-CJSON package by Mark Pulford: http://www.kyne.com.au/~mark/software/lua-cjson.php .. _the official documentation: http://www.kyne.com.au/~mark/software/lua-cjson-manual.html diff --git a/doc/sphinx/reference/other.rst b/doc/sphinx/reference/other.rst index 3942560bdd7817e4e19eab4a0242eac61d09b059..e1c041686e78f77718b3d29354df7067990c2ff2 100644 --- a/doc/sphinx/reference/other.rst +++ b/doc/sphinx/reference/other.rst @@ -10,26 +10,26 @@ number use floating-point arithmetic.) The ``tonumber64()`` function is added by Tarantool; the name is global. - .. code-block:: lua - - tarantool> type(123456789012345), type(tonumber64(123456789012345)) - --- - - number - - number - ... - tarantool> i = tonumber64('1000000000') - --- - ... - tarantool> type(i), i / 2, i - 2, i * 2, i + 2, i % 2, i ^ 2 - --- - - number - - 500000000 - - 999999998 - - 2000000000 - - 1000000002 - - 0 - - 1000000000000000000 - ... + | EXAMPLE + | + | :codenormal:`tarantool>` :codebold:`type(123456789012345), type(tonumber64(123456789012345))` + | :codenormal:`---` + | :codenormal:`- number` + | :codenormal:`- number` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`i = tonumber64('1000000000')` + | :codenormal:`---` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`type(i), i / 2, i - 2, i * 2, i + 2, i % 2, i ^ 2` + | :codenormal:`---` + | :codenormal:`- number` + | :codenormal:`- 500000000` + | :codenormal:`- 999999998` + | :codenormal:`- 2000000000` + | :codenormal:`- 1000000002` + | :codenormal:`- 0` + | :codenormal:`- 1000000000000000000` + | :codenormal:`...` .. function:: dostring(lua-chunk-string [, lua-chunk-string-argument ...]) @@ -44,32 +44,32 @@ :return: whatever is returned by the Lua code chunk. :except: If there is a compilation error, it is raised as a Lua error. - .. code-block:: lua - - tarantool> dostring('abc') - --- - error: '[string "abc"]:1: ''='' expected near ''<eof>''' - ... - tarantool> dostring('return 1') - --- - - 1 - ... - tarantool> dostring('return ...', 'hello', 'world') - --- - - hello - - world - ... - tarantool> console = require('console'); console.delimiter('!') - tarantool> -- This means ignore line feeds until next '!' - tarantool> -- Use `double square brackets`_ to enclose multi-line literal here! - tarantool> dostring([[local f = function(key) - -> t = box.space.tester:select{key}; - -> if t ~= nil then return t[1] else return nil end - -> end - -> return f(...)]], 1)! - --- - - null - ... - tarantool> console.delimiter('')! + | EXAMPLE + | + | :codenormal:`tarantool>` :codebold:`dostring('abc')` + | :codenormal:`---` + | :codenormal:`error: '[string "abc"]:1: ''='' expected near ''<eof>'''` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`dostring('return 1')` + | :codenormal:`---` + | :codenormal:`- 1` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`dostring('return ...', 'hello', 'world')` + | :codenormal:`---` + | :codenormal:`- hello` + | :codenormal:`- world` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`console = require('console'); console.delimiter('!')` + | :codenormal:`tarantool>` :codebold:`-- This means ignore line feeds until next '!'` + | :codenormal:`tarantool>` :codebold:`-- Use` `double square brackets`_ :codebold:`to enclose multi-line literal here!` + | :codenormal:`tarantool>` :codebold:`dostring([[local f = function(key)` + | |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`->` :codebold:`t = box.space.tester:select{key};` + | |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`->` :codebold:`if t ~= nil then return t[1] else return nil end` + | |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`->` :codebold:`end` + | |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`->` :codebold:`return f(...)]], 1)!` + | :codenormal:`---` + | :codenormal:`- null` + | :codenormal:`...` + | :codenormal:`tarantool> console.delimiter('')!` .. _double square brackets: http://www.lua.org/pil/2.4.html diff --git a/doc/sphinx/reference/pickle.rst b/doc/sphinx/reference/pickle.rst index c4a0747545490c09e246057ee2d51f87976408c9..39e0844f5ecc45c8cbe4a24c8f8f70dcd1c37d8b 100644 --- a/doc/sphinx/reference/pickle.rst +++ b/doc/sphinx/reference/pickle.rst @@ -60,35 +60,36 @@ :except: unknown format specifier. - .. code-block:: lua - - tarantool> pickle = require('pickle') - --- - ... - tarantool> box.space.tester:insert{0, 'hello world'} - --- - - [0, 'hello world'] - ... - tarantool> box.space.tester:update({0}, {{'=', 2, 'bye world'}}) - --- - - [0, 'bye world'] - ... - tarantool> box.space.tester:update({0}, {{'=', 2, pickle.pack('iiA', 0, 3, 'hello')}}) - --- - - [0, "\0\0\0\0\x03\0\0\0hello"] - ... - tarantool> box.space.tester:update({0}, {{'=', 2, 4}}) - --- - - [0, 4] - ... - tarantool> box.space.tester:update({0}, {{'+', 2, 4}}) - --- - - [0, 8] - ... - tarantool> box.space.tester:update({0}, {{'^', 2, 4}}) - --- - - [0, 12] - ... + | EXAMPLE + | + | + | :codenormal:`tarantool>` :codebold:`pickle = require('pickle')` + | :codenormal:`---` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`box.space.tester:insert{0, 'hello world'}` + | :codenormal:`---` + | :codenormal:`- [0, 'hello world']` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`box.space.tester:update({0}, {{'=', 2, 'bye world'}})` + | :codenormal:`---` + | :codenormal:`- [0, 'bye world']` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`box.space.tester:update({0}, {{'=', 2, pickle.pack('iiA', 0, 3, 'hello')}})` + | :codenormal:`---` + | :codenormal:`- [0, "\0\0\0\0\x03\0\0\0hello"]` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`box.space.tester:update({0}, {{'=', 2, 4}})` + | :codenormal:`---` + | :codenormal:`- [0, 4]` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`box.space.tester:update({0}, {{'+', 2, 4}})` + | :codenormal:`---` + | :codenormal:`- [0, 8]` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`box.space.tester:update({0}, {{'^', 2, 4}})` + | :codenormal:`---` + | :codenormal:`- [0, 12]` + | :codenormal:`...` .. function:: unpack(format, binary-string) @@ -100,40 +101,39 @@ :return: A list of strings or numbers. :rtype: table - .. code-block:: lua - - tarantool> pickle = require('pickle') - --- - ... - tarantool> -- this means following commands must end with '!' - tarantool> console = require('console'); console.delimiter('!') - tarantool> tuple = box.space.tester:replace{0}! - --- - ... - tarantool> string.len(tuple[1])! - --- - - 1 - ... - tarantool> pickle.unpack('b', tuple[1])! - --- - - 48 - ... - tarantool> pickle.unpack('bsi', pickle.pack('bsi', 255, 65535, 4294967295))! - --- - - 255 - - 65535 - - 4294967295 - ... - tarantool> pickle.unpack('ls', pickle.pack('ls', tonumber64('18446744073709551615'), 65535))! - --- - - 18446744073709551615 - - 65535 - ... - tarantool> num, str, num64 = pickle.unpack('sAl', pickle.pack('sAl', 666, 'string', - -> tonumber64('666666666666666')))! - --- - ... - tarantool> console.delimiter('') -- back to normal: commands end with line feed! - + | EXAMPLE + | + | :codenormal:`tarantool>` :codebold:`pickle = require('pickle')` + | :codenormal:`---` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`-- this means following commands must end with '!'` + | :codenormal:`tarantool>` :codebold:`console = require('console'); console.delimiter('!')` + | :codenormal:`tarantool>` :codebold:`tuple = box.space.tester:replace{0}!` + | :codenormal:`---` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`string.len(tuple[1])!` + | :codenormal:`---` + | :codenormal:`- 1` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`pickle.unpack('b', tuple[1])!` + | :codenormal:`---` + | :codenormal:`- 48` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`pickle.unpack('bsi', pickle.pack('bsi', 255, 65535, 4294967295))!` + | :codenormal:`---` + | :codenormal:`- 255` + | :codenormal:`- 65535` + | :codenormal:`- 4294967295` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`pickle.unpack('ls', pickle.pack('ls', tonumber64('18446744073709551615'), 65535))!` + | :codenormal:`---` + | :codenormal:`- 18446744073709551615` + | :codenormal:`- 65535` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`num, str, num64 = pickle.unpack('sAl', pickle.pack('sAl', 666, 'string',` + | |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| |nbsp| :codenormal:`->` :codebold:`tonumber64('666666666666666')))!` + | :codenormal:`---` + | :codenormal:`...` + | :codenormal:`tarantool>` :codebold:`console.delimiter('') -- back to normal: commands end with line feed!` .. _pack: http://perldoc.perl.org/functions/pack.html