Cassandra – save file

cassandrapython

I'm new with Cassandra, and even more – I never have such task for habitual RDMS systems, like MariaDB or Oracle.

So, how can I store file in to Cassandra's table? Preferably using Python-driver, but few examples with raw CQL (cqlengine?) also appreciated.

We have large amount of small files, less then 10MB, with currently stored in Cassandra, and I'd like to understood how it's can be done.

For example – using next table:

cqlsh:testkeyspace> desc table files_uuids;

CREATE TABLE files_uuids (
  id uuid,
  file blob,
  PRIMARY KEY ((id))
) WITH
  bloom_filter_fp_chance=0.010000 AND
  caching='KEYS_ONLY' AND
  comment='' AND
  dclocal_read_repair_chance=0.100000 AND
  gc_grace_seconds=864000 AND
  index_interval=128 AND
  read_repair_chance=0.000000 AND
  replicate_on_write='true' AND
  populate_io_cache_on_flush='false' AND
  default_time_to_live=0 AND
  speculative_retry='99.0PERCENTILE' AND
  memtable_flush_period_in_ms=0 AND
  compaction={'class': 'SizeTieredCompactionStrategy'} AND
  compression={'sstable_compression': 'LZ4Compressor'};

Best Answer

You (and other future readers) might also try using the COPY command of cqlsh.

For example, if you have a local file named "filedata.csv", containing e.g.:

123-45-678-9,some file data here
abc-de-fgh-1,some other file data here

where the CSV fields corresponding to the columns in your file_uuids table, then you should be able to use:

cqlsh> COPY file_uuids FROM 'filedata.csv';

Hope this helps!