Search code examples
cassandrahector

Cassandra-check whether column name exists in column family


Am using hector java client for cassandra. Using Java how can i check whether particular column Name in column family exists or not?


Solution

  • I think you have to attempt to retrieve the column. If this succeeds, then the column exists. If not, then it doesn't.

    From the user guide:

    ColumnQuery<String, String, String> columnQuery =
        HFactory.createStringColumnQuery(keyspace);
    columnQuery.setColumnFamily("Standard1").setKey("jsmith").setName("first");
    QueryResult<HColumn<String, String>> result = columnQuery.execute();
    

    If your column values are very large, and you don't want to retrieve them like this, then one trick is to store a small 'companion' column that indicates the presence of the large column.