You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Sasha Dolgy <sd...@gmail.com> on 2011/02/18 23:39:24 UTC

simple erlang example

hi,

does anyone have an erlang example for connecting to cassandra and
performing an operation like a get?

I'm not having much luck with: \thrift-0.5.0\test\erl\src\* as a reference
point.

I generated all of the erlang files using thrift and have successfully
compiled them but am having a pretty rough go at it.

Found this old post:
http://www.mail-archive.com/cassandra-user@incubator.apache.org/msg02893.html
...
but seems the examples never made it to the wiki.

-sd

-- 
Sasha Dolgy
sasha.dolgy@gmail.com

Re: simple erlang example

Posted by Sasha Dolgy <sd...@gmail.com>.
there is a current stratregy to use cassandra for data storage and it makes
sense to have user management and roster management exist in the same place
for all the different services that we provide.

specific to user interaction, i started looking at ejabberd because Apache
Vysper is not as feature rich .... ejabber is erlang based and supports
different external sources as a storage provider ... mysql, sql server,
active directory, etc.

-sd

On Sat, Feb 19, 2011 at 8:18 AM, Joshua Partogi <jo...@gmail.com>wrote:

> Is there any reason why you would be interested to use erlang with
> cassandra instead of other erlang based database [i.e Couchbase, Riak]
> ?
>
> I am interested to know the reason.
>
> Kind regards,
> Joshua
>
>

Re: simple erlang example

Posted by J T <jt...@googlemail.com>.
Well I can't go in to too much detail I'm afraid but yes, in some cases
there is duplication of data across the different database engines but then
thats 'ok' in this new NOSQL world.



On Sat, Feb 19, 2011 at 2:01 PM, Joshua Partogi <jo...@gmail.com>wrote:

> Hi,
>
> Would you like to share you use both database? Does this mean you have
> the same data in both database?
>
> Thanks for sharing.
>
> Kind regards,
> Joshua.
>
> On Sun, Feb 20, 2011 at 12:41 AM, J T <jt...@googlemail.com> wrote:
> > Hi Joshua,
> > I can't speak for Sasha, but in my case I use both Riak and Cassandra
> since
> > cassandra has ranges and build in secondary indexes whereas Riak does
> not.
> > Actually I use others too as the different ones bring different qualities
> to
> > the table.
> >
> > JT>
> >
> > On Sat, Feb 19, 2011 at 7:18 AM, Joshua Partogi <jo...@gmail.com>
> > wrote:
> >>
> >> Is there any reason why you would be interested to use erlang with
> >> cassandra instead of other erlang based database [i.e Couchbase, Riak]
> >> ?
> >>
> >> I am interested to know the reason.
> >>
> >> Kind regards,
> >> Joshua
> >>
> >> On Sat, Feb 19, 2011 at 9:39 AM, Sasha Dolgy <sd...@gmail.com> wrote:
> >> > hi,
> >> > does anyone have an erlang example for connecting to cassandra and
> >> > performing an operation like a get?
> >> > I'm not having much luck with: \thrift-0.5.0\test\erl\src\* as a
> >> > reference
> >> > point.
> >> > I generated all of the erlang files using thrift and have successfully
> >> > compiled them but am having a pretty rough go at it.
> >> > Found this old post:
> >> >
> >> >
> http://www.mail-archive.com/cassandra-user@incubator.apache.org/msg02893.html
>  ...
> >> > but seems the examples never made it to the wiki.
> >> > -sd
> >> >
> >> > --
> >> > Sasha Dolgy
> >> > sasha.dolgy@gmail.com
> >> >
> >>
> >>
> >>
> >> --
> >> http://twitter.com/jpartogi
> >
> >
>
>
>
> --
> http://twitter.com/jpartogi
>

Re: simple erlang example

Posted by Joshua Partogi <jo...@gmail.com>.
Hi,

Would you like to share you use both database? Does this mean you have
the same data in both database?

Thanks for sharing.

Kind regards,
Joshua.

