Permalink
Browse files

Added composite types support (still undocumented). Added composite t…

…ype example in simple test.
  • Loading branch information...
1 parent 2957078 commit 1e72e6faff136d80994b6c0b141301f55fddc874 @fmgoncalves committed Oct 10, 2011
Showing with 968 additions and 476 deletions.
  1. +15 −10 README
  2. +99 −45 examples/cassandra_simple_test.pm
  3. +267 −266 lib/Cassandra/Cassandra.pm
  4. +41 −0 lib/Cassandra/Composite.pm
  5. +14 −4 lib/Cassandra/Pool.pm
  6. +83 −34 lib/Cassandra/Simple.pm
  7. +449 −117 lib/Cassandra/Types.pm
View
25 README
@@ -13,30 +13,30 @@ DESCRIPTION
SYNOPSYS
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');
$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' ]);
@@ -184,6 +184,11 @@ BUGS
<https://github.com/fmgoncalves/p5-cassandra-simple>.
TODO
+ Error Handling
+
+ Exceptions raised when calling Cassandra code should be report in error
+ form with appropriate description.
+
Unit Tests
Sort of done in the examples folder
@@ -4,26 +4,25 @@ use warnings;
use Data::Dumper;
use Cassandra::Simple;
-use Cassandra::Pool;
+use Cassandra::Composite qw/composite/;
use Sys::Hostname qw/hostname/;
sub println {
print @_, "\n";
}
-my ($keyspace, $column_family) = qw/simple simple/;
+my ( $keyspace, $column_family ) = qw/simple simple/;
-my $conn = Cassandra::Simple->new(
- server_name => '127.0.0.1',
- keyspace => $keyspace,
-);
+my $conn = Cassandra::Simple->new( server_name => '127.0.0.1',
+ keyspace => $keyspace, );
-my $present = grep { $_ eq $column_family } @{[ $conn->list_keyspace_cfs($keyspace) ]};
+my $present =
+ grep { $_ eq $column_family } @{ [ $conn->list_keyspace_cfs($keyspace) ] };
-unless ( $present ){
+unless ($present) {
println "Creating $column_family in $keyspace";
- $conn->create_column_family($keyspace, $column_family);
+ $conn->create_column_family( $keyspace, $column_family );
}
#Method to test code here success
@@ -36,81 +35,136 @@ unless ( $present ){
#insert 100% 100%
#batch_insert 100% 100%
#remove 100% 100%
+#composite get 100% 100%
+#composite insert 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/] } );
-println "\$conn->get($column_family, 'ChaveA', { columns => [ qw/ColunaA1/ ] })";
-println Dumper $conn->get($column_family, 'ChaveA', { columns => [ qw/ColunaA1/ ] });
#Expected result: ValorA1
println "\$conn->get($column_family, 'ChaveA')";
-println Dumper $conn->get($column_family, 'ChaveA');
+println Dumper $conn->get( $column_family, 'ChaveA' );
+
#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 });
+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 } );
+
#Expected result: only one column, the last given by get($column_family, 'ChaveA')
-println "\$conn->batch_insert($column_family, { 'ChaveB' => {'ColunaB1' => 'ValorB1' , 'ColunaB2' => 'ValorB2' }, 'ChaveC' => { 'ColunaC1' => 'ValorC1' , 'ColunaC2' => 'ValorC2' } })";
-println Dumper $conn->batch_insert($column_family, { 'ChaveB' => {'ColunaB1' => 'ValorB1' , 'ColunaB2' => 'ValorB2' }, 'ChaveC' => { 'ColunaC1' => 'ValorC1' , 'ColunaC2' => 'ValorC2' } });
+println
+"\$conn->batch_insert($column_family, { 'ChaveB' => {'ColunaB1' => 'ValorB1' , 'ColunaB2' => 'ValorB2' }, 'ChaveC' => { 'ColunaC1' => 'ValorC1' , 'ColunaC2' => 'ValorC2' } })";
+println Dumper $conn->batch_insert(
+ $column_family,
+ {
+ 'ChaveB' => {
+ 'ColunaB1' => 'ValorB1',
+ 'ColunaB2' => 'ValorB2'
+ },
+ 'ChaveC' => {
+ 'ColunaC1' => 'ValorC1',
+ 'ColunaC2' => 'ValorC2'
+ }
+ }
+);
println "\$conn->multiget($column_family, [ qw/ChaveA ChaveC/ ])";
-println Dumper $conn->multiget($column_family, [qw/ChaveA ChaveC/]);
+println Dumper $conn->multiget( $column_family, [qw/ChaveA ChaveC/] );
+
#Expected result: all content from ChaveA and ChaveC
-println "\$conn->get_range($column_family, { start=> 'ChaveA', finish => 'ChaveB', column_count => 1 })";
-println Dumper $conn->get_range($column_family, { start=> 'ChaveA', finish => 'ChaveB', column_count => 1 });
-#Expected result: Depends on key order inside Cassandra. Probably only these 2 keys are returned with 1 column each.
+println
+"\$conn->get_range($column_family, { start=> 'ChaveA', finish => 'ChaveB', column_count => 1 })";
+println Dumper $conn->get_range(
+ $column_family,
+ {
+ start => 'ChaveA',
+ finish => 'ChaveB',
+ column_count => 1
+ }
+);
+#Expected result: Depends on key order inside Cassandra. Probably only these 2 keys are returned with 1 column each.
println "\$conn->create_index($keyspace, $column_family, 'age')";
-println Dumper $conn->create_index($keyspace, $column_family, 'age');
+println Dumper $conn->create_index( $keyspace, $column_family, 'age' );
+
+println
+"\$conn->batch_insert($column_family, { 'whisky1' => { 'age' => 12 }, 'whisky2' => { 'age' => 12 }, 'whisky3' => { 'age' => 15 }, 'whisky4' => { 'age' => 12 } })";
+println Dumper $conn->batch_insert(
+ $column_family,
+ {
+ 'whisky1' => { 'age' => 12 },
+ 'whisky2' => { 'age' => 12 },
+ 'whisky3' => { 'age' => 15 },
+ 'whisky4' => { 'age' => 12 }
+ }
+);
-println "\$conn->batch_insert($column_family, { 'whisky1' => { 'age' => 12 }, 'whisky2' => { 'age' => 12 }, 'whisky3' => { 'age' => 15 }, 'whisky4' => { 'age' => 12 } })";
-println Dumper $conn->batch_insert($column_family, { 'whisky1' => { 'age' => 12 }, 'whisky2' => { 'age' => 12 }, 'whisky3' => { 'age' => 15 }, 'whisky4' => { 'age' => 12 } });
+println
+"\$conn->get_indexed_slices($column_family, { expression_list => [ [ 'age' => '12' ] ] })";
+println Dumper $conn->get_indexed_slices( $column_family,
+ { expression_list => [ [ 'age' => '12' ] ] } );
-println "\$conn->get_indexed_slices($column_family, { expression_list => [ [ 'age' => '12' ] ] })";
-println Dumper $conn->get_indexed_slices($column_family, { expression_list => [ [ 'age' => '12' ] ] });
-#Expected result: Rows whisky1, whisky2, whisky4
+#Expected result: Rows whisky1, whisky2, whisky4
-println "\$conn->remove($column_family, [ 'ChaveA' ], { columns => [ 'ColunaA1' ]})";
-println Dumper $conn->remove($column_family, [ 'ChaveA' ], { columns => [ 'ColunaA1' ]});
+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->get_count($column_family, 'whisky2');
+println Dumper $conn->multiget_count( $column_family, [ 'ChaveA', 'ChaveB' ] );
+
#Expected result: ChaveA -> 1, ChaveB -> 2
println "\$conn->get_count($column_family, 'whisky2')";
-println Dumper $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 Dumper $conn->remove( $column_family, 'whisky2' );
println "\$conn->get($column_family, 'whisky2')";
-println Dumper $conn->get($column_family, 'whisky2');
+println Dumper $conn->get( $column_family, 'whisky2' );
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
println "\$conn->ring('simple')";
println Dumper $conn->ring('simple');
-println "new Cassandra::Pool($keyspace)";
-my $pool = new Cassandra::Pool($keyspace);
-
-println "\$pool->get()";
-my $client = $pool->get();
+$column_family = "TCF";
+println
+"\$conn->insert( 'TCF', 'hello', { composite( 'a','en') => 'world' , composite('a','pt') => 'mundo' } )";
+println Dumper $conn->insert(
+ $column_family, "hello",
+ {
+ composite( "a", "en" ) => "world",
+ composite( "a", "pt" ) => "mundo"
+ }
+);
-println "\$client->describe_snitch()";
-println $client->describe_snitch();
-println "\$client";
-println Dumper $client;
+println
+ "\$conn->get( 'TCF', 'hello', { columns => [ composite('a', 'pt' ) ] } )";
+println Dumper $conn->get( $column_family, "hello",
+ { columns => [ composite( "a", "pt" ) ] } );
-println "\$pool->put(\$client)";
-$pool->put($client);
+println Dumper "\$conn->remove($column_family)";
+println Dumper $conn->remove($column_family);
Oops, something went wrong.

0 comments on commit 1e72e6f

Please sign in to comment.