You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Zubair Quraishi <zu...@gmail.com> on 2010/04/30 15:58:09 UTC

Batch mutate doesn't work

I have the following code in Erlang to set a value and then add a
property. The first set works but the mutate fails. Can anyone
enlighten me?
Thanks

 {ok, C} = thrift_client:start_link("127.0.0.1",9160, cassandra_thrift),

 Key = "Key1",

 %
 % set first property
 %
 thrift_client:call( C,
                  'insert',
                  [ "Keyspace1",
                    Key,
                    #columnPath{column_family="KeyValue", column="value"},
                    "value1",
                    1,
                    1
                    ] ),

 %
 % set second property ( fails! - why? )
 %
 MutationMap =
 {
   Key,
   {
     <<"KeyValue">>,
     [
       #mutation{
         column_or_supercolumn = #column{ name = "property" , value =
"value" , timestamp = 2 }
       }
     ]
   }
 },
 thrift_client:call( C,
   'batch_mutate',
   [ "Keyspace1",
      MutationMap,
      1
   ] )

: The error returned is :

** exception exit: {bad_return_value,{error,{function_clause,[{dict,size,
                                                                   [{"Key1",

{<<"KeyValue">>,

[{mutation,{column,"property","value",2},undefined}]}}]},

{thrift_protocol,write,2},

{thrift_protocol,struct_write_loop,3},

{thrift_protocol,write,2},

{thrift_client,send_function_call,3},

{thrift_client,'-handle_call/3-fun-0-',3},

{thrift_client,catch_function_exceptions,2},

{thrift_client,handle_call,3}]}}}
7>
=ERROR REPORT==== 30-Apr-2010::15:13:42 ===
** Generic server <0.55.0> terminating
** Last message in was {call,batch_mutate,
                          ["Keyspace1",
                           {"Key1",
                            {<<"KeyValue">>,
                             [{mutation,
                                  {column,"property","value",2},
                                  undefined}]}},
                           1]}
** When Server state == {state,cassandra_thrift,
                        {protocol,thrift_binary_protocol,
                         {binary_protocol,
                          {transport,thrift_buffered_transport,<0.58.0>},
                          true,true}},
                        0}
** Reason for termination ==
** {bad_return_value,
      {error,
          {function_clause,
              [{dict,size,
                   [{"Key1",
                     {<<"KeyValue">>,
                      [{mutation,
                           {column,"property","value",2},
                           undefined}]}}]},
               {thrift_protocol,write,2},
               {thrift_protocol,struct_write_loop,3},
               {thrift_protocol,write,2},
               {thrift_client,send_function_call,3},
               {thrift_client,'-handle_call/3-fun-0-',3},
               {thrift_client,catch_function_exceptions,2},
               {thrift_client,handle_call,3}]}}}

Re: Batch mutate doesn't work

Posted by Jonathan Ellis <jb...@gmail.com>.
like I told you on the other list, erlang or the erlang thrift
compiler is not exposing the error the cassandra server is sending
you.  "bad_return_value" is not it.

Unless someone with actual erlang experience chimes in here, I would
suggest trying with Python first, at least that will show you the real
error.  Then you can port back to erlang if you want.

On Fri, Apr 30, 2010 at 8:58 AM, Zubair Quraishi <zu...@gmail.com> wrote:
> I have the following code in Erlang to set a value and then add a
> property. The first set works but the mutate fails. Can anyone
> enlighten me?
> Thanks
>
>  {ok, C} = thrift_client:start_link("127.0.0.1",9160, cassandra_thrift),
>
>  Key = "Key1",
>
>  %
>  % set first property
>  %
>  thrift_client:call( C,
>                  'insert',
>                  [ "Keyspace1",
>                    Key,
>                    #columnPath{column_family="KeyValue", column="value"},
>                    "value1",
>                    1,
>                    1
>                    ] ),
>
>  %
>  % set second property ( fails! - why? )
>  %
>  MutationMap =
>  {
>   Key,
>   {
>     <<"KeyValue">>,
>     [
>       #mutation{
>         column_or_supercolumn = #column{ name = "property" , value =
> "value" , timestamp = 2 }
>       }
>     ]
>   }
>  },
>  thrift_client:call( C,
>   'batch_mutate',
>   [ "Keyspace1",
>      MutationMap,
>      1
>   ] )
>
> : The error returned is :
>
> ** exception exit: {bad_return_value,{error,{function_clause,[{dict,size,
>                                                                   [{"Key1",
>
> {<<"KeyValue">>,
>
> [{mutation,{column,"property","value",2},undefined}]}}]},
>
> {thrift_protocol,write,2},
>
> {thrift_protocol,struct_write_loop,3},
>
> {thrift_protocol,write,2},
>
> {thrift_client,send_function_call,3},
>
> {thrift_client,'-handle_call/3-fun-0-',3},
>
> {thrift_client,catch_function_exceptions,2},
>
> {thrift_client,handle_call,3}]}}}
> 7>
> =ERROR REPORT==== 30-Apr-2010::15:13:42 ===
> ** Generic server <0.55.0> terminating
> ** Last message in was {call,batch_mutate,
>                          ["Keyspace1",
>                           {"Key1",
>                            {<<"KeyValue">>,
>                             [{mutation,
>                                  {column,"property","value",2},
>                                  undefined}]}},
>                           1]}
> ** When Server state == {state,cassandra_thrift,
>                        {protocol,thrift_binary_protocol,
>                         {binary_protocol,
>                          {transport,thrift_buffered_transport,<0.58.0>},
>                          true,true}},
>                        0}
> ** Reason for termination ==
> ** {bad_return_value,
>      {error,
>          {function_clause,
>              [{dict,size,
>                   [{"Key1",
>                     {<<"KeyValue">>,
>                      [{mutation,
>                           {column,"property","value",2},
>                           undefined}]}}]},
>               {thrift_protocol,write,2},
>               {thrift_protocol,struct_write_loop,3},
>               {thrift_protocol,write,2},
>               {thrift_client,send_function_call,3},
>               {thrift_client,'-handle_call/3-fun-0-',3},
>               {thrift_client,catch_function_exceptions,2},
>               {thrift_client,handle_call,3}]}}}
>



