Permalink
Browse files

Fixed full row deletion on method remove.

  • Loading branch information...
1 parent cabb172 commit d6a4347a72898b5d78312f25bb82b4d5571178ca @fmgoncalves committed Aug 25, 2011
Showing with 34 additions and 31 deletions.
  1. +1 −1 README
  2. +6 −0 examples/cassandra_simple_test.pm
  3. +27 −30 lib/Cassandra/Simple.pm
View
2 README
@@ -141,7 +141,7 @@ SYNOPSYS
remove
Usage: "remove($column_family[, $keys][, opt])"
- $keys is an *ARRAY* of keys to be deleted.
+ $keys is key or an *ARRAY* of keys to be deleted.
A removal whitout keys truncates the whole column_family.
@@ -81,6 +81,12 @@ println "\$conn->get_count($column_family, 'whisky2')";
println Dumper $conn->get_count($column_family, 'whisky2');
#Expected result: 1
+println "\$conn->remove($column_family, 'whisky2')";
+println Dumper $conn->remove($column_family, 'whisky2');
+
+println "\$conn->get($column_family, 'whisky2')";
+println Dumper $conn->get($column_family, 'whisky2');
+
println "\$conn->remove($column_family)";
println Dumper $conn->remove($column_family);
View
@@ -447,8 +447,7 @@ sub get_range {
map {
my $a = $self->_column_or_supercolumn_to_hash($_);
$a->[0] => $a->[1]
- }
- @{ $_->{columns} }
+ } @{ $_->{columns} }
}
} @{$result};
@@ -722,7 +721,7 @@ sub batch_insert {
Usage: C<< remove($column_family[, $keys][, opt]) >>
-C<$keys> is key or an I<ARRAY> of keys to be deleted.
+C<$keys> is a key or an I<ARRAY> of keys to be deleted.
A removal whitout keys truncates the whole column_family.
@@ -745,42 +744,40 @@ sub remove {
my $keys = shift;
my $opt = shift // {};
- $keys = [$keys] unless ref($keys) eq 'ARRAY';
-
my $timestamp = time;
my $level = $self->_consistency_level_write($opt);
if ($keys) {
- my $predicate = Cassandra::SlicePredicate->new;
+ $keys = [$keys] unless ref($keys) eq 'ARRAY';
+
+ my $deletion =
+ Cassandra::Deletion->new(
+ {
+ timestamp => $timestamp,
+ super_column => $opt->{super_column} // undef,
+ }
+ );
+
if ( exists $opt->{columns} ) {
- $predicate->{column_names} = $opt->{columns};
- } else {
- my $sliceRange = Cassandra::SliceRange->new($opt);
- $sliceRange->{start} = $opt->{column_start} // '';
- $sliceRange->{finish} = $opt->{column_finish} // '';
- $sliceRange->{reversed} = $opt->{column_reversed} // 0;
- $sliceRange->{count} = $opt->{column_count} // 100;
- $predicate->{slice_range} = $sliceRange;
+ $deletion->{predicate} = Cassandra::SlicePredicate->new(
+ { column_names => $opt->{columns} } );
}
+ # else {#Unsupported by Cassandra yet
+ # my $predicate = Cassandra::SlicePredicate->new;
+ # my $sliceRange = Cassandra::SliceRange->new($opt);
+ # $sliceRange->{start} = $opt->{column_start} // '';
+ # $sliceRange->{finish} = $opt->{column_finish} // '';
+ # $sliceRange->{reversed} = $opt->{column_reversed} // 0;
+ # $sliceRange->{count} = $opt->{column_count} // 100;
+ # $predicate->{slice_range} = $sliceRange;
+ # $deletion->{predicate} = $predicate;
+ # }
+
my %mutation_map = map {
- $_ => {
- $column_family => [
- new Cassandra::Mutation(
- {
- deletion =>
- Cassandra::Deletion->new(
- {
- timestamp => $timestamp,
- super_column => $opt->{super_column} // undef,
- predicate => $predicate,
- }
- )
- }
- )
- ]
- }
+ $_ => { $column_family =>
+ [ new Cassandra::Mutation( { deletion => $deletion, } ) ] }
} @{$keys};
$self->client->batch_mutate( \%mutation_map, $level );

0 comments on commit d6a4347

Please sign in to comment.