protected List < ColumnDef > getColumnMeta ( Cassandra . Client client , boolean cassandraStorage , boolean includeCompactValueColumn ) throws InvalidRequestException , UnavailableException , TimedOutException , SchemaDisagreementException , TException , CharacterCodingException , org . apache . cassandra . exceptions . InvalidRequestException , ConfigurationException , NotFoundException { String query = "SELECT column_name, " + " validator, " + " index_type, " + " type " + "FROM system.schema_columns " + "WHERE keyspace_name = '%s' " + " AND columnfamily_name = '%s'" ; CqlResult result = client . execute_cql3_query ( ByteBufferUtil . bytes ( String . format ( query , keyspace , column_family ) ) , Compression . NONE , ConsistencyLevel . ONE ) ; List < CqlRow > rows = result . rows ; List < ColumnDef > columnDefs = new ArrayList < ColumnDef > ( ) ; if ( rows == null || rows . isEmpty ( ) ) { // if CassandraStorage, just return the empty list if ( cassandraStorage ) return columnDefs ; // otherwise for CqlNativeStorage, check metadata for classic thrift tables CFMetaData cfm = getCFMetaData ( keyspace , column_family , client ) ; for ( ColumnDefinition def : cfm . regularAndStaticColumns ( ) ) { ColumnDef cDef = new ColumnDef ( ) ; String columnName = def . name . toString ( ) ; String type = def . type . toString ( ) ; logger . debug ( "name: {}, type: {} " , columnName , type ) ; cDef . name = ByteBufferUtil . bytes ( columnName ) ; cDef . validation_class = type ; columnDefs . add ( cDef ) ; } // we may not need to include the value column for compact tables as we // could have already processed it as schema_columnfamilies.value_alias if ( columnDefs . size ( ) == 0 && includeCompactValueColumn && cfm . compactValueColumn ( ) != null ) { ColumnDefinition def = cfm . compactValueColumn ( ) ; if ( "value" . equals ( def . name . toString ( ) ) ) { ColumnDef cDef = new ColumnDef ( ) ; cDef . name = def . name . bytes ; cDef . validation_class = def . type . toString ( ) ; columnDefs . add ( cDef ) ; } } return columnDefs ; } Iterator < CqlRow > iterator = rows . iterator ( ) ; while ( iterator . hasNext ( ) ) { CqlRow row = iterator . next ( ) ; ColumnDef cDef = new ColumnDef ( ) ; String type = ByteBufferUtil . string ( row . getColumns ( ) . get ( 3 ) . value ) ; if ( ! type . equals ( "regular" ) ) continue ; cDef . setName ( ByteBufferUtil . clone ( row . getColumns ( ) . get ( 0 ) . value ) ) ; cDef . validation_class = ByteBufferUtil . string ( row . getColumns ( ) . get ( 1 ) . value ) ; ByteBuffer indexType = row . getColumns ( ) . get ( 2 ) . value ; if ( indexType != null ) cDef . index_type = getIndexType ( ByteBufferUtil . string ( indexType ) ) ; columnDefs . add ( cDef ) ; } return columnDefs ; }
get column meta data