-- 
Jonathan Ellis
Project Chair, Apache Cassandra
co-founder of Riptano, the source for professional Cassandra support
http://riptano.com

Re: Batch mutate doesn't work

Posted by Anthony Molinaro <an...@alumni.caltech.edu>.
On Fri, Apr 30, 2010 at 03:58:09PM +0200, Zubair Quraishi wrote:
>  %
>  % set second property ( fails! - why? )
>  %
>  MutationMap =
>  {
>    Key,
>    {
>      <<"KeyValue">>,
>      [
>        #mutation{
>          column_or_supercolumn = #column{ name = "property" , value =
> "value" , timestamp = 2 }
>        }
>      ]
>    }
>  },
>  thrift_client:call( C,
>    'batch_mutate',
>    [ "Keyspace1",
>       MutationMap,
>       1
>    ] )

I haven't actually tried compiling this, but looking at the records in
the generated .hrl file and the .thrift file it looks like column_or_supercolumn
in the mutation record is a #columnOrSuperColumn record, so I think you want

  MutationMap =
  {
    Key,
    {
      <<"KeyValue">>,
      [
        #mutation {
          column_or_supercolumn =
            #columnOrSuperColumn {
              column =
                #column {
                  name = "property",
                  value = "value",
                  timestamp = 2
                }
            }
        }
      ]
    }
  },

Try that,

-Anthony

-- 
------------------------------------------------------------------------
Anthony Molinaro                           <an...@alumni.caltech.edu>

Re: Batch mutate doesn't work

Posted by Erik Bogghed <bo...@codemate.se>.
Try this. You need to use the dict module. 

MutationMap = dict:store(Key,
			dict:store("KeyValue",
			[
				#mutation {column_or_supercolumn = 
					#columnOrSuperColumn {column = 
						#column {name = "property", value="value", timestamp = 2}}}
			], dict:new()),
		dict:new()),

Erik


On 30 apr 2010, at 15.58, Zubair Quraishi wrote:

> I have the following code in Erlang to set a value and then add a
> property. The first set works but the mutate fails. Can anyone
> enlighten me?
> Thanks
> 
> {ok, C} = thrift_client:start_link("127.0.0.1",9160, cassandra_thrift),
> 
> Key = "Key1",
> 
> %
> % set first property
> %
> thrift_client:call( C,
>                  'insert',
>                  [ "Keyspace1",
>                    Key,
>                    #columnPath{column_family="KeyValue", column="value"},
>                    "value1",
>                    1,
>                    1
>                    ] ),
> 
> %
> % set second property ( fails! - why? )
> %
> MutationMap =
> {
>   Key,
>   {
>     <<"KeyValue">>,
>     [
>       #mutation{
>         column_or_supercolumn = #column{ name = "property" , value =
> "value" , timestamp = 2 }
>       }
>     ]
>   }
> },
> thrift_client:call( C,
>   'batch_mutate',
>   [ "Keyspace1",
>      MutationMap,
>      1
>   ] )
> 
> : The error returned is :
> 
> ** exception exit: {bad_return_value,{error,{function_clause,[{dict,size,
>                                                                   [{"Key1",
> 
> {<<"KeyValue">>,
> 
> [{mutation,{column,"property","value",2},undefined}]}}]},
> 
> {thrift_protocol,write,2},
> 
> {thrift_protocol,struct_write_loop,3},
> 
> {thrift_protocol,write,2},
> 
> {thrift_client,send_function_call,3},
> 
> {thrift_client,'-handle_call/3-fun-0-',3},
> 
> {thrift_client,catch_function_exceptions,2},
> 
> {thrift_client,handle_call,3}]}}}
> 7>
> =ERROR REPORT==== 30-Apr-2010::15:13:42 ===
> ** Generic server <0.55.0> terminating
> ** Last message in was {call,batch_mutate,
>                          ["Keyspace1",
>                           {"Key1",
>                            {<<"KeyValue">>,
>                             [{mutation,
>                                  {column,"property","value",2},
>                                  undefined}]}},
>                           1]}
> ** When Server state == {state,cassandra_thrift,
>                        {protocol,thrift_binary_protocol,
>                         {binary_protocol,
>                          {transport,thrift_buffered_transport,<0.58.0>},
>                          true,true}},
>                        0}
> ** Reason for termination ==
> ** {bad_return_value,
>      {error,
>          {function_clause,
>              [{dict,size,
>                   [{"Key1",
>                     {<<"KeyValue">>,
>                      [{mutation,
>                           {column,"property","value",2},
>                           undefined}]}}]},
>               {thrift_protocol,write,2},
>               {thrift_protocol,struct_write_loop,3},
>               {thrift_protocol,write,2},
>               {thrift_client,send_function_call,3},
>               {thrift_client,'-handle_call/3-fun-0-',3},
>               {thrift_client,catch_function_exceptions,2},
>               {thrift_client,handle_call,3}]}}}