Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To get the column specific information, you will first have to iterate through the Column Family definitions in the Keyspace definition and match the Column Family by name -- can use the thrift API, but I would suggest using Hector.</p> <p>With the Column Family Definition, iterate through the Column Metadata, and finding the match for the desired column. Then refer to the matching Column Definition, to get the validation class. If there is no metadata, or no matching column, the validation class will be the default validation class in the Column Family Definition.</p> <p>Using Hector API, the following will list all Column Families in the keyspace and complete details on the CF name passed as argument.</p> <pre><code>public static void main(String[] args) { String hostPort = "localhost:9160"; String cfname = null; if (args.length &lt; 1) { System.out.println("Expecting &lt;CF&gt; as arguments"); System.exit(1); } cfname = args[0]; Cluster cluster = HFactory.getOrCreateCluster( "myCluster", hostPort ); KeyspaceDefinition ksdef = cluster.describeKeyspace("myKeyspace"); for (ColumnFamilyDefinition cfdef: ksdef.getCfDefs()) { System.out.println(cfdef.getName()); if (cfdef.getName().equals(cfname)) { System.out.println("Comment: " + cfdef.getComment()); System.out.println("Key: " + cfdef.getKeyValidationClass()); System.out.println("Comparator: " + cfdef.getComparatorType().getTypeName()); System.out.println("Default Validation:" + cfdef.getDefaultValidationClass()); System.out.println("Column MetaData:"); for (ColumnDefinition cdef: cfdef.getColumnMetadata()) { System.out.println(" Column Name: " + Charset.defaultCharset().decode(cdef.getName()).toString()); System.out.println(" Validation Class: " + cdef.getValidationClass()); System.out.println(" Index Name: " + cdef.getIndexName()); System.out.println(" Index Type: " + cdef.getIndexType().toString()); } } } } </code></pre> <p>If you run that, you will notice that any validation class will belong to the org.apache.cassandra.db.marshal package and each type is derived from AbstractType.</p> <p>Once you have the Type, you can make decisions on your data. For example, if writing a data dumper tool, you might just want to get the string representation of each column and you can use the AbstractType to get the string representation of the value, using the TypeParser to create the type.</p> <p>E.g. a <em>non-Hector</em> method I used to do this looks like</p> <pre><code>private String getAsString(java.nio.ByteBuffer bytes, String marshalType) { String val = null; try { AbstractType abstractType = TypeParser.parse(marshalType); val = abstractType.getString(bytes); } catch (ConfigurationException e) { e.printStackTrace(); } return val; } </code></pre> <p>You could use this method to dump out keys and column names; those type names are in the Column Family Definition as well.</p> <p>One quick shortcut, if you know the column value is a string, since there is no method on the byte buffer to getString, you have to use java.nio.charset.Charset:</p> <pre><code>Charset.defaultCharset().decode(col.getValue()).toString() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload