[Tarantool-patches] [PATCH resend v2 06/11] box, datetime: datetime comparison for indices

Oleg Babin olegrok at tarantool.org
Thu Jul 29 21:56:46 MSK 2021


Thanks for your patch. One question below.


Also update with arithmetic operations doesn't work.


```

tarantool> box.space.dt:update({v}, {{'+', 2, 3}})
---
- error: 'Argument type in operation ''+'' on field 2 does not match 
field type: expected
     a number'
...

tarantool> box.space.dt:update({v}, {{'+', 2, dt.week(1)}})
---
- error: unsupported Lua type 'cdata'
...

```


On 28.07.2021 13:34, Timur Safin via Tarantool-patches wrote:
> * storage hints implemented for datetime_t values;
> * proper comparison for indices of datetime type.
>
>
> diff --git a/test/engine/datetime.result b/test/engine/datetime.result
> new file mode 100644
> index 000000000..3ff474dee
> --- /dev/null
> +++ b/test/engine/datetime.result
> @@ -0,0 +1,77 @@
> +-- test-run result file version 2
> +env = require('test_run')
> + | ---
> + | ...
> +test_run = env.new()
> + | ---
> + | ...
> +engine = test_run:get_cfg('engine')
> + | ---
> + | ...
> +
> +date = require('datetime')
> + | ---
> + | ...
> +
> +_ = box.schema.space.create('T', {engine = engine})
> + | ---
> + | ...
> +_ = box.space.T:create_index('pk', {parts={1,'datetime'}})
> + | ---
> + | ...
> +
> +box.space.T:insert{date('1970-01-01')}\
> +box.space.T:insert{date('1970-01-02')}\
> +box.space.T:insert{date('1970-01-03')}\
> +box.space.T:insert{date('2000-01-01')}
> + | ---
> + | ...
> +
> +o = box.space.T:select{}
> + | ---
> + | ...
> +assert(tostring(o[1][1]) == '1970-01-01T00:00Z')
> + | ---
> + | - true
> + | ...
> +assert(tostring(o[2][1]) == '1970-01-02T00:00Z')
> + | ---
> + | - true
> + | ...
> +assert(tostring(o[3][1]) == '1970-01-03T00:00Z')
> + | ---
> + | - true
> + | ...
> +assert(tostring(o[4][1]) == '2000-01-01T00:00Z')
> + | ---
> + | - true
> + | ...
> +
> +for i = 1,16 do\
> +    box.space.T:insert{date.now()}\
> +end
> + | ---
> + | ...
> +
> +a = box.space.T:select{}
> + | ---
> + | ...
> +err = nil
> + | ---
> + | ...
> +for i = 1, #a - 1 do\
> +    if tostring(a[i][1]) >= tostring(a[i+1][1]) then\

Why do you compare string representation but not values itself?


> +        err = {a[i][1], a[i+1][1]}\
> +        break\
> +    end\
> +end
> + | ---
> + | ...
> +
> +err
> + | ---
> + | - null
> + | ...
> +box.space.T:drop()
> + | ---
> + | ...
>


More information about the Tarantool-patches mailing list