0
卡桑德拉1.0.6
節儉0.8卡桑德拉:通過Perl的
我已經寫了〜120K值代入我的卡桑德拉節點使用Perl得到。有問題的ColumnFamily「活動」對「ValTypeA」和「ValTypeB」有兩個索引。如果我通過cassandra-cli訪問數據庫,我可以輸入命令,如「獲取ValTypeA = 10的活動」;並獲得一些數據。
問題是 - >如何將這個動作轉換成Perl?
卡桑德拉1.0.6
節儉0.8卡桑德拉:通過Perl的
我已經寫了〜120K值代入我的卡桑德拉節點使用Perl得到。有問題的ColumnFamily「活動」對「ValTypeA」和「ValTypeB」有兩個索引。如果我通過cassandra-cli訪問數據庫,我可以輸入命令,如「獲取ValTypeA = 10的活動」;並獲得一些數據。
問題是 - >如何將這個動作轉換成Perl?
FWIW:答案是'索引切片'。在Perl中如下:
#!/usr/bin/perl -w
use strict;
use warnings;
# Change for your environment
use lib '/vol2/users/progs/perl/cassandra_lib';
use lib '/usr/local/src/thrift-0.8.0/lib/perl/lib';
use Cassandra::Cassandra;
use Cassandra::Constants;
use Cassandra::Types;
use Thrift;
use Thrift::BinaryProtocol;
use Thrift::Socket;
use Thrift::FramedTransport;
use Data::Dumper;
# localhost and 9160 are default in storage conf for rpc listener
my $socket = new Thrift::Socket('10.127.56.42', 9160);
my $transport = new Thrift::FramedTransport($socket, 1024, 1024);
my $protocol = new Thrift::BinaryProtocol($transport);
my $client = new Cassandra::CassandraClient($protocol);
eval {
$transport->open();
my $keyspace = 'some_data';
# ColumnParent tells the API the ColumnFamily or SuperColumn we're working on
my $column_parent = new Cassandra::ColumnParent({ column_family => "activity" });
my $consistency_level = Cassandra::ConsistencyLevel::ONE;
$client->set_keyspace($keyspace);
my $slice_range = new Cassandra::SliceRange();
$slice_range->{start} = "";
$slice_range->{finish} = "";
my $slice_predicate = new Cassandra::SlicePredicate();
$slice_predicate->{slice_range} = $slice_range;
my $index_expression0 = new Cassandra::IndexExpression();
$index_expression0->{ column_name } = 'ValTypeA';
$index_expression0->{ op } = Cassandra::IndexOperator::EQ;
$index_expression0->{ value } = 13;
my $index_expression1 = new Cassandra::IndexExpression();
$index_expression1->{ column_name } = 'ValTypeB';
$index_expression1->{ op } = Cassandra::IndexOperator::EQ;
$index_expression1->{ value } = '2011-12-26 15:43:34';
my $index_clause = new Cassandra::IndexClause();
$index_clause->{ expressions } = [ $index_expression0, $index_expression1 ];
$index_clause->{ start_key } = '';
my $result = $client->get_indexed_slices($column_parent, $index_clause, $slice_predicate, $consistency_level);
print Dumper($result);
};
if([email protected])
{
print Dumper([email protected]);
}
這可能是值得檢查一下這個Perl lib:http://fmgoncalves.github.com/p5-cassandra-simple/。這樣,你不必自己寫所有的Thrift資料。獎勵積分,如果你幫助改善圖書館;) – 2012-01-01 23:44:54
尼斯鏈接。我期望我的大部分困惑都只是試圖將我的老派DB思想應用到這個新模型中。 「範圍切片」vs「列切片」和「索引切片」等等。 – ethrbunny 2012-01-02 00:17:56