On Sun, Feb 20, 2011 at 12:41 AM, J T <jt...@googlemail.com> wrote:
> Hi Joshua,
> I can't speak for Sasha, but in my case I use both Riak and Cassandra since
> cassandra has ranges and build in secondary indexes whereas Riak does not.
> Actually I use others too as the different ones bring different qualities to
> the table.
>
> JT>
>
> On Sat, Feb 19, 2011 at 7:18 AM, Joshua Partogi <jo...@gmail.com>
> wrote:
>>
>> Is there any reason why you would be interested to use erlang with
>> cassandra instead of other erlang based database [i.e Couchbase, Riak]
>> ?
>>
>> I am interested to know the reason.
>>
>> Kind regards,
>> Joshua
>>
>> On Sat, Feb 19, 2011 at 9:39 AM, Sasha Dolgy <sd...@gmail.com> wrote:
>> > hi,
>> > does anyone have an erlang example for connecting to cassandra and
>> > performing an operation like a get?
>> > I'm not having much luck with: \thrift-0.5.0\test\erl\src\* as a
>> > reference
>> > point.
>> > I generated all of the erlang files using thrift and have successfully
>> > compiled them but am having a pretty rough go at it.
>> > Found this old post:
>> >
>> >  http://www.mail-archive.com/cassandra-user@incubator.apache.org/msg02893.html ...
>> > but seems the examples never made it to the wiki.
>> > -sd
>> >
>> > --
>> > Sasha Dolgy
>> > sasha.dolgy@gmail.com
>> >
>>
>>
>>
>> --
>> http://twitter.com/jpartogi
>
>



-- 
http://twitter.com/jpartogi

Re: simple erlang example

Posted by J T <jt...@googlemail.com>.
Hi Joshua,

I can't speak for Sasha, but in my case I use both Riak and Cassandra since
cassandra has ranges and build in secondary indexes whereas Riak does not.
Actually I use others too as the different ones bring different qualities to
the table.


JT>

On Sat, Feb 19, 2011 at 7:18 AM, Joshua Partogi <jo...@gmail.com>wrote:

> Is there any reason why you would be interested to use erlang with
> cassandra instead of other erlang based database [i.e Couchbase, Riak]
> ?
>
> I am interested to know the reason.
>
> Kind regards,
> Joshua
>
> On Sat, Feb 19, 2011 at 9:39 AM, Sasha Dolgy <sd...@gmail.com> wrote:
> > hi,
> > does anyone have an erlang example for connecting to cassandra and
> > performing an operation like a get?
> > I'm not having much luck with: \thrift-0.5.0\test\erl\src\* as a
> reference
> > point.
> > I generated all of the erlang files using thrift and have successfully
> > compiled them but am having a pretty rough go at it.
> > Found this old post:
> >
> http://www.mail-archive.com/cassandra-user@incubator.apache.org/msg02893.html
>  ...
> > but seems the examples never made it to the wiki.
> > -sd
> >
> > --
> > Sasha Dolgy
> > sasha.dolgy@gmail.com
> >
>
>
>
> --
> http://twitter.com/jpartogi
>

Re: simple erlang example

Posted by Joshua Partogi <jo...@gmail.com>.
Is there any reason why you would be interested to use erlang with
cassandra instead of other erlang based database [i.e Couchbase, Riak]
?

I am interested to know the reason.

Kind regards,
Joshua

On Sat, Feb 19, 2011 at 9:39 AM, Sasha Dolgy <sd...@gmail.com> wrote:
> hi,
> does anyone have an erlang example for connecting to cassandra and
> performing an operation like a get?
> I'm not having much luck with: \thrift-0.5.0\test\erl\src\* as a reference
> point.
> I generated all of the erlang files using thrift and have successfully
> compiled them but am having a pretty rough go at it.
> Found this old post:
>  http://www.mail-archive.com/cassandra-user@incubator.apache.org/msg02893.html ...
> but seems the examples never made it to the wiki.
> -sd
>
> --
> Sasha Dolgy
> sasha.dolgy@gmail.com
>



-- 
http://twitter.com/jpartogi

Re: simple erlang example

Posted by J T <jt...@googlemail.com>.
HI Sasha,

That was me that was going to try and put something on the wiki and I
completely forgot about it.
I'm tied up this weekend but I will endeavor to ping you an example asap.

Jason

On Fri, Feb 18, 2011 at 10:39 PM, Sasha Dolgy <sd...@gmail.com> wrote:

> hi,
>
> does anyone have an erlang example for connecting to cassandra and
> performing an operation like a get?
>
> I'm not having much luck with: \thrift-0.5.0\test\erl\src\* as a reference
> point.
>
> I generated all of the erlang files using thrift and have successfully
> compiled them but am having a pretty rough go at it.
>
> Found this old post:
> http://www.mail-archive.com/cassandra-user@incubator.apache.org/msg02893.html ...
> but seems the examples never made it to the wiki.
>
> -sd
>
> --
> Sasha Dolgy
> sasha.dolgy@gmail.com
>

Re: simple erlang example

Posted by J T <jt...@googlemail.com>.
Hi Sasha,

Below is some code from an old module I was working with a while back.

It should give you an idea of the direction to go but really if you look at
the files generated by thrift for cassandra it should help as well:

*  cassandra_thrift.erl
*  cassandra_thrift.hrl
*  cassandra_types.erl
*  cassandra_types.hrl

% -- Snip --

get_connection( Host, KeySpace, Credentials) when is_list(KeySpace) ->
    get_connection( Host, list_to_binary(KeySpace), Credentials );

get_connection( Host, KeySpace, Credentials) when is_binary(KeySpace) ->
    case thrift_client_util:new(Host, 9160, cassandra_thrift, [ { framed,
true } ] ) of
        {ok, Connection } -> set_keyspace( Connection, KeySpace ),
                             authenticate( Connection, Credentials ),
                             Connection;
        _                 -> throw({ get_connection, "Failed to get
connection to cassandra!" })
    end.

    authenticate( Connection, _Credentials ) ->
        thrift_client:call( Connection, login, [ #authenticationRequest{
credentials = dict:new() } ]).

    set_keyspace( Connection, KeySpace ) ->
        thrift_client:call( Connection, set_keyspace, [ KeySpace ]).

% Key = ...              e.g. <<"ARowKey">>
% CF  = ColumnFamily     e.g. <<"TestColumnFamily">>
% SC  = SuperColumn      e.g. <<"TestSuperColumn">>
% C   = Column           e.g. <<"TestColumn">>
% CL  = ConsistencyLevel e.g. ?cassandra_ConsistencyLevel_QUORUM

get( Connection, Key, CF, SC, C, CL  ) when is_binary(CF), is_binary(C) ->
    try thrift_client:call( Connection, get, [ Key, #columnPath{
column_family = CF, super_column = SC, column = C }, CL ]) of
        { _, { ok, R  }} -> R;
        { _, { _,  E1 }} -> throw( { ?MODULE, get, E1 } );
        X                -> throw( { ?MODULE, get, X  } )
    catch
        throw:notFoundException   -> notfound
    end.

% -- Snip --

Example Call Might be:

Connection  = get_connection( "localhost", "TestKeySpace", "" ),
ColumnValue = ?MODULE:get( Connection, <<"ARowKey">>, <<"TestColumnFamily
">>, <<"TestSuperColumn">>, <<"TestColumn">>,
?cassandra_ConsistencyLevel_QUORUM
)


On Fri, Feb 18, 2011 at 10:39 PM, Sasha Dolgy <sd...@gmail.com> wrote:

> hi,
>
> does anyone have an erlang example for connecting to cassandra and
> performing an operation like a get?
>
> I'm not having much luck with: \thrift-0.5.0\test\erl\src\* as a reference
> point.
>
> I generated all of the erlang files using thrift and have successfully
> compiled them but am having a pretty rough go at it.
>
> Found this old post:
> http://www.mail-archive.com/cassandra-user@incubator.apache.org/msg02893.html ...
> but seems the examples never made it to the wiki.
>
> -sd
>
> --
> Sasha Dolgy
> sasha.dolgy@gmail.com
>