Adding secondary index with and do not overwrite existing ones
--------------------------------------------------------------

                 Key: CASSANDRA-2676
                 URL: https://issues.apache.org/jira/browse/CASSANDRA-2676
             Project: Cassandra
          Issue Type: New Feature
          Components: API
            Reporter: Markus Wiesenbacher
            Priority: Minor


Hi,

I am hard working on a web client for Cassandra (about 80% reached by now), and 
have a problem. I am using following function to create a new secondary index:

public boolean insertSecondaryIndex (String keyspace, String column_family, int 
columnfamilyid, String columnfamily_comparator, String column_validation_class, 
String column_index_name, String column_index_field)
        throws Exception {

                if (!isClosed()) {
                        
                        client.set_keyspace(keyspace);
                        
                        CfDef cfDef = new CfDef(keyspace, column_family);
                        cfDef.setId(columnfamilyid);
                        cfDef.setComparator_type(columnfamily_comparator);

                        // secondary index definition
                        ColumnDef column_metadata = new ColumnDef();
                        column_metadata.setIndex_name(column_index_name);
                        
column_metadata.setName(ByteBuffer.wrap(column_index_field.getBytes()));
                        
column_metadata.setValidation_class(lastPart(column_validation_class, "."));
                        column_metadata.setIndex_type(IndexType.KEYS);

                        cfDef.addToColumn_metadata(column_metadata);

                        client.system_update_column_family(cfDef);
                        
                        return true;
                }
                
                return false;
        }

This seems to overwrite the already existing indices. I use this to select the 
indexed field names:

public HashMap<String, String> getIndexColumns (String keyspaceName, String 
columnFamilyName)
        throws Exception {

                HashMap<String, String> toret = new HashMap<String,String>();
                
                if (!isClosed()) {

                        KsDef keyspace = client.describe_keyspace(keyspaceName);
                        List<CfDef> columnFamilies = keyspace.getCf_defs();
                        
                        for (CfDef columnFamily : columnFamilies) {

                                if 
(columnFamily.getName().equalsIgnoreCase(columnFamilyName)) {

                                        Iterator<ColumnDef> iter = 
columnFamily.getColumn_metadataIterator();
                                        while (iter.hasNext()) {
                                                
                                                ColumnDef cd = iter.next();
                                                toret.put (new 
String(cd.getName(), encoding), "");
                                        }
                                        
                                        break;
                                }
                        }
                }
                
                return toret;
        }       

Is this by design or a bug?

Many thanks and best regards
Wiesi ;)

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to