Giter Site home page Giter Site logo

Comments (11)

lukebakken avatar lukebakken commented on July 28, 2024

Hello,

Please provide this information:

  • Your table definition
  • The data you have inserted
  • Your query
  • The version of Ruby you're using
  • The version of Riak TS you're using
  • The version of the riak-client gem you're using

Most likely, this is due to rounding in the Float type in Ruby, but I would like to be able to reproduce it.

Thank you.

from riak-ruby-client.

bobhall avatar bobhall commented on July 28, 2024

Table definition:

CREATE TABLE test_bob (                                                                                                                                                           
  bob_id sint64 not null,                                                                                                                                                         
  creation_time timestamp not null,                                                                                                                                               
  PRIMARY KEY ((bob_id, quantum(creation_time, 7, d)),                                                                                                                            
  bob_id,                                                                                                                                                                         
  creaton_time)                                                                                                                                                                   
)

Data I inserted:


riak-shell(7)>select * from test_bob where bob_id=11 and creation_time > 1459382400000 and creation_time < 1459468800000;
+------+-------------+
|bob_id|creation_time|
+------+-------------+
|  11  |1459443822778|
|  11  |1459444070103|
+------+-------------+

Query:

select * from test_bob where bob_id=11 and creation_time > 1459382400000 and creation_time < 1459468800000

Ruby version:
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]

Riak TS Version:
1.3

riak-client version:
2.3.2

Then I print the result of my query (using strftime) and I get:

11, 2016-03-31T10:03:42.778000Z
11, 2016-03-31T10:07:50.102999Z

... And I expect:
11, 2016-03-31T10:03:42.778000Z
11, 2016-03-31T10:07:50.103000Z

from riak-ruby-client.

lukebakken avatar lukebakken commented on July 28, 2024

One last question, just so I'm using the same code, what strftime format are you using?

from riak-ruby-client.

bobhall avatar bobhall commented on July 28, 2024

"%Y-%m-%dT%H:%M:%S.%6NZ"

from riak-ruby-client.

lukebakken avatar lukebakken commented on July 28, 2024

I'm glad I asked!

from riak-ruby-client.

lukebakken avatar lukebakken commented on July 28, 2024

Looks like I'm going to have to make the code a bit more intelligent:

irb(main):010:0> Time.at(1459444070103 / 1000.0).strftime("%Y-%m-%dT%H:%M:%S.%6NZ")
=> "2016-03-31T10:07:50.102999Z"

Basically, this is what is done here

from riak-ruby-client.

lukebakken avatar lukebakken commented on July 28, 2024

@bobhall I did some more research in irb. Note that using to_f on the Time object returned by Time.at does return the correct value for milliseconds, but that using the nsec and usec methods reveals the difference due to the use of a float to store the value internally.

I recently changed the Python client to not auto-convert timestamp values to datetime objects since using integer values preserves accuracy. I could add a similar feature to the Ruby client to use integers rather than converting to Time objects. What do you think?

irb(main):019:0> time = Time.at(1459444070103.to_f / 1000)
=> 2016-03-31 10:07:50 -0700
irb(main):020:0> time.to_f
=> 1459444070.103
irb(main):021:0> time.nsec
=> 102999925
irb(main):022:0> time.usec
=> 102999
irb(main):024:0> time.strftime("%Y-%m-%dT%H:%M:%S.%6NZ")
=> "2016-03-31T10:07:50.102999Z"

from riak-ruby-client.

lukebakken avatar lukebakken commented on July 28, 2024

@bobhall the following code should resolve your issue, I'll get it in the next release:

irb(main):010:0> t = 1459444070103
=> 1459444070103
irb(main):011:0> secs = t / 1000
=> 1459444070
irb(main):012:0> millis = t % 1000
=> 103
irb(main):013:0> Time.at(secs, millis * 1000)
=> 2016-03-31 10:07:50 -0700
irb(main):014:0> time = Time.at(secs, millis * 1000)
=> 2016-03-31 10:07:50 -0700
irb(main):015:0> time.strftime("%Y-%m-%dT%H:%M:%S.%6NZ")
=> "2016-03-31T10:07:50.103000Z"

I am still interested to know if you would find it useful to have optional conversion from Riak TS timestamp to Time objects.

from riak-ruby-client.

bobhall avatar bobhall commented on July 28, 2024

@lukebakken , thanks for the workaround.

It would be great to have an option to have RiakTS timestamps convert to Time objects or integers. It might be cool to have that be an option on the init method of the client itself (so you don't have to pass convert_to_time=true over and over, for example). The same option would be cool to have in the Python client as well.

from riak-ruby-client.

lukebakken avatar lukebakken commented on July 28, 2024

Yep, that's how the Python client works.

I'll implement something similar in Ruby, and, to be consistent, will make the default to be no auto conversion. That is the default in the Python client since it is used as middleware between Riak TS and other data consumers, so the conversion added a performance cost.

from riak-ruby-client.

bobhall avatar bobhall commented on July 28, 2024

Ah, so it does!

from riak-ruby-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.