On Thu, Apr 18, 2013 at 9:02 PM, Techy Teck <[email protected]> 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/>