thibaultcha / lua-cassandra

Pure Lua driver for Apache Cassandra
https://thibaultcha.github.io/lua-cassandra
Other
98 stars 35 forks source link

attempt to concatenate local 'val' (a table value) #98

Closed AxelWal closed 7 years ago

AxelWal commented 7 years ago

In Openresty i Implemented the Cluster version like shown here: http://thibaultcha.github.io/lua-cassandra/examples/intro.lua.html Querys certain exchanged with my own ones. On the 'my_module.execute' i get this exception: 2017/06/02 13:13:09 [error] 5987#5987: *37 lua entry thread aborted: runtime error: /usr/local/share/lua/5.1/cassandra/cql.lua:296: attempt to concatenate local 'val' (a table value) stack traceback: coroutine 0: /usr/local/share/lua/5.1/cassandra/cql.lua: in function 'marshaller' /usr/local/share/lua/5.1/cassandra/cql.lua:508: in function 'write_long_string' /usr/local/share/lua/5.1/cassandra/cql.lua:1043: in function 'build_body' /usr/local/share/lua/5.1/cassandra/cql.lua:938: in function 'build_frame' /usr/local/share/lua/5.1/cassandra/init.lua:149: in function 'send' /usr/local/share/lua/5.1/resty/cassandra/cluster.lua:751: in function 'execute' /var/www/lua/xxx.lua:3: in function </var/www/lua/xxx.lua:1>

I Installed via luarocks and later updated to the Code from the Git. But the Error Stays. When i directly implement the Cluster Class then it works.

Works: local cassandra = require "cassandra" local Cluster = require 'resty.cassandra.cluster' dbclient = Cluster.new { shm = 'cassandra', -- defined by the lua_shared_dict directive contact_points = {'cassandra.master.demo'}, auth = cassandra.auth_providers.plain_text("cassuser", "XXX"), keyspace = 'shop' }
local fallback_id = (dbclient:execute("select * from users"))

Does not work: local cassandra = require "cassandra" local cassandradb = require "cassandradb" cassandradb.init_cluster { shm = 'cassandra', -- defined by the lua_shared_dict directive contact_points = {'cassandra.master.demo'}, auth = cassandra.auth_providers.plain_text("cassuser", "XXX"), keyspace = 'shop' }
local fallback_id = (dbclient:execute("select * from users"))

-- -- cassandradb.lua

local cassandra = require "cassandra" local Cluster = require "resty.cassandra.cluster"

-- cluster instance as an upvalue local cluster

local _M = {}

function _M.init_cluster(...) cluster = assert(Cluster.new(...))

assert(cluster:refresh()) end

function _M.execute(...) return cluster:execute(...) end

return _M

thibaultcha commented 7 years ago

You defined your function as:

function _M.execute(...)
return cluster:execute(...)
end

But you are calling it with:

dbclient:execute()

Hence, you are passing dbclient as the first argument to :execute(), which is a table and not a string as the driver expects. Call it like so instead:

dbclient.execute()