incubator-cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Techy Teck <comptechge...@gmail.com>
Subject Re: Datastax API which uses Binary protocol- Quick question
Date Sat, 20 Apr 2013 00:07:01 GMT
Thanks a lot Tyler. That clears lot of my doubt. I have couple more
questions related to Datastax Java Driver-

1) Firstly, is there any way to figure out what version of CQL I am
running? Is it CQL 3 or something else? Is there any command that we can
use to check? Abd also by default CQLish behavior is false and I need to
enable that? Or it will come by default in all the Cassandra Version? By
the way, I am running Cassandra 1.2.3.

2) Secondly, I have created my column family in my keyspace like this-

         create column family profile
         with key_validation_class = 'UTF8Type'
         and comparator = 'UTF8Type'
         and default_validation_class = 'UTF8Type'
         and column_metadata = [
         {column_name : crd, validation_class : 'DateType'}
         {column_name : lmd, validation_class : 'DateType'}
         {column_name : account, validation_class : 'UTF8Type'}
         {column_name : advertising, validation_class : 'UTF8Type'}
         {column_name : behavior, validation_class : 'UTF8Type'}
         {column_name : info, validation_class : 'UTF8Type'}
         ];

Now I am trying to upsert data into above Column Family. I am not able to
understand how should I upsert the data into that as I am not able to find
lot of documentation that can explain simple example. Below is my upsert
method which will have two parameters-

userId and columnsNameAndValue

columnsNameAndValue is the map which will contain columns name as the key
and that corresponding value as the value.

    /**
     * Performs an upsert of the specified attributes for the specified id.
     */
    public void upsertAttributes(final String userId, final Map<String,
String> columnsNameAndValue) {

    // I am not sure what I am supposed to do here to upsert the data?

    }

Can you provide an example how to do that?


3)Thirdly, my last question- I am also trying to retrieve the data from
Cassandra using the same Datastax Java Driver given a row key-


    /**
     * Retrieves and returns the <strong>specified attributes</strong> for
the specified id.
     * @return a Map of attribute name and its corresponding value
     */
    public Map<String, String> getAttributes(final String userId, final
Collection<String> columnNames ) {

     // Now I am not sure what to do here as well to retrieve the data from
the Cassandra using Datastax Java Driver?
     // Here columnNames will be List of columns that I want to retrieve
from Cassandra on userId as the row key.

    }

Any example on this will also be of great help.


I am totally new to Cassandra and Datastax Java driver so that is the
reason I am having problem.

Thanks for the help.




On Fri, Apr 19, 2013 at 2:17 PM, Tyler Hobbs <tyler@datastax.com> wrote:

>
> On Thu, Apr 18, 2013 at 9:02 PM, Techy Teck <comptechgeeky@gmail.com>wrote:
>
>>
>> When I was working with Cassandra CLI using the Netflix client(Astyanax
>> client), then I created the column family like this-
>>
>>     create column family profile
>>     with key_validation_class = 'UTF8Type'
>>     and comparator = 'UTF8Type'
>>     and default_validation_class = 'UTF8Type'
>>     and column_metadata = [
>>       {column_name : crd, validation_class : 'DateType'}
>>       {column_name : lmd, validation_class : 'DateType'}
>>       {column_name : account, validation_class : 'UTF8Type'}
>>       {column_name : advertising, validation_class : 'UTF8Type'}
>>       {column_name : behavior, validation_class : 'UTF8Type'}
>>       {column_name : info, validation_class : 'UTF8Type'}
>>       ];
>>
>> Now I was trying to do the same thing using Datastax API. So to start
>> working with Datastax API, do I need to create the column family in some
>> different way as mentioned above? Or the above column familiy will work
>> fine whenever I will try to insert data into Cassandra database using
>> Datastax API.
>>
>
> If this column family already exists, the java-driver will be able to use
> it.  It will resemble a column family created WITH COMPACT STORAGE through
> cql3.
>
>
>>
>> If the above column family will not work then-
>>
>> First of all I have created the KEYSPACE like below-
>>
>> `CREATE KEYSPACE USERS WITH strategy_class = 'SimpleStrategy' AND
>> strategy_options:replication_factor = '1';`
>>
>> Now I am confuse how to create the table? I am not sure which is the
>> right way to do that?
>>
>> Should I create like this?
>>
>> `CREATE TABLE profile (
>> id varchar,
>> account varchar,
>> advertising varchar,
>> behavior varchar,
>> info varchar,
>> PRIMARY KEY (id)
>> );`
>>
>> or should I create like this?
>>
>> `CREATE COLUMN FAMILY profile (
>> id varchar,
>> account varchar,
>> advertising varchar,
>> behavior varchar,
>> info varchar,
>> PRIMARY KEY (id)
>> );`
>>
>
> You can use either "TABLE" or "COLUMN FAMILY".  They are equivalent.
>
>
>>
>> And also how to add-
>>
>>     crd as DateType
>>     lmd as DateType
>>
>> in above table or column family while working with Datastax API?
>>
>
> In cql3, "timestamp" corresponds to DateType.
>
> Use ALTER TABLE to add columns to a table:
> http://www.datastax.com/docs/1.2/cql_cli/cql/ALTER_TABLE#cql-alter-columnfamily
>
> --
> Tyler Hobbs
> DataStax <http://datastax.com/>
>

Mime
View raw message