Comments (11)
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.
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.
One last question, just so I'm using the same code, what strftime
format are you using?
from riak-ruby-client.
"%Y-%m-%dT%H:%M:%S.%6NZ"
from riak-ruby-client.
I'm glad I asked!
from riak-ruby-client.
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.
@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.
@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.
@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.
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.
Ah, so it does!
from riak-ruby-client.
Related Issues (20)
- Riak search instructions do not work [JIRA: CLIENTS-404] HOT 1
- Cannot connect to Riak via SSL HOT 9
- Don't error on empty TsQueryResp responses [JIRA: CLIENTS-620] HOT 1
- Timestamp value parsing [JIRA: CLIENTS-822] HOT 3
- Finding objects by integer keys fail badly [JIRA: CLIENTS-865] HOT 2
- Improve error when non-String is used as a key [JIRA: CLIENTS-868]
- Some tests fail running under OSX [JIRA: CLIENTS-890] HOT 1
- `getaddrinfo': can't convert Hash into String (TypeError) [JIRA: CLIENTS-924] HOT 8
- Update support for 1.9.3 [JIRA: CLIENTS-947] HOT 1
- Errors when using beefcake 1.2.0 [JIRA: CLIENTS-949] HOT 1
- Need clean way to handle deleted objects and tombstones [JIRA: CLIENTS-965] HOT 5
- Implement saving bucket type properties [JIRA: CLIENTS-1010]
- Ruby tests fails with latests TS version [JIRA: CLIENTS-1052] HOT 2
- wait_for_finish should not be public [JIRA: CLIENTS-1054] HOT 4
- GSet Support - Ruby [JIRA: CLIENTS-1062]
- Add warning and safety mechanism to prevent unintentional list [buckets | keys] operations [JIRA: CLIENTS-1071] HOT 1
- Ruby content.meta does not correctly apply X-Riak-Meta- prefix [JIRA: CLIENTS-1109] HOT 3
- Use RIAK Client in Multithreaded application
- Interview partners for research about communication in GitHub projects wanted
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from riak-ruby-client.