Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add supercolumn examples

  • Loading branch information...
commit 71bdb9602aa68e48a3632e32e03f4551b7c5566c 1 parent f3d4689
Léon Brocard authored
Showing with 113 additions and 27 deletions.
  1. +113 −27 examples/simple.pl
140 examples/simple.pl
View
@@ -8,7 +8,8 @@
my $cassandra = Net::Cassandra->new( hostname => 'localhost' );
my $client = $cassandra->client;
-my $key = '123';
+my $key1 = '123';
+my $key2 = '456';
my $timestamp = time;
# void insert(1:required string keyspace,
@@ -21,13 +22,30 @@
eval {
$client->insert(
'Keyspace1',
- $key,
+ $key1,
Net::Cassandra::Backend::ColumnPath->new(
{ column_family => 'Standard1', column => 'name' }
),
'Leon Brocard',
$timestamp,
- Net::Cassandra::Backend::ConsistencyLevel::ZERO
+ Net::Cassandra::Backend::ConsistencyLevel::QUORUM
+ );
+};
+die $@->why if $@;
+
+eval {
+ $client->insert(
+ 'Keyspace1',
+ $key1,
+ Net::Cassandra::Backend::ColumnPath->new(
+ { column_family => 'Super1',
+ super_column => 'Fred',
+ column => 'name'
+ }
+ ),
+ 'Leon Brocard',
+ $timestamp,
+ Net::Cassandra::Backend::ConsistencyLevel::QUORUM
);
};
die $@->why if $@;
@@ -40,7 +58,7 @@
eval {
$client->batch_insert(
'Keyspace1',
- $key,
+ $key2,
{ 'Standard1' => [
Net::Cassandra::Backend::ColumnOrSuperColumn->new(
{ column => Net::Cassandra::Backend::Column->new(
@@ -53,7 +71,35 @@
)
],
},
- Net::Cassandra::Backend::ConsistencyLevel::ZERO
+ Net::Cassandra::Backend::ConsistencyLevel::QUORUM
+ );
+};
+die $@->why if $@;
+
+eval {
+ $client->batch_insert(
+ 'Keyspace1',
+ $key2,
+ { 'Super1' => [
+ Net::Cassandra::Backend::ColumnOrSuperColumn->new(
+ { super_column =>
+ Net::Cassandra::Backend::SuperColumn->new(
+ { name => 'Fred',
+ columns => [
+ Net::Cassandra::Backend::Column->new(
+ { name => 'name',
+ value => 'Leon Brocard',
+ timestamp => $timestamp,
+ }
+ )
+ ]
+ }
+ )
+ }
+ )
+ ],
+ },
+ Net::Cassandra::Backend::ConsistencyLevel::QUORUM
);
};
die $@->why if $@;
@@ -66,7 +112,7 @@
eval {
my $what = $client->get(
'Keyspace1',
- $key,
+ $key1,
Net::Cassandra::Backend::ColumnPath->new(
{ column_family => 'Standard1', column => 'name' }
),
@@ -74,7 +120,52 @@
);
my $value = $what->column->value;
my $timestamp = $what->column->timestamp;
- warn "$value / $timestamp";
+ warn "$key1 / $value / $timestamp";
+};
+die $@->why if $@;
+
+eval {
+ my $what = $client->get(
+ 'Keyspace1',
+ $key2,
+ Net::Cassandra::Backend::ColumnPath->new(
+ { column_family => 'Standard1', column => 'name' }
+ ),
+ Net::Cassandra::Backend::ConsistencyLevel::QUORUM
+ );
+ my $value = $what->column->value;
+ my $timestamp = $what->column->timestamp;
+ warn "$key2 / $value / $timestamp";
+};
+die $@->why if $@;
+
+eval {
+ my $what = $client->get(
+ 'Keyspace1',
+ $key1,
+ Net::Cassandra::Backend::ColumnPath->new(
+ { column_family => 'Super1', super_column => 'Fred', column => 'name' }
+ ),
+ Net::Cassandra::Backend::ConsistencyLevel::QUORUM
+ );
+ my $value = $what->column->value;
+ my $timestamp = $what->column->timestamp;
+ warn "$key1 / $value / $timestamp";
+};
+die $@->why if $@;
+
+eval {
+ my $what = $client->get(
+ 'Keyspace1',
+ $key2,
+ Net::Cassandra::Backend::ColumnPath->new(
+ { column_family => 'Super1', super_column => 'Fred', column => 'name' }
+ ),
+ Net::Cassandra::Backend::ConsistencyLevel::QUORUM
+ );
+ my $value = $what->column->value;
+ my $timestamp = $what->column->timestamp;
+ warn "$key2 / $value / $timestamp";
};
die $@->why if $@;
@@ -87,13 +178,12 @@
eval {
my $what = $client->get_slice(
'Keyspace1',
- $key,
+ $key1,
Net::Cassandra::Backend::ColumnParent->new(
{ column_family => 'Standard1' }
),
Net::Cassandra::Backend::SlicePredicate->new(
- { column_names => ['name'],
- slice_range => Net::Cassandra::Backend::SliceRange->new(
+ { slice_range => Net::Cassandra::Backend::SliceRange->new(
{ start => '', finish => '', count => 100 }
)
}
@@ -102,7 +192,7 @@
);
my $value = $what->[0]->column->value;
my $timestamp = $what->[0]->column->timestamp;
- warn "$value / $timestamp";
+ warn "$key1 / $value / $timestamp";
};
die $@->why if $@;
@@ -114,15 +204,15 @@
eval {
my $what = $client->multiget(
'Keyspace1',
- [$key],
+ [$key1],
Net::Cassandra::Backend::ColumnPath->new(
{ column_family => 'Standard1', column => 'name' }
),
Net::Cassandra::Backend::ConsistencyLevel::QUORUM
);
- my $value = $what->{$key}->column->value;
- my $timestamp = $what->{$key}->column->timestamp;
- warn "$value / $timestamp";
+ my $value = $what->{$key1}->column->value;
+ my $timestamp = $what->{$key1}->column->timestamp;
+ warn "$key1 / $value / $timestamp";
};
die $@->why if $@;
@@ -135,22 +225,18 @@
eval {
my $what = $client->multiget_slice(
'Keyspace1',
- [$key],
+ [$key1],
Net::Cassandra::Backend::ColumnParent->new(
{ column_family => 'Standard1' }
),
Net::Cassandra::Backend::SlicePredicate->new(
- { column_names => ['name'],
- slice_range => Net::Cassandra::Backend::SliceRange->new(
- { start => '', finish => '', count => 100 }
- )
- }
+ { column_names => ['name'], }
),
Net::Cassandra::Backend::ConsistencyLevel::QUORUM
);
- my $value = $what->{$key}->[0]->column->value;
- my $timestamp = $what->{$key}->[0]->column->timestamp;
- warn "$value / $timestamp";
+ my $value = $what->{$key1}->[0]->column->value;
+ my $timestamp = $what->{$key1}->[0]->column->timestamp;
+ warn "$key1 / $value / $timestamp";
};
die $@->why if $@;
@@ -162,13 +248,13 @@
eval {
my $what = $client->get_count(
'Keyspace1',
- $key,
+ $key1,
Net::Cassandra::Backend::ColumnParent->new(
{ column_family => 'Standard1' }
),
Net::Cassandra::Backend::ConsistencyLevel::QUORUM
);
- warn "$what columns";
+ warn "$key1 / $what columns";
};
die $@->why if $@;
@@ -196,7 +282,7 @@
eval {
$client->remove(
'Keyspace1',
- $key,
+ $key1,
Net::Cassandra::Backend::ColumnPath->new(
{ column_family => 'Standard1', column => 'name' }
),
Please sign in to comment.
Something went wrong with that request. Please try again.