cassandra - CQL2 Java Client Results Binary Data -
i have built table using cql2, data looks fine cqlsh hive command prompt. when reading data java client shows binary value 2 columns, shown below
"hr1":"\u0000\u0000\u0000\u000e","hr2":"\u0000\u0000\u0000)"
after creating table have created index on column "col1" cql prompt.
my java code looks :
public void read() { if (null != cluster && null != keyspace) { cqlquery<string, string, string> cqlquery = new cqlquery<string, string, string>( keyspace, stringserializer.get(), stringserializer.get(), stringserializer.get()); cqlquery.setquery("select * mytable col1 = 'hr100'"); queryresult<cqlrows<string, string, string>> result = cqlquery .execute(); cqlrows rows = result.get(); (int = 0; < rows.getcount(); i++) { rowimpl<string, string, string> row = (rowimpl<string, string, string>) rows .getlist().get(i); system.out.println("row key = " + row.getkey()); (hcolumn<string, string> column : row.getcolumnslice() .getcolumns()) { system.out.println("column name = " + column.getname().tostring()); system.out.println("colmn value = " + column.getvalue().tostring()); } } } }
here problem trying read every value strings. approach works string values. when comes other types, must have specify appropriate serialiser before reading. can use column metadata know data types columnfamily.
so iteration impossible in such situation , must have read individual columns follows.
columnslice<string, integer> slice = row.getcolumnslice(); hcolumn<string,integer> col = slice.getcolumnbyname("column_name");
here have used integer type value since i'm expecting integer.
please find more details in how use cql queries different datatypes out of cassandra java client hector
Comments
Post a Comment