0

I am taking some babysteps into cassandra and i wanted some advice.

I want to insert data into a into column family , i have already created a column family with the following credentials -

  ColumnFamily: testkp
  Key Validation Class: org.apache.cassandra.db.marshal.UTF8Type
  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: Col_A
      Validation Class: org.apache.cassandra.db.marshal.FloatType
    Column Name: Col_B
      Validation Class: org.apache.cassandra.db.marshal.LongType
    Column Name: Col_C
      Validation Class: org.apache.cassandra.db.marshal.Int32Type
    Column Name: Col_D
      Validation Class: org.apache.cassandra.db.marshal.DateType
    Column Name: Col_E
      Validation Class: org.apache.cassandra.db.marshal.UTF8Type
  Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy
  Compression Options:
    chunk_length_kb: 64
    sstable_compression: org.apache.cassandra.io.compress.SnappyCompressor

Now i saw some basic insertion mechanisms and i tried, it basically works if i did not predefine my schema

public class SampleDataInsert {

private static StringSerializer stringSerializer = StringSerializer.get();

public static void main(String[] args) throws Exception {
    Cluster cluster = HFactory.getOrCreateCluster("TestCluster","localhost:9160");

    Keyspace keyspaceOperator = HFactory.createKeyspace("test",cluster);

    try {
        Mutator<String> mutator =   HFactory.createMutator(keyspaceOperator,stringSerializer);

        for (int i = 0; i < 2; i++) {
            mutator.addInsertion("key_" + i, "testkp", HFactory.createStringColumn("Col_A", ""+ i));
            mutator.addInsertion("key_" + i, "testkp", HFactory.createStringColumn("Col_B", ""+ i));
            mutator.addInsertion("key_" + i, "testkp", HFactory.createStringColumn("Col_C", ""+ i));
            mutator.addInsertion("key_" + i, "testkp", HFactory.createStringColumn("Col_D", ""+ i));
            mutator.addInsertion("key_" + i, "testkp", HFactory.createStringColumn("Col_E", ""+ i));
}
mutator.execute();
}

Now, since i have predefined the schema , if i try to add any column with key validation class other than UTF8Type. It basically pops an error( This is fine ).

My question is how to define other validation class (FloatType,LongType,DateType).. in hector so that i can do the insert.

Any links, suggestions to find this information..

P.S I tried for couple of days but i could not find much information. Apologies if my question is a bit low-level/ or poorly formatted.

Best Regards

4

1 回答 1

1

mutator.addInsertion(key, cf, HFactory.createColumn(longName, floatValue, LongSerializer.get(), FloatSerializer.get()))

于 2012-11-08T16:33:16.083 回答