0

I am new to Cassandra, and have been playing around with the Hector API. As you can see in the screenshot below, I Have a Column Family defined and when i use CQL to return the rows, it is returning the Key and Value as a Hex Value, I would like to return it as a UTF8 value if possible. Also, it seems my My Column Name did not take, it is using "Column1" instead. I'll post my col family declaration below.

//Define ColumnFamily Def in Hector
            ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition(keyspaceName,"DP_ColumnFamily1",ComparatorType.UTF8TYPE);      


            //Add the column family to actual Cassandra Instance
            cluster.addColumnFamily(cfDef,false);

            stringSerializer = StringSerializer.get();

             //The following example inserts a Column with the column name "Datapower_Device_Name" and the column value of "DPIPE0101" under the key "key1". 

            Mutator mutator = HFactory.createMutator(ksp, stringSerializer);
            mutator.insert("key1", "DP_ColumnFamily1", HFactory.createStringColumn("Datapower_Device_Name", "DPIPE0101"));


cqlsh:test3> select * from "DP_ColumnFamily1";

 key        | column1               | value
------------+-----------------------+----------------------
 0x6b657931 | Datapower_Device_Name | 0x445049504530313031

(1 rows)
0

1 Answer 1

1

This line:

ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition(keyspaceName,"DP_ColumnFamily1",ComparatorType.UTF8TYPE);

creates a column family with the comparator set to UTF8. The comparator defines the data type of your column names, and says nothing about the values. CQL is smart enough to use this comparator to correctly display the name as a string when you run your query, but it has no information at all about the key or value types.

A better approach would be to use the new native driver, which avoids Thrift altogether and allows you to do everything via CQL. Then you'd be able to create your schema in CQL like this:

CREATE TABLE Device (
  DeviceID varchar, 
  DeviceName varchar,
  PRIMARY KEY (DeviceID)
);

... then insert like this:

INSERT INTO Device (DeviceID, DeviceName) 
VALUES ('Some_ID', 'DPIPE0101');

then if you query in cqlsh it looks like this:

 deviceid | devicename
----------+------------
  Some_ID |  DPIPE0101

Keep in mind that CQL rows are not a direct correlation to storage rows, so you shouldn't really mix Thrift and CQL-based operations. The exception is that it's helpful to use cassandra-cli to see what the storage engine is doing with your CQL. In this case it looks like this:

RowKey: Some_ID
=> (name=, value=, timestamp=1382118992099000)
=> (name=devicename, value=445049504530313031, timestamp=1382118992099000)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.