Re: Retrieve data from Cassandra database using Datastax java driver

2013-04-20 Thread Abhijit Chanda
You have the collection attributeNames, just iterate it
  Iterator it = result.iterator();
while(it.hasNext()){
Row row = it.next();
for(String column : attributeNames) {
//not sure how to put the columnName and columnValue that
came back from the database
attributes.put(column,row.getString(column));
}
}


Cheers


On Sun, Apr 21, 2013 at 10:24 AM, Techy Teck wrote:

> Thanks Dave for the suggestion. I have all my columns name in this
> collection-
>
>  *final Collection attributeNames*
> *
> *
> And all my results back in this resultset-
>
> *ResultSet result =
> CassandraDatastaxConnection.getSession().execute(query);*
> *
> *
> Now I need to store the column name and its corresponding value in the
> Below Map-
>
>   *Map attributes = new
> ConcurrentHashMap();*
> *
> *
> What's the best way to do that in this case?
>
> Thanks for the help.
>
>
>
>
>
>
> On Sat, Apr 20, 2013 at 9:36 PM, Dave Brosius wrote:
>
>>  getColumnDefinitions only returns meta data, to get the data, use the
>> iterator to navigate the rows
>>
>>
>> Iterator it = result.iterator();
>>
>> while (it.hasNext()) {
>> Row r = it.next();
>> //do stuff with row
>>
>> }
>>
>> On 04/21/2013 12:02 AM, Techy Teck wrote:
>>
>>  I am working with Datastax java-driver. And I am trying to retrieve few
>> columns from the database basis on the input that is being passed to the
>> below method-
>>
>>
>>  public Map getAttributes(final String userId, final
>> Collection attributeNames) {
>>
>>  String query="SELECT " +attributeNames.toString().substring(1,
>> attributeNames.toString().length()-1)+ " from profile where id = '"+userId+
>> "';";
>>   CassandraDatastaxConnection.getInstance();
>>
>>  ResultSet result =
>> CassandraDatastaxConnection.getSession().execute(query);
>>
>>  Map attributes = new ConcurrentHashMap> String>();
>>   for(Definition def : result.getColumnDefinitions()) {
>>  //not sure how to put the columnName and columnValue that came back from
>> the database
>>  attributes.put(column name, column value);
>>  }
>>   return attributes;
>>  }
>>
>>  Now I got the result back from the database in *result*
>> *
>> *
>> Now how to put the colum name and column value that came back from the
>> database in a map?
>>
>>  I am not able to understand how to retrieve colum value for a
>> particular column in datastax java driver?
>>
>>  Any thoughts will be of great help.
>>
>>
>>
>


-- 
-Abhijit


Re: Retrieve data from Cassandra database using Datastax java driver

2013-04-20 Thread Techy Teck
Thanks Dave for the suggestion. I have all my columns name in this
collection-

 *final Collection attributeNames*
*
*
And all my results back in this resultset-

*ResultSet result =
CassandraDatastaxConnection.getSession().execute(query);*
*
*
Now I need to store the column name and its corresponding value in the
Below Map-

  *Map attributes = new
ConcurrentHashMap();*
*
*
What's the best way to do that in this case?

Thanks for the help.






On Sat, Apr 20, 2013 at 9:36 PM, Dave Brosius wrote:

>  getColumnDefinitions only returns meta data, to get the data, use the
> iterator to navigate the rows
>
>
> Iterator it = result.iterator();
>
> while (it.hasNext()) {
> Row r = it.next();
> //do stuff with row
>
> }
>
> On 04/21/2013 12:02 AM, Techy Teck wrote:
>
>  I am working with Datastax java-driver. And I am trying to retrieve few
> columns from the database basis on the input that is being passed to the
> below method-
>
>
>  public Map getAttributes(final String userId, final
> Collection attributeNames) {
>
>  String query="SELECT " +attributeNames.toString().substring(1,
> attributeNames.toString().length()-1)+ " from profile where id = '"+userId+
> "';";
>   CassandraDatastaxConnection.getInstance();
>
>  ResultSet result =
> CassandraDatastaxConnection.getSession().execute(query);
>
>  Map attributes = new ConcurrentHashMap();
>   for(Definition def : result.getColumnDefinitions()) {
>  //not sure how to put the columnName and columnValue that came back from
> the database
>  attributes.put(column name, column value);
>  }
>   return attributes;
>  }
>
>  Now I got the result back from the database in *result*
> *
> *
> Now how to put the colum name and column value that came back from the
> database in a map?
>
>  I am not able to understand how to retrieve colum value for a particular
> column in datastax java driver?
>
>  Any thoughts will be of great help.
>
>
>


Re: Retrieve data from Cassandra database using Datastax java driver

2013-04-20 Thread Dave Brosius
getColumnDefinitions only returns meta data, to get the data, use the 
iterator to navigate the rows



Iterator it = result.iterator();

while (it.hasNext()) {
Row r = it.next();
//do stuff with row
}

On 04/21/2013 12:02 AM, Techy Teck wrote:
I am working with Datastax java-driver. And I am trying to retrieve 
few columns from the database basis on the input that is being passed 
to the below method-



public Map getAttributes(final String userId, final 
Collection attributeNames) {


String query="SELECT " +attributeNames.toString().substring(1, 
attributeNames.toString().length()-1)+ " from profile where id = 
'"+userId+ "';";

CassandraDatastaxConnection.getInstance();

ResultSet result = 
CassandraDatastaxConnection.getSession().execute(query);


Map attributes = new ConcurrentHashMap();
for(Definition def : result.getColumnDefinitions()) {
//not sure how to put the columnName and columnValue that came back 
from the database

attributes.put(column name, column value);
}
return attributes;
}

Now I got the result back from the database in *result*
*
*
Now how to put the colum name and column value that came back from the 
database in a map?


I am not able to understand how to retrieve colum value for a 
particular column in datastax java driver?


Any thoughts will be of great help.




Retrieve data from Cassandra database using Datastax java driver

2013-04-20 Thread Techy Teck
I am working with Datastax java-driver. And I am trying to retrieve few
columns from the database basis on the input that is being passed to the
below method-


public Map getAttributes(final String userId, final
Collection attributeNames) {

String query="SELECT " +attributeNames.toString().substring(1,
attributeNames.toString().length()-1)+ " from profile where id = '"+userId+
"';";
 CassandraDatastaxConnection.getInstance();

ResultSet result = CassandraDatastaxConnection.getSession().execute(query);

Map attributes = new ConcurrentHashMap();
 for(Definition def : result.getColumnDefinitions()) {
 //not sure how to put the columnName and columnValue that came back from
the database
attributes.put(column name, column value);
 }
 return attributes;
 }

Now I got the result back from the database in *result*
*
*
Now how to put the colum name and column value that came back from the
database in a map?

I am not able to understand how to retrieve colum value for a particular
column in datastax java driver?

Any thoughts will be of great help.