Question

If I have a column family created like this in Cassandra as previously I was using Thrift based client..

create column family USER
with comparator = 'UTF8Type'
and key_validation_class = 'UTF8Type'
and default_validation_class = 'BytesType'

Then can I insert into above column family by using the Datastax Java driver with asynchonous / batch writes capability?

I will be using INSERT statement to insert into above column family? Is that possible using Datastax Java driver?

I am in the impression that I can only insert into CQL based tables using Datastax Java driver not in the column family design tables...

Était-ce utile?

La solution

TL;DR
Sort of, but it is better to create a cql3 based table and continue from there.

First off to get a clear impression of what's going on use the describe command in cqlsh:

cqlsh> describe COLUMNFAMILY "USER";

CREATE TABLE "USER" (
  key text,
  column1 text,
  value blob,
  PRIMARY KEY (key, column1)
) WITH COMPACT STORAGE AND
  bloom_filter_fp_chance=0.010000 AND
  caching='KEYS_ONLY' AND
  comment='' AND
  dclocal_read_repair_chance=0.000000 AND
  gc_grace_seconds=864000 AND
  index_interval=128 AND
  read_repair_chance=0.100000 AND
  replicate_on_write='true' AND
  populate_io_cache_on_flush='false' AND
  default_time_to_live=0 AND
  speculative_retry='NONE' AND
  memtable_flush_period_in_ms=0 AND
  compaction={'class': 'SizeTieredCompactionStrategy'} AND
  compression={'sstable_compression': 'LZ4Compressor'};

Then you can build insert statements using cqlh (i used cqlsh):

cqlsh:test> insert into test."USER" (key, column1, value) VALUES ('epickey', 'epic column 1 text', null);

If you do a select however...

cqlsh:test> SELECT * FROM test."USER" ;

(0 rows)

Once you've done that go back to the CLI:

[default@unknown] use test;
Authenticated to keyspace: test
[default@test] list USER;
Using default limit of 100
Using default cell limit of 100
-------------------
RowKey: epickey

1 Row Returned.
Elapsed time: 260 msec(s).

The last tool I'll use is sstable2json (takes all your data from an sstable and ... turns it into a json representation)

For the above single insert of the USER cf i got this back:

[
{"key": "657069636b6579","columns": [["epic column 1 text","5257c34b",1381483339315000,"d"]]}
]

So the data is there, but you just dont really have access to it over cql.

Note This is all done using C* 2.0 and cqlsh 4.0 (cql3)

Autres conseils

Yes, using below code:

String query = "INSERT INTO " + keyspace_name + "." + column_family + " (" + column_names + ") VALUES (" + column_values + ");";
statement = session.prepare(query);
boundStatement = new BoundStatement(statement);

boundStatement.setString(0, key);
boundStatement.setString(1, subColNames[k]);
boundStatement.setMap(2, colValues);
session.execute(boundStatement);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top