pythoncassandrapycassa

PyCassa - ColumnFamily.get() - Now what?


Sorry if this seems like a dumb question, but I can't find an answer anywhere.

I have a column family with a comparator type of "TimeUUIDType"

I can do inserts to it no problem, and I can also do gets on on without any issue and see my results be shown.

What I am really lost on here, is after I perform a get() what exactly am I getting back? Is it an array of values?

If someone could show me how I might ever go about doing a simple loop to loop through my results, that would be a massive help!

When I do a get, the results are in the following format in terminal :

(key) -> (Column : value) (Column: value) (Column: value)

Thanks in advance!


Solution

  • If memory serves, you get back a tuple of

    (key<string>, OrderedDict{column_name: column_value})
    

    So, if you want to go over each column, you would do something like

    for column_name, column_value in cf.get(...)[1].items():
        print column_name, column_value
    

    **EDIT / CORRECTION **

    The return value from a get() is only the columns, not the key and columns.

    for column_name, column_value in cf.get(...).items():
        print column_name, column_value
    

    I was thinking of multiget / get_range which include them as you are potentially returning more than a single row. Thanks @thobbs for pycassa and the correction.