Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed method returns (when possible return hash)

  • Loading branch information...
commit 5b7d8121eb77a715a2fc3af788c134995047bb5b 1 parent 15cfcd2
@fmgoncalves authored
Showing with 75 additions and 19 deletions.
  1. +27 −1 README
  2. +8 −4 examples/cassandra_simple_test.pm
  3. +40 −14 lib/Cassandra/Simple.pm
View
28 README
@@ -12,7 +12,33 @@ DESCRIPTION
using Cassandra.
SYNOPSYS
- None yet...
+ #Assuming the keyspace 'simple' and the column family 'simple' exist
+
+ my ($keyspace, $column_family) = qw/simple simple/;
+
+ my $conn = Cassandra::Simple->new(keyspace => $keyspace,);
+
+ $conn->insert($column_family, 'KeyA', [ [ 'ColumnA' => 'AA' ], [ 'ColumnB' => 'AB' ] ] );
+
+ $conn->get($column_family, 'KeyA');
+ $conn->get($column_family, 'KeyA', { columns => [ qw/ColumnA/ ] });
+ $conn->get($column_family, 'KeyA', { column_count => 1, column_reversed => 1 });
+
+ $conn->batch_insert($column_family, { 'KeyB' => [ [ 'ColumnA' => 'BA' ] , [ 'ColumnB' => 'BB' ] ], 'KeyC' => [ [ 'ColumnA' => 'CA' ] , [ 'ColumnD' => 'CD' ] ] });
+
+ $conn->multiget($column_family, [qw/KeyA KeyC/]);
+
+ $conn->get_range($column_family, { start=> 'KeyA', finish => 'KeyB', column_count => 1 });
+ $conn->get_range($column_family);
+
+ $conn->get_indexed_slices($column_family, { expression_list => [ [ 'ColumnA' => 'BA' ] ] });
+
+ $conn->remove($column_family, [ 'KeyA' ], { columns => [ 'ColumnA' ]});
+ $conn->remove($column_family, [ 'KeyA' ]);
+ $conn->remove($column_family);
+
+ $conn->get_count($column_family, 'KeyA');
+ $conn->multiget_count($column_family, [ 'KeyB', 'KeyC' ]);
get
Usage: "get($column_family, $key[, opt])"
View
12 examples/cassandra_simple_test.pm
@@ -13,7 +13,7 @@ use Cassandra::Simple;
#
sub println {
- print $_ foreach @_, "\n";
+ print @_, "\n";
}
my ($keyspace, $column_family) = qw/simple simple/;
@@ -32,7 +32,7 @@ my $conn = Cassandra::Simple->new(
#Method to test code here success
#get 100% 100%
#multiget 100% 100%
-#get_count 0% 0%
+#get_count 100% 100%
#multiget_count 100% 100%
#get_range 100% 100%
#get_indexed_slices 100% 100%
@@ -77,12 +77,16 @@ println "\$conn->remove($column_family, [ 'ChaveA' ], { columns => [ 'ColunaA1'
println Dumper $conn->remove($column_family, [ 'ChaveA' ], { columns => [ 'ColunaA1' ]});
println "\$conn->multiget_count($column_family, ['ChaveA', 'ChaveB'])";
-println Dumper $conn->multiget_count($column_family, ['ChaveA', 'ChaveB']);
+println Dumper$conn->get_count($column_family, 'whisky2');
#Expected result: ChaveA -> 1, ChaveB -> 2
+println "\$conn->get_count($column_family, 'whisky2')";
+println Dumper $conn->get_count($column_family, 'whisky2');
+#Expected result: 1
+
println "\$conn->remove($column_family)";
println Dumper $conn->remove($column_family);
println "\$conn->get_range($column_family)";
println Dumper $conn->get_range($column_family);
-#Expected result: empty list
+#Expected result: empty list
View
54 lib/Cassandra/Simple.pm
@@ -23,7 +23,34 @@ This module attempts to abstract the underlying Thrift methods as much as possib
=head1 SYNOPSYS
- None yet...
+ #Assuming the keyspace 'simple' and the column family 'simple' exist
+
+ my ($keyspace, $column_family) = qw/simple simple/;
+
+ my $conn = Cassandra::Simple->new(keyspace => $keyspace,);
+
+ $conn->insert($column_family, 'KeyA', [ [ 'ColumnA' => 'AA' ], [ 'ColumnB' => 'AB' ] ] );
+
+ $conn->get($column_family, 'KeyA');
+ $conn->get($column_family, 'KeyA', { columns => [ qw/ColumnA/ ] });
+ $conn->get($column_family, 'KeyA', { column_count => 1, column_reversed => 1 });
+
+ $conn->batch_insert($column_family, { 'KeyB' => [ [ 'ColumnA' => 'BA' ] , [ 'ColumnB' => 'BB' ] ], 'KeyC' => [ [ 'ColumnA' => 'CA' ] , [ 'ColumnD' => 'CD' ] ] });
+
+ $conn->multiget($column_family, [qw/KeyA KeyC/]);
+
+ $conn->get_range($column_family, { start=> 'KeyA', finish => 'KeyB', column_count => 1 });
+ $conn->get_range($column_family);
+
+ $conn->get_indexed_slices($column_family, { expression_list => [ [ 'ColumnA' => 'BA' ] ] });
+
+ $conn->remove($column_family, [ 'KeyA' ], { columns => [ 'ColumnA' ]});
+ $conn->remove($column_family, [ 'KeyA' ]);
+ $conn->remove($column_family);
+
+ $conn->get_count($column_family, 'KeyA');
+ $conn->multiget_count($column_family, [ 'KeyB', 'KeyC' ]);
+
=cut
@@ -173,11 +200,11 @@ sub get {
my $result =
$self->client->get_slice( $key, $columnParent, $predicate, $level );
- my @result_columns = map {
- { $_->{column}->{name} => $_->{column}->{value} }
+ my %result_columns = map {
+ $_->{column}->{name} => $_->{column}->{value}
} @{$result};
- return @result_columns;
+ return %result_columns;
}
=head2 multiget
@@ -223,12 +250,12 @@ sub multiget {
my $result =
$self->client->multiget_slice( $keys, $columnParent, $predicate, $level );
- my @result_columns = map {
+ my %result_columns = map {
map { $_->{column}->{name} => $_->{column}->{value} }
@{ $result->{$_} }
} keys %$result;
- return @result_columns;
+ return %result_columns;
}
=head2 get_count
@@ -379,14 +406,13 @@ sub get_range {
$self->client->get_range_slices( $columnParent, $predicate,
$keyRange, $level );
- my @result_columns = map {
- {
- map { $_->{column}->{name} => $_->{column}->{value} }
- @{ $_->{columns} }
- }
+ my %result_columns = map {
+ $_->{key} => {map { $_->{column}->{name} => $_->{column}->{value} }
+ @{ $_->{columns} } }
+
} @{$result};
- return @result_columns;
+ return %result_columns;
}
=head2 get_indexed_slices
@@ -471,8 +497,8 @@ sub get_indexed_slices {
$predicate, $level );
my %result_keys = map {
- $_->{key} => [ map { $_->{column}->{name} => $_->{column}->{value} }
- @{ $_->{columns} } ]
+ $_->{key} => { map { $_->{column}->{name} => $_->{column}->{value} }
+ @{ $_->{columns} } }
} @{$result};
return %result_keys;
Please sign in to comment.
Something went wrong with that request. Please try again.