Return-Path: Delivered-To: apmail-cassandra-user-archive@www.apache.org Received: (qmail 48407 invoked from network); 19 Feb 2011 19:36:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 19 Feb 2011 19:36:15 -0000 Received: (qmail 97567 invoked by uid 500); 19 Feb 2011 19:36:13 -0000 Delivered-To: apmail-cassandra-user-archive@cassandra.apache.org Received: (qmail 97519 invoked by uid 500); 19 Feb 2011 19:36:11 -0000 Mailing-List: contact user-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cassandra.apache.org Delivered-To: mailing list user@cassandra.apache.org Received: (qmail 97511 invoked by uid 99); 19 Feb 2011 19:36:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 19 Feb 2011 19:36:11 +0000 X-ASF-Spam-Status: No, hits=4.3 required=5.0 tests=FREEMAIL_FROM,FREEMAIL_REPLY,HTML_FONT_FACE_BAD,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jt4websites@googlemail.com designates 209.85.212.44 as permitted sender) Received: from [209.85.212.44] (HELO mail-vw0-f44.google.com) (209.85.212.44) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 19 Feb 2011 19:36:06 +0000 Received: by vws7 with SMTP id 7so2915032vws.31 for ; Sat, 19 Feb 2011 11:35:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=DgGSQF2st2DbK0vb4nlAJaU3mQ8lfYjBzCHhIL3qsjc=; b=Z18apmfdQ7MV+Jr1SvMYR56CncL5Z3cHpnHEKsPTgzT21OfKj55EZT+JbcFb//LvFT 52PGrpeiB2PtZTO0lo62MbpOz3XYU5piBdGJ546nW73YsiA6tF/zF8yZneqHR8r28nCH ooExAgBouz3EFrxBCCQjc+QOaPKhPBLKEEFaY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=iOj6iH92sn6QCJynExPllFnv9NCMH62hLMG6KrS1OudjRXB05l4toskP2jOgSHAy8N tgHxzN2uZNkayqmKz2hpC0n6gjo9HPUINJ0Fmu7J9Mdt+8SLG6RjQLSa//qsAbQK87oG tfq9lKETrgGRXM7VFeRrETzZR2CUeG/gBNmVk= MIME-Version: 1.0 Received: by 10.52.166.102 with SMTP id zf6mr3630451vdb.89.1298144145811; Sat, 19 Feb 2011 11:35:45 -0800 (PST) Received: by 10.220.100.66 with HTTP; Sat, 19 Feb 2011 11:35:45 -0800 (PST) In-Reply-To: References: Date: Sat, 19 Feb 2011 19:35:45 +0000 Message-ID: Subject: Re: simple erlang example From: J T To: user@cassandra.apache.org Content-Type: multipart/alternative; boundary=20cf306847e3ada9ba049ca7bc2a --20cf306847e3ada9ba049ca7bc2a Content-Type: text/plain; charset=ISO-8859-1 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 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 > --20cf306847e3ada9ba049ca7bc2a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi Sasha,

Below is some code fr= om an old module I was working with a while back.

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

= * =A0cassandra_thrift.erl=A0
=
= * =A0cassandra_thrift.hrl=A0
=
= * =A0cassandra_types.erl=A0
= * =A0cassandra_types.hrl

% -- Snip --
=

get_connection( Host, KeySpace, Credentials) when is_list= (KeySpace) ->
=A0=A0 =A0get_connection( Host, list_to_b= inary(KeySpace), Credentials );

get_connection( Host, KeySpace, Credentials) whe= n is_binary(KeySpace) ->
=A0=A0 =A0case thrift_client_util:new(Host, 9160, cassandra_thrift, [ = { framed, true } ] ) of
=A0=A0 =A0 =A0 =A0{ok, Connection = } -> set_keyspace( Connection, KeySpace ),
=A0=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 authenticat= e( Connection, Credentials ),
=A0=A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Connection;
=A0=A0 =A0 =A0 =A0_ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -> throw({ get_= connection, "Failed to get connection to cassandra!" })
=A0=A0 =A0end.

=A0=A0 =A0authenticate( Connection, _Creden= tials ) ->
=A0=A0 =A0 =A0 =A0thrift_client:call( Connection, login, [ #authentica= tionRequest{ credentials =3D dict:new() } ]).

=A0=A0 =A0set_keyspace( Connection, KeySpace ) ->=
=A0=A0 =A0 =A0 =A0thrift_client:call( Connection, set_key= space, [ KeySpace ]).

% Key =3D ... =A0 =A0 =A0 =A0 =A0 =A0 =A0e= .g. <<"ARowKey">>
% CF =A0=3D ColumnFamily =A0 =A0 e.g. <<"TestColumnFamily&q= uot;>>
% SC =A0=3D SuperColumn =A0 =A0 =A0e.g. <&= lt;"TestSuperColumn">>
% C =A0 =3D Column =A0 =A0 =A0 =A0 =A0 e.g. <<= "TestColumn">>
% CL =A0=3D ConsistencyLevel e.g.=A0?cassandra_ConsistencyLevel_QUORUM=

get( Connection, Key, CF, SC, C,= CL =A0) when is_binary(CF), is_binary(C) ->
=A0=A0 =A0= try thrift_client:call( Connection, get, [ Key, #columnPath{ column_family = =3D CF, super_column =3D SC, column =3D C }, CL ]) of
=A0=A0 =A0 =A0 =A0{ _, { ok, R =A0}} -> R;
=A0=A0 = =A0 =A0 =A0{ _, { _, =A0E1 }} -> throw( { ?MODULE, get, E1 } );
=A0=A0 =A0 =A0 =A0X =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-> throw( { ?MOD= ULE, get, X =A0} )
=A0=A0 =A0catch
=A0=A0 =A0 =A0 =A0throw:notFoundException =A0 -> notfound
=A0=A0 =A0end.

% --= Snip --

Example Call Might be:
=

Connection =A0=3D=A0get_connection( "localhost", &= quot;TestKeySpace", "" ),
ColumnValue =3D ?MODULE:get( Connection, <<"ARowKey"= >>, <<"TestColumnFamily">>,=A0<<"= TestSuperColumn">>, <<"TestColumn">>,=A0=A0?cassandra_ConsistencyLevel_QUORUM )


On Fri, Feb 18, 2011 a= t 10:39 PM, Sasha Dolgy <sdolgy@gmail.com> wrote:
hi,

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

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

I generated all of the erlang files using thrift and ha= ve successfully compiled them but am having a pretty rough go at it.
<= div>
Found this old post: =A0http://www.mail-archive.com/cassandra-user@incubator.apache.org/msg02893.h= tml=A0... but seems the examples never made it to the wiki.

-sd

--
Sasha Dolgy
sasha.dolgy@gmail.com

--20cf306847e3ada9ba049ca7bc2a--