From 5f2c7b6059b597cfb1b974f0dd424225cbcf6556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20Gon=C3=A7alves?= Date: Mon, 18 Jul 2011 15:45:49 +0100 Subject: [PATCH] Changed insert and batch insert $columns argument type --- README | 6 +++--- examples/cassandra_simple_test.pm | 6 +++--- examples/super_column_support.pm | 1 - lib/Cassandra/Simple.pm | 16 ++++++++-------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/README b/README index 1d6c251..dd703f0 100644 --- a/README +++ b/README @@ -12,12 +12,12 @@ DESCRIPTION using Cassandra. SYNOPSYS - #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->create_column_family( $keyspace, $column_family); + $conn->insert($column_family, 'KeyA', [ [ 'ColumnA' => 'AA' ], [ 'ColumnB' => 'AB' ] ] ); $conn->get($column_family, 'KeyA'); @@ -118,7 +118,7 @@ SYNOPSYS timestamp, ttl, consistency_level_write insert_super - Usage: "insert($column_family, $key, $columns[, opt])" + Usage: "insert_super($column_family, $key, $columns[, opt])" The $columns is an *HASH* of the form "{ super_column => { column => value, column => value } }" diff --git a/examples/cassandra_simple_test.pm b/examples/cassandra_simple_test.pm index 132dabd..32aad1e 100644 --- a/examples/cassandra_simple_test.pm +++ b/examples/cassandra_simple_test.pm @@ -40,8 +40,8 @@ my $conn = Cassandra::Simple->new( #batch_insert 100% 100% #remove 100% 100% -println "\$conn->insert($column_family, 'ChaveA', [ [ 'ColunaA1' => 'ValorA1' ], [ 'ColunaA2' => 'ValorA2' ] ] )"; -$conn->insert($column_family, 'ChaveA', [ [ 'ColunaA1' => 'ValorA1' ], [ 'ColunaA2' => 'ValorA2' ] ] ); +println "\$conn->insert($column_family, 'ChaveA', { 'ColunaA1' => 'ValorA1' , 'ColunaA2' => 'ValorA2' } )"; +$conn->insert($column_family, 'ChaveA', { 'ColunaA1' => 'ValorA1' , 'ColunaA2' => 'ValorA2' } ); println "\$conn->get($column_family, 'ChaveA', { columns => [ qw/ColunaA1/ ] })"; println Dumper $conn->get($column_family, 'ChaveA', { columns => [ qw/ColunaA1/ ] }); @@ -49,7 +49,7 @@ println Dumper $conn->get($column_family, 'ChaveA', { columns => [ qw/ColunaA1/ println "\$conn->get($column_family, 'ChaveA')"; println Dumper $conn->get($column_family, 'ChaveA'); -#Expected result: [ [ 'ColunaA1' => 'ValorA1' ], [ 'ColunaA2' => 'ValorA2' ] ] +#Expected result: { 'ColunaA1' => 'ValorA1', 'ColunaA2' => 'ValorA2' } println "\$conn->get($column_family, 'ChaveA', { column_count => 1, column_reversed => 1 })"; println Dumper $conn->get($column_family, 'ChaveA', { column_count => 1, column_reversed => 1 }); diff --git a/examples/super_column_support.pm b/examples/super_column_support.pm index 75ff2f8..65392a5 100644 --- a/examples/super_column_support.pm +++ b/examples/super_column_support.pm @@ -61,7 +61,6 @@ println "\$conn->get_count($column_family, 'KeyA')"; println Dumper $conn->get_count($column_family, 'KeyA'); #Expected result: 3 - ##NOT IMPLEMENTED IN CASSANDRA YET #println "\$conn->remove($column_family, ['KeyA'], {super_column => 'SuperColumnC'})"; #println Dumper $conn->remove($column_family, ['KeyA'], {super_column => 'SuperColumnC'}); diff --git a/lib/Cassandra/Simple.pm b/lib/Cassandra/Simple.pm index 61f3fd0..2e77406 100644 --- a/lib/Cassandra/Simple.pm +++ b/lib/Cassandra/Simple.pm @@ -21,12 +21,12 @@ This module attempts to abstract the underlying Thrift methods as much as possib =head1 SYNOPSYS - #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->create_column_family( $keyspace, $column_family); + $conn->insert($column_family, 'KeyA', [ [ 'ColumnA' => 'AA' ], [ 'ColumnB' => 'AB' ] ] ); $conn->get($column_family, 'KeyA'); @@ -541,7 +541,7 @@ sub get_indexed_slices { Usage: C<< insert($column_family, $key, $columns[, opt]) >> -The C<$columns> is an I of the form C<< [ [ column => value ] ] >> +The C<$columns> is an I of the form C<< { column => value, column => value } >> C<$opt> is an I and can have the following keys: @@ -574,8 +574,8 @@ sub insert { column => new Cassandra::Column( { - name => $_->[0], - value => $_->[1], + name => $_, + value => $columns->{$_}, timestamp => $opt->{timestamp} // time, ttl => $opt->{ttl} // undef, } @@ -584,7 +584,7 @@ sub insert { ) } ) - } @{$columns}; + } keys % $columns; $self->client->batch_mutate( { $key => { $column_family => \@mutations } }, $level ); @@ -592,7 +592,7 @@ sub insert { =head2 insert_super -Usage: C<< insert($column_family, $key, $columns[, opt]) >> +Usage: C<< insert_super($column_family, $key, $columns[, opt]) >> The C<$columns> is an I of the form C<< { super_column => { column => value, column => value } } >> @@ -657,7 +657,7 @@ sub insert_super { Usage: C -C<$rows> is an I of the form C<< { key => [ [ column => value ] , [ column => value ] ], key => [ [ column => value ] , [ column => value ] ] } >> +C<$rows> is an I of the form C<< { key => { column => value , column => value }, key => { column => value , column => value } } >> C<$opt> is an I and can have the following keys: