Hi All,
Following Hector's cql code examples, I created an example and I could execute this example successfully.
However, when reviewing the source code, I have a question for it.
Here is the source code I created:
Cluster tutorialCluster = HFactory.getOrCreateCluster("TutorialCluster", "16.158.81.59:9160");
ConfigurableConsistencyLevel ccl = new ConfigurableConsistencyLevel();
ccl.setDefaultReadConsistencyLevel(HConsistencyLevel.ONE);
Keyspace keyspace = HFactory.createKeyspace("Tutorial", tutorialCluster, ccl);
CqlQuery<String,String,String> cqlQuery = new CqlQuery<String,String,String>(keyspace, se, se, se);
cqlQuery.setQuery("select * from testcql");
QueryResult<CqlRows<String,String,String>> result = cqlQuery.execute();
CqlRows<String,String,String> rows = result.get();
System.out.println("size is: " + rows.getList().size());
And here is the testcql column family I created for this example:
create column family testcql
with comparator = 'UTF8Type'
and default_validation_class = 'UTF8Type'
and key_validation_class = 'UTF8Type';
As I said, the code could run successfully, and I'm able to get the total rows for the column family testcql. However, I'm very confused with "CqlQuery<String,String,String>" declaration, I know the three <String> is for the key type, value name type and value type, but if I create a column family with multiple column name type and column value type, then, how do I declare CqlQuery?
For example,
when I create a table using cqlsh as below:
create table temptest (id int, value1 varchar, value2 int, primary key (id));
And I describe the table in cassandra-cli:
[default@demodb] describe temptest;
ColumnFamily: temptest
Key Validation Class: org.apache.cassandra.db.marshal.Int32Type
Default column value validator: org.apache.cassandra.db.marshal.UTF8Type
Columns sorted by: org.apache.cassandra.db.marshal.UTF8Type
GC grace seconds: 864000
Compaction min/max thresholds: 4/32
Read repair chance: 0.1
DC Local Read repair chance: 0.0
Replicate on write: true
Caching: KEYS_ONLY
Bloom Filter FP chance: default
Built indexes: []
Column Metadata:
Column Name: value2
Validation Class: org.apache.cassandra.db.marshal.Int32Type
Column Name: value1
Validation Class: org.apache.cassandra.db.marshal.UTF8Type
Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy
Compression Options:
sstable_compression: org.apache.cassandra.io.compress.SnappyCompressor
For this table(column family), how do we declare CqlQuery since the value could be a number or a String ?
Thanks.
