-
Notifications
You must be signed in to change notification settings - Fork 2
/
simple.pl
executable file
·292 lines (276 loc) · 9.98 KB
/
simple.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/home/acme/perl-5.10.0/bin//perl
use strict;
use warnings;
use lib 'lib';
use Net::Cassandra;
use Perl6::Say;
my $cassandra = Net::Cassandra->new( hostname => 'localhost' );
my $client = $cassandra->client;
my $key1 = '123';
my $key2 = '456';
my $timestamp = time;
# void insert(1:required string keyspace,
# 2:required string key,
# 3:required ColumnPath column_path,
# 4:required binary value,
# 5:required i64 timestamp,
# 6:required ConsistencyLevel consistency_level=0)
# throws (1: InvalidRequestException ire, 2: UnavailableException ue),
eval {
$client->insert(
'Keyspace1',
$key1,
Net::Cassandra::Backend::ColumnPath->new(
{ column_family => 'Standard1', column => 'name' }
),
'Leon Brocard',
$timestamp,
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 $@;
# void batch_insert(1:required string keyspace,
# 2:required string key,
# 3:required map<string, list<ColumnOrSuperColumn>> cfmap,
# 4:required ConsistencyLevel consistency_level=0)
# throws (1: InvalidRequestException ire, 2: UnavailableException ue),
eval {
$client->batch_insert(
'Keyspace1',
$key2,
{ 'Standard1' => [
Net::Cassandra::Backend::ColumnOrSuperColumn->new(
{ column => Net::Cassandra::Backend::Column->new(
{ name => 'name',
value => 'Leon Brocard',
timestamp => $timestamp,
}
)
}
)
],
},
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 $@;
# ColumnOrSuperColumn get(1:required string keyspace,
# 2:required string key,
# 3:required ColumnPath column_path,
# 4:required ConsistencyLevel consistency_level=1)
# throws (1: InvalidRequestException ire, 2: NotFoundException nfe, 3: UnavailableException ue),
eval {
my $what = $client->get(
'Keyspace1',
$key1,
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 "$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 $@;
# list<ColumnOrSuperColumn> get_slice(1:required string keyspace,
# 2:required string key,
# 3:required ColumnParent column_parent,
# 4:required SlicePredicate predicate,
# 5:required ConsistencyLevel consistency_level=1)
# throws (1: InvalidRequestException ire, 3: UnavailableException ue),
eval {
my $what = $client->get_slice(
'Keyspace1',
$key1,
Net::Cassandra::Backend::ColumnParent->new(
{ column_family => 'Standard1' }
),
Net::Cassandra::Backend::SlicePredicate->new(
{ slice_range => Net::Cassandra::Backend::SliceRange->new(
{ start => '', finish => '', count => 100 }
)
}
),
Net::Cassandra::Backend::ConsistencyLevel::QUORUM
);
my $value = $what->[0]->column->value;
my $timestamp = $what->[0]->column->timestamp;
warn "$key1 / $value / $timestamp";
};
die $@->why if $@;
# map<string,ColumnOrSuperColumn> multiget(1:required string keyspace,
# 2:required list<string> keys,
# 3:required ColumnPath column_path,
# 4:required ConsistencyLevel consistency_level=1)
# throws (1: InvalidRequestException ire, 2: UnavailableException ue),
eval {
my $what = $client->multiget(
'Keyspace1',
[$key1],
Net::Cassandra::Backend::ColumnPath->new(
{ column_family => 'Standard1', column => 'name' }
),
Net::Cassandra::Backend::ConsistencyLevel::QUORUM
);
my $value = $what->{$key1}->column->value;
my $timestamp = $what->{$key1}->column->timestamp;
warn "$key1 / $value / $timestamp";
};
die $@->why if $@;
# map<string,list<ColumnOrSuperColumn>> multiget_slice(1:required string keyspace,
# 2:required list<string> keys,
# 3:required ColumnParent column_parent,
# 4:required SlicePredicate predicate,
# 5:required ConsistencyLevel consistency_level=1)
# throws (1: InvalidRequestException ire, 2: UnavailableException ue),
eval {
my $what = $client->multiget_slice(
'Keyspace1',
[$key1],
Net::Cassandra::Backend::ColumnParent->new(
{ column_family => 'Standard1' }
),
Net::Cassandra::Backend::SlicePredicate->new(
{ column_names => ['name'], }
),
Net::Cassandra::Backend::ConsistencyLevel::QUORUM
);
my $value = $what->{$key1}->[0]->column->value;
my $timestamp = $what->{$key1}->[0]->column->timestamp;
warn "$key1 / $value / $timestamp";
};
die $@->why if $@;
# i32 get_count(1:required string keyspace,
# 2:required string key,
# 3:required ColumnParent column_parent,
# 4:required ConsistencyLevel consistency_level=1)
# throws (1: InvalidRequestException ire, 2: UnavailableException ue),
eval {
my $what = $client->get_count(
'Keyspace1',
$key1,
Net::Cassandra::Backend::ColumnParent->new(
{ column_family => 'Standard1' }
),
Net::Cassandra::Backend::ConsistencyLevel::QUORUM
);
warn "$key1 / $what columns";
};
die $@->why if $@;
# list<string> get_key_range(1:required string keyspace,
# 2:required string column_family,
# 3:required string start="",
# 4:required string finish="",
# 5:required i32 count=100,
# 6:required ConsistencyLevel consistency_level=1)
# throws (1: InvalidRequestException ire, 2: UnavailableException ue),
eval {
my $what
= $client->get_key_range( 'Keyspace1', 'Standard1', '', '', 100,
Net::Cassandra::Backend::ConsistencyLevel::QUORUM );
warn "Keys: ", join( ', ', @$what );
};
warn $@->why if $@;
# void remove(1:required string keyspace,
# 2:required string key,
# 3:required ColumnPath column_path,
# 4:required i64 timestamp,
# 5:ConsistencyLevel consistency_level=0)
# throws (1: InvalidRequestException ire, 2: UnavailableException ue),
eval {
$client->remove(
'Keyspace1',
$key1,
Net::Cassandra::Backend::ColumnPath->new(
{ column_family => 'Standard1', column => 'name' }
),
$timestamp
);
};
die $@->why if $@;