How to write SortedSet of cassandra data type as json in python? -


i trying dump cassandra data in csv format using python. far, developed following script:

from cassandra.cluster import cluster cassandra.auth import plaintextauthprovider cassandra.query import tuple_factory cassandra.query import dict_factory import csv auth_provider = plaintextauthprovider(username='cassandra', password='std123') cluster = cluster(['127.0.0.1'],auth_provider=auth_provider) session = cluster.connect('killrvideo')  session.row_factory = tuple_factory rows = session.execute("select * videos videoid = 873ff430-9c23-4e60-be5f-278ea2bb21bd") row = cursor.fetchall() open('data.csv', 'w') fp:     = csv.writer(fp, delimiter=',')     a.writerows(rows)       cluster.shutdown() 

and giving me output like:

873ff430-9c23-4e60-be5f-278ea2bb21bd, 2013-05-16 23:50:00, second in 3 part series cassandra data modeling, http://www.youtube.com/watch?v=qphhxujn5es,1, "sortedset([video_metadata(height=480, width=640, video_bit_rate=sortedset([u'1000kbs', u'400kbs']), encoding=u'mp4')])", become super modeler, {u'youtube': u'http://www.youtube.com/watch?v=qphhxujn5es'}, "sortedset([u'cassandra', u'cql', u'data model', u'instruction'])", 9761d3d7-7fbd-4269-9988-6cfd4e188678 

i added new line manually can readable here. now, actual data set this:

 videoid            | 873ff430-9c23-4e60-be5f-278ea2bb21bd  added_date         | 2013-05-16 23:50:00.000000+0000  description        | second in 3 part series cassandra data modeling  location           | http://www.youtube.com/watch?v=qphhxujn5es  location_type      | 1  metadata           | {{height: 480, width: 640, video_bit_rate: {'1000kbs', '400kbs'}, encoding: 'mp4'}}  name               | become super modeler  preview_thumbnails | {'youtube': 'http://www.youtube.com/watch?v=qphhxujn5es'}  tags               | {'cassandra', 'cql', 'data model', 'instruction'}  userid             | 9761d3d7-7fbd-4269-9988-6cfd4e188678 

my question in result set csv created value

"sortedset([u'cassandra', u'cql', u'data model', u'instruction'])" 

how can make simple json format use csv using copy command restore. here table description:

create table killrvideo.videos (     videoid uuid primary key,     added_date timestamp,     description text,     location text,     location_type int,     metadata set<frozen<video_metadata>>,     name text,     preview_thumbnails map<text, text>,     tags set<text>,     userid uuid ) 

please advise.

thanks.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -