jbochi / lua-resty-cassandra

Pure Lua Cassandra client using CQL binary protocol

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to iterate over key/value pairs

thibaultcha opened this issue · comments

Hi,

I noticed that in parse_rows here, every row is added to two keys in the final result:

row[j] = value
row[columns[j].name] = value

Thus leading to results such as:

{ 
  { "3.2.0", "3", "2.1.2",
  cql_version = "3.2.0",
  native_protocol_version = "3",
  release_version = "2.1.2"
}

I was wondering what purpose this behaviour served, and if an option to only retrieve this part:

{
  cql_version = "3.2.0",
  native_protocol_version = "3",
  release_version = "2.1.2"
}

could be considered.

Hi,

This allows the fields to be accessed by position or by column name, which
is also possible with the official Python driver:
http://datastax.github.io/python-driver/getting_started.html#executing-queries

I try to mimic its behavior whenever possible.

Would you mind elaborating why you want to avoid those extra keys? Are you
concerned about memory usage or do you want to iterate over all keys? Maybe
we could use metatables to allow the fields to be accessed either by
position or by column name without duplicating them.

Thanks
On Jan 30, 2015 7:58 PM, "thibaultCha" notifications@github.com wrote:

Hi,

I noticed that in parse_rows here
https://github.com/jbochi/lua-resty-cassandra/blob/master/src/cassandra.lua#L841,
every row is added to two keys in the final result:

row[j] = value
row[columns[j].name] = value

Thus leading to results such as:

{
{ "3.2.0", "3", "2.1.2",
cql_version = "3.2.0",
native_protocol_version = "3",
release_version = "2.1.2"
}

I was wondering what purpose served this, and if an option to only
retrieve this part:

{
cql_version = "3.2.0",
native_protocol_version = "3",
release_version = "2.1.2"
}

could be considered.


Reply to this email directly or view it on GitHub
#27.

Thank you for the clarifications. No, memory is not what I am worried about, simply put, my use case is building an API. I am retrieving data from Cassandra and send it as JSON in responses.

Currently, this behaviour makes me iterate over each SELECT result to suppress the undesired fields and only send the key (column name)/value part. Which is fine, but I was just wondering why you chose to do so out of curiosity.

Concerning the option part, well, I'm not sure what would be best here, if that is how datastax consider it to be correct...

@thibaultcha, iteration should work now, without duplicated keys.

I used some metatable magic to allow access by position even though only the column names are used as keys.

Please let me know if this works for you.

Yes, that sounds like a pretty good option to me. Thank you for the feature 😉

Oh, do you plan on bumping the version number and publish the new version soon?