Many thanks for your code, would you please send me the get_slice() function
as well so I can compile it?

thanks in advance

Juan


2010/3/15 casablinca126.com <casabli...@126.com>

>  hello Juan,
> this is the C++ code with super-column  I'm using. I hope it will be
> useful :
>
> #include "Cassandra.h"
> #include <protocol/TBinaryProtocol.h>
> #include <transport/TBufferTransports.h>
> #include <transport/TSocket.h>
> #include <string>
> //#include <stdio.h>
> #include <iostream>
> #include <fstream>
> #include <pthread.h>
> #include <vector>
> #include <map>
>
> using namespace std;
>
> using namespace ::apache::thrift;
> using namespace ::apache::thrift::protocol;
> using namespace ::apache::thrift::transport;
>
> using boost::shared_ptr;
>
> using namespace org::apache::cassandra;
>
> //macros..
> #define MAX_STRLEN  100000
> #define ITEM_COUNT   100000
> #define ChapterNumPerNovel 30
>
> //global variables  & functions
>
> int port = 9160;
>
> void insert();
> void get(void );
> void get_slice();
> void remove();
>
> const string strKeyspace = "Keyspace1";
> const string strColFamily_org = "Super1";
> string strColFamily = "Super1";
> string strColOrg = "chapter";
> string strCol = "chapter";
> string strSuperColOrg = "Novel";
> string strSuperCol = "Novel";
> string strKeyOrg = "novel_key";
> string strKey = "novel_key";
> string strValue = "";
> size_t thread_id = 0;
>
> bool STOP = false;
> size_t start_time = 0;
> size_t average_time = 0;
> int ret_num = 0;
> unsigned long long total_get_count = 0;
> unsigned long long ntmp = 10;
> int error_num = 0;
>
>
>
>
>
> int main(int argc, char **argv)
> {
>  //insert();
>  //get(NULL);
>  get_slice();
>  //remove();
>
>
>  return EXIT_SUCCESS;
> }
>
>
> void insert()
> {
>
>  shared_ptr<TTransport> socket_novel(new TSocket("localhost", port));
>  shared_ptr<TTransport> transport_novel(new
> TBufferedTransport(socket_novel) );
>  shared_ptr<TProtocol> protocol_novel(new TBinaryProtocol(transport_novel)
> );
>  CassandraClient client(protocol_novel);
>  transport_novel->open();
>  string strValueOrg = "1234567";
>
>
>  ColumnPath col_path;
>  int i = 0;
>  char chTmp[MAX_STRLEN];
>  string str_zeros;
>  while(i<ITEM_COUNT )
>  {
>   memset(&chTmp, 0, MAX_STRLEN);
>   sprintf(chTmp, "%d", i++);
>
>   strValue = strValueOrg + string(chTmp);
>   strKey = strKeyOrg + string(chTmp);
>   strSuperCol = strSuperColOrg + string(chTmp);
>
>   col_path.column_family.assign(strColFamily );
>   col_path.column.assign(strCol);
>   col_path.super_column.assign(strSuperCol);
>   col_path.__isset.super_column = true;
>   col_path.__isset.column = true;
>
>
>   try
>   {
>    for(int j=0; j<ChapterNumPerNovel; j++)
>    {
>     memset(&chTmp, 0, MAX_STRLEN);
>     sprintf(chTmp, "%d", j);
>     int len = string(chTmp).length();
>     str_zeros = "";
>     for(int k=len; k<10; k++)
>     {
>      str_zeros += "0";
>     }
>     strCol= strSuperCol + "_" + strColOrg + str_zeros + string(chTmp);
>     col_path.column.assign(strCol);
>     client.insert(strKeyspace,strKey, col_path, strValue,time(NULL), ONE);
>    }
>   }
>   catch(TException &tx)
>   {
>    printf("ERROR: %s\n", tx.what());
>    error_num ++ ;
>   }
>
>   total_get_count ++ ;
>
>  }
>
>  STOP = true;
>  transport_novel->close();
> }
> //---------------------------------------
>
> cheers,
> Cao Jiguang
>
>
> 2010-03-16
> ------------------------------
>  casablinca126.com
> ------------------------------
>  *发件人:* Juan Manuel Garcia del Moral
> *发送时间:* 2010-03-16  05:16:50
> *收件人:* user@cassandra.apache.org
> *抄送:*
> *主题:* Re: SuperColumns in C++ API
>  Ok, I'll check out libcassandra in a while.
>
> I've been able to insert values with this:
>
>     new_col.__isset.super_column = true;
>     new_col.__isset.column     = true; /* this is required! */
>     new_col.column_family.assign("Anonimos");
>     new_col.super_column.assign("Tag");
>     new_col.column.assign("300");
>
>     client.insert("SocialAds",
>                   "50",
>                   new_col,
>                   "5",
>                   12345678,
>                   ONE);
>
> I thought I could GET it by doing:
>
>     client.get(ret_val,
>                "SocialAds",
>                "50",
>                new_col,
>                ONE);
>
> But I'm getting this error:
>  Default TException.
>
> Ah nothing on the server log
>
> Thanks, and sorry for all these newbie questions
>
>
> 2010/3/15 Jonathan Ellis <jbel...@gmail.com>
>
>> you're still not setting isset on column_family.
>>
>> you need both isset and assign on each value you're sending.
>>
>> maybe you should use http://github.com/posulliv/libcassandra ?
>>
>> On Mon, Mar 15, 2010 at 3:29 PM, Juan Manuel Garcia del Moral
>>  <j...@southcode.com.ar> wrote:
>> > Ok,
>> >
>> > Now I've changed to:
>> >
>> >     ColumnPath new_col;
>> >     new_col.__isset.super_column = true;
>> >     new_col.__isset.column     = true; /* this is required! */
>> >     new_col.column_family.assign("Anonimos");
>> >     new_col.super_column.assign("Tag");
>> >     new_col.column.assign("300");
>> >
>> >
>> >     client.insert("SocialAds",
>> >                   "1",
>> >                   new_col,
>> >                   "200",
>> >                   12345678,
>> >                   ONE);
>> >
>> > I'm not getting any error but no entry on the log either, and the value
>> is
>> > not being inserted...
>> >
>> >
>> > Thanks
>> >
>> >
>> > 2010/3/15 Jonathan Ellis <jbel...@gmail.com>
>> >>
>> >> Ah, thrift is letting you set something to be null, that shouldn't be
>> >> legal.  This is fixed in 0.6 svn, btw.
>> >>
>> >> it looks like you are setting new_col.__isset.column to true, but not
>> >> actually assigning it a value.
>> >>
>> >> On Mon, Mar 15, 2010 at 3:14 PM, Juan Manuel Garcia del Moral
>> >> <j...@southcode.com.ar> wrote:
>> >> > This is what the log says:
>> >> >
>> >> > ERROR [pool-1-thread-8] 2010-03-15 15:54:06,753 Cassandra.java (line
>> >> > 1482)
>> >> > Internal error processing insert
>> >> > java.lang.AssertionError: QueryPath(columnFamilyName='Anonimos',
>> >> > superColumnName='[...@d0357a', columnName='null')
>> >> >         at
>> >> > org.apache.cassandra.db.ColumnFamily.addColumn(ColumnFamily.java:165)
>> >> >         at
>> >> > org.apache.cassandra.db.ColumnFamily.addColumn(ColumnFamily.java:159)
>> >> >         at
>> org.apache.cassandra.db.RowMutation.add(RowMutation.java:159)
>> >> >         at
>> >> >
>> >> >
>> org.apache.cassandra.thrift.CassandraServer.insert(CassandraServer.java:351)
>> >> >         at
>> >> >
>> >> >
>> org.apache.cassandra.thrift.Cassandra$Processor$insert.process(Cassandra.java:1474)
>> >> >         at
>> >> >
>> >> >
>> org.apache.cassandra.thrift.Cassandra$Processor.process(Cassandra.java:1115)
>> >> >         at
>> >> >
>> >> >
>> org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:253)
>> >> >         at
>> >> >
>> >> >
>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>> >> >         at
>> >> >
>> >> >
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>> >> >         at java.lang.Thread.run(Thread.java:619)
>> >> >
>> >> >
>> >> > I need to do replicate this:
>> >> > set SocialAds.Anonimos['122']['Tag']['150'] = '100';
>> >> >
>> >> > from my code...
>> >> >
>> >> > any ideas?
>> >> >
>> >> > thanks in advance
>> >> >
>> >> > Juan
>> >> >
>> >> >
>> >> > 2010/3/15 Jonathan Ellis <jbel...@gmail.com>
>> >> >>
>> >> >> check the server log for exception.  and if you are not on 0.5.1 or
>> >> >> 0.6 svn branch, upgrade.
>> >> >>
>> >> >> On Mon, Mar 15, 2010 at 12:47 PM, Juan Manuel Garcia del Moral
>> >> >> <j...@southcode.com.ar> wrote:
>> >> >> > Many thanks!
>> >> >> >
>> >> >> > That seems to be useful,
>> >> >> >
>> >> >> > But now I'm getting
>> >> >> >  The error message: "Internal error processing insert"
>> >> >> >
>> >> >> > I'm not sure if I'm setting the timestamp properly
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > 2010/3/15 Padraig O'Sullivan <osullivan.padr...@gmail.com>
>> >> >> >>
>> >> >> >> You need to manually set the __isset fields when using the thift
>> API
>> >> >> >> in C++. Since you are trying to insert a super column, you need
>> to
>> >> >> >> set
>> >> >> >> the super_column __isset field.
>> >> >> >>
>> >> >> >> So this:
>> >> >> >>
>> >> >> >> new_col.__isset.column = true;
>> >> >> >>
>> >> >> >> should become:
>> >> >> >>
>> >> >> >> new_col.__isset.super_column = true;
>> >> >> >>
>> >> >> >> -Padraig
>> >> >> >>
>> >> >> >> On Mon, Mar 15, 2010 at 12:36 PM, Juan Manuel Garcia del Moral
>> >> >> >> <j...@southcode.com.ar> wrote:
>> >> >> >> > Hello
>> >> >> >> >
>> >> >> >> > I'm trying to add values using supercolumns but I get this
>> error
>> >> >> >> >
>> >> >> >> > ERROR: supercolumn parameter is not optional for super CF
>> Anonimos
>> >> >> >> >
>> >> >> >> > This is my code
>> >> >> >> >
>> >> >> >> > // **********
>> >> >> >> >  ColumnPath new_col;
>> >> >> >> >     new_col.__isset.column     = true; /* this is required! */
>> >> >> >> >     new_col.column_family.assign("Anonimos");
>> >> >> >> >     new_col.super_column.assign("Tag");
>> >> >> >> >
>> >> >> >> >     client.insert("SocialAds",
>> >> >> >> >                   "1",
>> >> >> >> >                   new_col,
>> >> >> >> >                   "200",
>> >> >> >> >                   123456789,
>> >> >> >> >                   ONE);
>> >> >> >> >
>> >> >> >> > // **********
>> >> >> >> >
>> >> >> >> > What I'm doing wrong?
>> >> >> >> >
>> >> >> >> > Thanks
>> >> >> >> >
>> >> >> >> > Juan
>> >> >> >> >
>> >> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >>
>> >> >
>> >> >
>> >> >
>> >
>> >
>> >
>> > --
>> > Juan Manuel García del Moral
>> > Southcode Global IT Resources
>> > j...@southcode.com.ar
>> > http://www.southcode.com.ar
>> >
>> >
>>
>
>
>
> --
> Juan Manuel García del Moral
> Southcode Global IT Resources
> j...@southcode.com.ar
> http://www.southcode.com.ar
>
>


-- 
Juan Manuel García del Moral
Southcode Global IT Resources
j...@southcode.com.ar
http://www.southcode.com.ar

Reply via email to