Closed Reg1234 closed 8 years ago
This library is tested against Cassandra 3.7 but I haven't been using it in production against 3.7 just yet. Please let me know of any issue you might encounter.
Sure thing, thanks
Hi there,
I'm having an issue passing timestamp parameters to my Cassandra 3.7. - here is my code (with IP address omitted)
local cassandra = require "cassandra" local peer = assert(cassandra.new { host = "IPaddress", port = 9042, keyspace = "das" }) peer:settimeout(5000) assert(peer:connect())
local query = select * from data_env where time > ? and time <= ? limit 5000 ALLOW FILTERING
local start_date_time = 1439017200000 local end_date_time = 1504338900000
local params = {{start_date_time},{end_date_time}}
local rows,err = assert(peer:execute(query, params, {page_size = 2000}))
Error:
2016/08/15 15:08:15 [error] 13578#0: *384 lua entry thread aborted: runtime error: handler.lua:115: [Invalid] Expected 8 or 0 byte long for date (14) stack traceback: coroutine 0: [C]: in function 'assert'
I can run this query successfully usng cql -
cqlsh:das> select * from data_env where time > 1439017200000 and time <= 1504338900000 limit 5000 ALLOW FILTERING;
instrument_id | campaign_id | time | azaspiracid | campaign | camphechlor | day | domoic_acid | heavy_metals | hour | lat | lon | microcystin | month | naphthalene | pfos | saxitoxine | year ---------------+-------------+---------------------------------+-------------+------------+-------------+-----+-------------+--------------+------+--------+--------+-------------+-------+-------------+------+------------+------ 1 | 1 | 2016-08-02 13:53:28.409000+0000 | null | Galway | 89.9 | 2 | 8 | 2 | 13 | 3345.1 | 1111.5 | null | 8 | 5.5 | 6.5 | 1 | 2016
(6 rows)
I wonder is this a 3.7 compatibility issue?
Cheers, Regina
You need to properly serialize the parameters given to :execute()
when they are not inlined in the query. Additionally, you are giving 2 tables instead of 2 numbers. local params = {start_date_time, end_date_time}
would be more logical, but still unsafe.
Try:
local cassandra = require "cassandra"
local peer = assert(cassandra.new {
host = "IPaddress",
port = 9042,
keyspace = "das"
})
peer:settimeout(5000)
assert(peer:connect())
local query = "select * from data_env where time > ? and time <= ? ALLOW FILTERING"
local start_date_time = 1439017200000
local end_date_time = 1504338900000
local params = {
cassandra.timestamp(start_date_time),
cassandra.timestamp(end_date_time)
}
local rows = assert(peer:execute(query, params, {
page_size = 2000
}))
btw: no need to specify both a limit
statement and a page_size
option. Also, no need to store the second return value of assert()
since if rows
is nil
, it will throw an error anyways.
See the type_serializers section of the documentation too.
That worked perfectly once I serialised the parameters as you outlined above.
Thanks a million for your help!
Hi from a newbie to lua,
Is Cassandra version 3.7 combined with cql version 3.4.2 supported?
Thanks. R