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

Timur Safin tsafin at tarantool.org
Sat Jul 31 01:18:45 MSK 2021


Hello Oleg,


: From: Oleg Babin <olegrok at tarantool.org>
: Subject: Re: [Tarantool-patches] [PATCH resend v2 06/11] box, datetime:
: datetime comparison for indices
: 
: 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'
: ...
: 
: ```

Oh, shit, I didn't take those operations into considerations.
Do they work similarly with decimal?


: 
: 
: 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?

Good question! Yeah, there should be original values compared, without
stringization. (And in this case, by some reason, it's easier to 
reproduce problem of incorrect sort ofder with sequential times from
date.now(). Which used to be reproduced only on some configs at GH)

: 
: 
: > +        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