Browse files

Fixed bug in get_range. Slightly improved error messages.

  • Loading branch information...
1 parent f28428e commit 58a520cd83de6bce6c2faac011b5a723c969f459 @fmgoncalves committed Jul 19, 2011
Showing with 100 additions and 81 deletions.
  1. +57 −57 lib/Cassandra/Cassandra.pm
  2. +43 −24 lib/Cassandra/Simple.pm
View
114 lib/Cassandra/Cassandra.pm
@@ -6263,7 +6263,7 @@ sub recv_login{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_login_result();
$result->read($self->{input});
@@ -6309,14 +6309,14 @@ sub recv_set_keyspace{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_set_keyspace_result();
$result->read($self->{input});
$self->{input}->readMessageEnd();
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
return;
}
@@ -6358,7 +6358,7 @@ sub recv_get{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_get_result();
$result->read($self->{input});
@@ -6368,7 +6368,7 @@ sub recv_get{
return $result->{success};
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{nfe}) {
die $result->{nfe}->getName();
@@ -6422,7 +6422,7 @@ sub recv_get_slice{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_get_slice_result();
$result->read($self->{input});
@@ -6432,7 +6432,7 @@ sub recv_get_slice{
return $result->{success};
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{ue}) {
die $result->{ue}->getName();
@@ -6483,7 +6483,7 @@ sub recv_get_count{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_get_count_result();
$result->read($self->{input});
@@ -6493,7 +6493,7 @@ sub recv_get_count{
return $result->{success};
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{ue}) {
die $result->{ue}->getName();
@@ -6544,7 +6544,7 @@ sub recv_multiget_slice{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_multiget_slice_result();
$result->read($self->{input});
@@ -6554,7 +6554,7 @@ sub recv_multiget_slice{
return $result->{success};
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{ue}) {
die $result->{ue}->getName();
@@ -6605,7 +6605,7 @@ sub recv_multiget_count{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_multiget_count_result();
$result->read($self->{input});
@@ -6615,7 +6615,7 @@ sub recv_multiget_count{
return $result->{success};
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{ue}) {
die $result->{ue}->getName();
@@ -6666,7 +6666,7 @@ sub recv_get_range_slices{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_get_range_slices_result();
$result->read($self->{input});
@@ -6676,7 +6676,7 @@ sub recv_get_range_slices{
return $result->{success};
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{ue}) {
die $result->{ue}->getName();
@@ -6727,7 +6727,7 @@ sub recv_get_indexed_slices{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_get_indexed_slices_result();
$result->read($self->{input});
@@ -6737,7 +6737,7 @@ sub recv_get_indexed_slices{
return $result->{success};
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{ue}) {
die $result->{ue}->getName();
@@ -6788,14 +6788,14 @@ sub recv_insert{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_insert_result();
$result->read($self->{input});
$self->{input}->readMessageEnd();
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{ue}) {
die $result->{ue}->getName();
@@ -6846,14 +6846,14 @@ sub recv_add{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_add_result();
$result->read($self->{input});
$self->{input}->readMessageEnd();
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{ue}) {
die $result->{ue}->getName();
@@ -6904,14 +6904,14 @@ sub recv_remove{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_remove_result();
$result->read($self->{input});
$self->{input}->readMessageEnd();
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{ue}) {
die $result->{ue}->getName();
@@ -6959,14 +6959,14 @@ sub recv_remove_counter{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_remove_counter_result();
$result->read($self->{input});
$self->{input}->readMessageEnd();
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{ue}) {
die $result->{ue}->getName();
@@ -7011,14 +7011,14 @@ sub recv_batch_mutate{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_batch_mutate_result();
$result->read($self->{input});
$self->{input}->readMessageEnd();
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{ue}) {
die $result->{ue}->getName();
@@ -7060,14 +7060,14 @@ sub recv_truncate{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_truncate_result();
$result->read($self->{input});
$self->{input}->readMessageEnd();
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{ue}) {
die $result->{ue}->getName();
@@ -7103,7 +7103,7 @@ sub recv_describe_schema_versions{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_describe_schema_versions_result();
$result->read($self->{input});
@@ -7113,7 +7113,7 @@ sub recv_describe_schema_versions{
return $result->{success};
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
die "describe_schema_versions failed: unknown result";
}
@@ -7146,7 +7146,7 @@ sub recv_describe_keyspaces{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_describe_keyspaces_result();
$result->read($self->{input});
@@ -7156,7 +7156,7 @@ sub recv_describe_keyspaces{
return $result->{success};
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
die "describe_keyspaces failed: unknown result";
}
@@ -7189,7 +7189,7 @@ sub recv_describe_cluster_name{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_describe_cluster_name_result();
$result->read($self->{input});
@@ -7229,7 +7229,7 @@ sub recv_describe_version{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_describe_version_result();
$result->read($self->{input});
@@ -7272,7 +7272,7 @@ sub recv_describe_ring{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_describe_ring_result();
$result->read($self->{input});
@@ -7282,7 +7282,7 @@ sub recv_describe_ring{
return $result->{success};
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
die "describe_ring failed: unknown result";
}
@@ -7315,7 +7315,7 @@ sub recv_describe_partitioner{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_describe_partitioner_result();
$result->read($self->{input});
@@ -7355,7 +7355,7 @@ sub recv_describe_snitch{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_describe_snitch_result();
$result->read($self->{input});
@@ -7398,7 +7398,7 @@ sub recv_describe_keyspace{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_describe_keyspace_result();
$result->read($self->{input});
@@ -7411,7 +7411,7 @@ sub recv_describe_keyspace{
die $result->{nfe}->getName();
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
die "describe_keyspace failed: unknown result";
}
@@ -7456,7 +7456,7 @@ sub recv_describe_splits{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_describe_splits_result();
$result->read($self->{input});
@@ -7466,7 +7466,7 @@ sub recv_describe_splits{
return $result->{success};
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
die "describe_splits failed: unknown result";
}
@@ -7502,7 +7502,7 @@ sub recv_system_add_column_family{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_system_add_column_family_result();
$result->read($self->{input});
@@ -7512,7 +7512,7 @@ sub recv_system_add_column_family{
return $result->{success};
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{sde}) {
die $result->{sde}->getName();
@@ -7551,7 +7551,7 @@ sub recv_system_drop_column_family{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_system_drop_column_family_result();
$result->read($self->{input});
@@ -7561,7 +7561,7 @@ sub recv_system_drop_column_family{
return $result->{success};
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{sde}) {
die $result->{sde}->getName();
@@ -7600,7 +7600,7 @@ sub recv_system_add_keyspace{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_system_add_keyspace_result();
$result->read($self->{input});
@@ -7610,7 +7610,7 @@ sub recv_system_add_keyspace{
return $result->{success};
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{sde}) {
die $result->{sde}->getName();
@@ -7649,7 +7649,7 @@ sub recv_system_drop_keyspace{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_system_drop_keyspace_result();
$result->read($self->{input});
@@ -7659,7 +7659,7 @@ sub recv_system_drop_keyspace{
return $result->{success};
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{sde}) {
die $result->{sde}->getName();
@@ -7698,7 +7698,7 @@ sub recv_system_update_keyspace{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_system_update_keyspace_result();
$result->read($self->{input});
@@ -7708,7 +7708,7 @@ sub recv_system_update_keyspace{
return $result->{success};
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{sde}) {
die $result->{sde}->getName();
@@ -7747,7 +7747,7 @@ sub recv_system_update_column_family{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_system_update_column_family_result();
$result->read($self->{input});
@@ -7757,7 +7757,7 @@ sub recv_system_update_column_family{
return $result->{success};
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{sde}) {
die $result->{sde}->getName();
@@ -7799,7 +7799,7 @@ sub recv_execute_cql_query{
my $x = new TApplicationException();
$x->read($self->{input});
$self->{input}->readMessageEnd();
- die $x->getMessage();
+ die $x->getMessage()->getMessage();
}
my $result = new Cassandra::Cassandra_execute_cql_query_result();
$result->read($self->{input});
@@ -7809,7 +7809,7 @@ sub recv_execute_cql_query{
return $result->{success};
}
if (defined $result->{ire}) {
- die $result->{ire}->why;
+ die $result->{ire}->why->why;
}
if (defined $result->{ue}) {
die $result->{ue}->getName();
View
67 lib/Cassandra/Simple.pm
@@ -80,7 +80,8 @@ use Thrift;
use Thrift::BinaryProtocol;
use Thrift::FramedTransport;
use Thrift::Socket;
-
+use strict;
+use warnings;
### Thrift Protocol/Client methods ###
sub _build_client {
@@ -442,8 +443,13 @@ sub get_range {
$keyRange, $level );
my %result_columns = map {
- $_->{key} => [ map { $self->_column_or_supercolumn_to_hash($_) }
- @{ $_->{columns} } ]
+ $_->{key} => {
+ map {
+ my $a = $self->_column_or_supercolumn_to_hash($_);
+ $a->[0] => $a->[1]
+ }
+ @{ $_->{columns} }
+ }
} @{$result};
return \%result_columns;
@@ -824,45 +830,53 @@ sub create_column_family {
$self->client->system_add_column_family($cfdef);
}
-
=head2 create_index
Usage: C<< create_index($keyspace, $column_family, $column, [$validation_class]) >>
Creates an index on C<$column> of C<$column_family>.
-$validation_class only applies when $column doesn't yet exist, and even then it is optional (defaults to BytesType).
+C<$validation_class> only applies when C<$column> doesn't yet exist, and even then it is optional (defaults to I<BytesType>).
=cut
-sub create_index{
+
+sub create_index {
my $self = shift;
my $keyspace = shift;
my $column_family = shift;
- my $column = shift;
-
- #TODO: get column family definition, substitute the target column with itself but indexed.
-
- my $cfdef = [grep {$_->{name} eq $column_family } @{ $self->client->describe_keyspace($keyspace)->{cf_defs} }]->[0];
-
+ my $column = shift;
+
+#TODO: get column family definition, substitute the target column with itself but indexed.
+
+ my $cfdef =
+ [ grep { $_->{name} eq $column_family }
+ @{ $self->client->describe_keyspace($keyspace)->{cf_defs} } ]->[0];
+
my $cdef;
- if(@{ $cfdef->{column_metadata} } and grep {$_->{name} eq $column } @{ $cfdef->{column_metadata} }){
- $cdef = [grep {$_->{name} eq $column } @{ $cfdef->{column_metadata} }]->[0];
- }else{
- $cdef = new Cassandra::ColumnDef({
- name => $column,
- validation_class => 'org.apache.cassandra.db.marshal.BytesType',
- });
+ if ( @{ $cfdef->{column_metadata} }
+ and grep { $_->{name} eq $column } @{ $cfdef->{column_metadata} } )
+ {
+ $cdef =
+ [ grep { $_->{name} eq $column } @{ $cfdef->{column_metadata} } ]
+ ->[0];
+ } else {
+ $cdef = new Cassandra::ColumnDef(
+ {
+ name => $column,
+ validation_class => 'org.apache.cassandra.db.marshal.BytesType',
+ }
+ );
}
$cdef->{index_type} = 0;
$cdef->{index_name} = $column . "_idx";
-
-
- $cfdef->{column_metadata} = [grep {$_->{name} ne $column } @{ $cfdef->{column_metadata} }];
+
+ $cfdef->{column_metadata} =
+ [ grep { $_->{name} ne $column } @{ $cfdef->{column_metadata} } ];
push @{ $cfdef->{column_metadata} }, $cdef;
-
+
print Dumper $cfdef;
-
+
$self->client->system_update_column_family($cfdef);
}
@@ -885,6 +899,11 @@ L<https://github.com/fmgoncalves/p5-cassandra-simple/tree/master/examples>
=back
+B<Tombstones>
+
+get, get_range and get_indexed_slices should probably filter out tombstones, even if it means returning less than the requested count.
+Ideally it would retry until it got enough results.
+
B<Methods>
The following are Thrift methods left unimplemented.

0 comments on commit 58a520c

Please sign in to comment.