/
keyspace.lisp
694 lines (546 loc) · 35.8 KB
/
keyspace.lisp
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
;;; -*- Mode: lisp; Syntax: ansi-common-lisp; Base: 10; Package: de.setf.cassandra; -*-
(in-package :de.setf.cassandra)
;;; This file defines keyspace operators for the 'de.setf.cassandra' library component.
;;; (c) 2010 james anderson
;;;
;;; 'de.setf.cassandra' is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU Lesser General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;;
;;; 'de.setf.cassandra' is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU Lesser General Public License for more details.
;;;
;;; You should have received a copy of the GNU Lesser General Public License along
;;; with 'de.setf.cassandra' as 'lgpl.txt'. If not, see the GNU [site](http://www.gnu.org/licenses/).
(defclass keyspace (thrift:binary-protocol)
((name
:initarg :name :initform (error "name is required.")
:accessor keyspace-name
:documentation "Specifies the keyspace in the store.")
(slice-size
:initarg :slice-size :initform 100
:accessor keyspace-slice-size
:type i32
:documentation "The default slice size to use for retrieval operations which return a list of values.")
(consistency-level
:initarg :consitency-level :initform cassandra_2.1.0:consistency-level.one
:type (enum cassandra_2.1.0:consistency-level)
:accessor keyspace-consistency-level
:documentation "The default cassandra consistency level to use for store operations.
The default value is cassandra_2.1.0:consistency-level.one.")
(description
:initform nil :initarg :description
:type list
:reader get-keyspace-description :writer setf-keyspace-description
:documentation "Caches a list of descriptions of keyspaces present in the store.")
(keyspaces
:initform nil :initarg :keyspaces
:type list
:reader get-keyspace-keyspaces :writer setf-keyspace-keyspaces
:documentation "Caches a list of keyspaces present in the store.")
(clock
:initform (cassandra_8.3.0:make-clock :timestamp (uuid::get-timestamp))
:allocation :class
:reader get-keyspace-clock
:documentation "Stub support for whatever vector clocks turn into. Usage is round-about for
0.6, as that uses just the timestamp, but permits a consistent API.")
(version
:initform nil :initarg :version
:reader keyspace-version)
(version-class-map
:initform '(("2.1.0" . cassandra_2.1.0:keyspace)
("8.3.0" . cassandra_8.3.0:keyspace))
:allocation :class
:reader keyspace-version-class-map
:documentation "Maps the _protocol_ version to the class which supports it. This implies the server version as
as 2.* is .6 and 8.* is .7, but the server does not report it actual version."))
(:documentation "A keyspace represents thrift protocol connection to a cassandra instance for access to
a particular keyspace. It provides cached state and defaults for
* name : a string designating a keyspace
* consistency-level : the default level for operations
* siice-size : the default slice size for retrieveal operations
Acts as the top-level interface to the cassandra API. It implements operators which
accept arguments as keywords, provides defaults for the keyspace, c(:mutation .nsistency level, and
timestamps, and delegates to the thrift-based positional request operators.
In addition to the standard interface, it provides composite operators:
insert-data
The class abstract keyspace class is specialized as per the thruft api versions for access to the respective
service versions:
* cassandra_2.1.0:keyspace : 0.6
* cassandra_8.3.0:keyspace : 0.7"))
(defun compute-versioned-constructor (type package)
(or (find-symbol (concatenate 'string (string :make-) (string type)) package)
(error "invalid struct-name: ~s." type)))
(defclass cassandra_2.1.0:keyspace (keyspace)
((version :initform "0.6.4" :allocation :class))
(:documentation "The keyspace protocol class for cassandra 0.6.4 w/api 2.1.0"))
(defclass cassandra_8.3.0:keyspace (keyspace)
((version :initform "0.7.0" :allocation :class))
(:documentation "The keyspace protocol class for cassandra 0.7.0 w/api 8.3.0"))
(defgeneric keyspace (location &key protocol direction element-type &allow-other-keys)
(:documentation "Open a client connection to a cassandra thrift service and instantiate a keyspace
and bind it to a named keyspace in the store.")
(:method ((location t) &rest args &key (protocol 'keyspace) &allow-other-keys)
(declare (dynamic-extent args))
(apply #'thrift:client location :protocol protocol args)))
(defmethod initialize-instance :after ((instance keyspace) &rest initargs)
(let ((concrete-class (compute-keyspace-class instance)))
(cond ((typep instance concrete-class))
((subtypep concrete-class (type-of instance))
(change-class instance concrete-class))
(t
(error "Service requires an incompatible implementation: ~s, ~s."
concrete-class (type-of instance)))))
;; once the effective class is set
(apply #'keyspace-bind-columns instance initargs))
(defmethod initialize-instance :after ((instance cassandra_8.3.0:keyspace) &key)
(cassandra_8.3.0:set-keyspace instance (keyspace-name instance)))
(defgeneric keyspace-clock (keyspace &optional timestamp)
(:documentation "Return the keyspace clock with an updated timestamp.")
(:method ((keyspace keyspace) &optional timestamp)
(let ((clock (get-keyspace-clock keyspace)))
(setf (cassandra_8.3.0:clock-timestamp clock) (or timestamp (uuid::get-timestamp)))
clock)))
(defgeneric compute-keyspace-class (keyspace)
(:method ((keyspace keyspace))
"The base method is based on version only."
(let* ((service-version (describe-version keyspace))
(new-class (rest (assoc service-version (keyspace-version-class-map keyspace) :test #'equal))))
(unless new-class
(error "Service version not supported: ~s. Expected one of: ~s."
service-version (mapcar #'first (keyspace-version-class-map keyspace))))
new-class)))
(defgeneric keyspace-bind-columns (keyspace &key &allow-other-keys)
(:method ((keyspace keyspace) &key &allow-other-keys) ))
;;;
;;; utility-operators
;;; these are invoked latest in the :after initialize instance to obtain information for
;;; adjusting the class to match the keyspaces present in the store.
(defgeneric keyspace-description (keyspace)
(:method ((keyspace keyspace))
(or (get-keyspace-description keyspace)
(setf-keyspace-description (describe-keyspace keyspace) keyspace))))
(defgeneric keyspace-keyspaces (keyspace)
(:method ((keyspace keyspace))
(or (get-keyspace-keyspaces keyspace)
(setf-keyspace-keyspaces (describe-keyspaces keyspace) keyspace))))
(defgeneric set-keyspace-column-family (keyspace column-family slot-name &key class required)
(:method ((keyspace keyspace) (cf-name string) slot-name &key (class 'standard-column-family) required)
(let ((cf-description (rest (assoc cf-name (keyspace-description keyspace) :test #'string-equal))))
(if cf-description
(if (string-equal (rest (assoc "Type" cf-description :test #'string-equal))
(ecase class
(standard-column-family "Standard")
(super-column-family "Super")))
(setf (slot-value keyspace slot-name) (make-instance class :name cf-name :keyspace keyspace))
(error "Column family class does not match: ~s; ~s; ~s."
cf-name class (rest (assoc "Type" cf-description :test #'string-equal))))
(when required
(error "The column family is required: ~s." cf-name)))))
(:method ((keyspace keyspace) (cf null) slot-name &key class (required t))
(declare (ignore class))
(when required
(error "The column family is required: ~s." slot-name))))
;;;
;;; interface operators
;;; get
(defmethod get ((keyspace cassandra_2.1.0:keyspace) &key
column-family key super-column column
(consistency-level (keyspace-consistency-level keyspace)))
(let ((column-path (cassandra_2.1.0:make-columnpath :column-family column-family
:column column)))
(when super-column
(setf (cassandra_2.1.0:columnpath-super-column column-path) super-column))
(cassandra_2.1.0:get keyspace (keyspace-name keyspace) key column-path consistency-level)))
(defmethod get ((keyspace cassandra_8.3.0:keyspace) &key
column-family key super-column column
(consistency-level (keyspace-consistency-level keyspace)))
(let ((column-path (cassandra_8.3.0:make-columnpath :column-family column-family
:column column)))
(when super-column
(setf (cassandra_8.3.0:columnpath-super-column column-path) super-column))
(cassandra_8.3.0:get keyspace key column-path consistency-level)))
;;; get_slice
(defmethod get-slice ((keyspace cassandra_2.1.0:keyspace) &key
key column-family super-column (start "") (finish "") (column-names nil cn-s) reversed count
(consistency-level (keyspace-consistency-level keyspace)))
(let ((column-parent (cassandra_2.1.0:make-columnparent :column-family column-family))
(slice-predicate (cassandra_2.1.0:make-slicepredicate))
(slice-range nil))
(when super-column
(setf (cassandra_2.1.0:columnparent-super-column column-parent) super-column))
(if cn-s
(setf (cassandra_2.1.0:slicepredicate-column-names slice-predicate) (mapcar #'string column-names))
(setf slice-range (cassandra_2.1.0:make-slicerange :reversed reversed :count count :start start :finish finish)
(cassandra_2.1.0:slicepredicate-slice-range slice-predicate) slice-range))
(cassandra_2.1.0:get-slice keyspace (keyspace-name keyspace) key column-parent slice-predicate consistency-level)))
(defmethod map-slice (op (keyspace cassandra_2.1.0:keyspace) &key
key column-family super-column (start "") (finish "") (column-names nil cn-s) reversed count
(consistency-level (keyspace-consistency-level keyspace)))
(let ((column-parent (cassandra_2.1.0:make-columnparent :column-family column-family))
(slice-predicate (cassandra_2.1.0:make-slicepredicate))
(slice-range nil))
(when super-column
(setf (cassandra_2.1.0:columnparent-super-column column-parent) super-column))
(cond (cn-s
(setf (cassandra_2.1.0:slicepredicate-column-names slice-predicate) (mapcar #'string column-names))
(map nil op
(cassandra_2.1.0:get-slice keyspace (keyspace-name keyspace) key column-parent slice-predicate consistency-level)))
(t
(setf slice-range (cassandra_2.1.0:make-slicerange :reversed reversed :count count :start start :finish finish))
(setf (cassandra_2.1.0:slicepredicate-slice-range slice-predicate) slice-range)
(let ((last-column nil))
(loop (let ((slice (cassandra_2.1.0:get-slice keyspace (keyspace-name keyspace) key column-parent slice-predicate consistency-level)))
(when last-column (pop slice))
(unless slice (return))
(loop (unless slice (return))
(when (minusp (decf count)) (return))
(setf last-column (cassandra_2.1.0:columnorsupercolumn-column (pop slice)))
(funcall op last-column))
(setf (cassandra_2.1.0:slicerange-start slice-range)
(cassandra_2.1.0:column-name last-column)))))))))
(defmethod get-slice ((keyspace cassandra_8.3.0:keyspace) &key
key column-family super-column (start "") (finish "") (column-names nil cn-s) reversed count
(consistency-level (keyspace-consistency-level keyspace)))
(let ((column-parent (cassandra_8.3.0:make-columnparent :column-family column-family))
(slice-predicate (cassandra_8.3.0:make-slicepredicate))
(slice-range nil))
(when super-column
(setf (cassandra_8.3.0:columnparent-super-column column-parent) super-column))
(if cn-s
(setf (cassandra_8.3.0:slicepredicate-column-names slice-predicate) (mapcar #'string column-names))
(setf slice-range (cassandra_8.3.0:make-slicerange :reversed reversed :count count :start start :finish finish)
(cassandra_8.3.0:slicepredicate-slice-range slice-predicate) slice-range))
(cassandra_8.3.0:get-slice keyspace key column-parent slice-predicate consistency-level)))
(defmethod map-slice (op (keyspace cassandra_8.3.0:keyspace) &key
key column-family super-column (start "") (finish "") (column-names nil cn-s) reversed count
(consistency-level (keyspace-consistency-level keyspace)))
(let ((column-parent (cassandra_8.3.0:make-columnparent :column-family column-family))
(slice-predicate (cassandra_8.3.0:make-slicepredicate))
(slice-range nil))
(when super-column
(setf (cassandra_8.3.0:columnparent-super-column column-parent) super-column))
(cond (cn-s
(setf (cassandra_8.3.0:slicepredicate-column-names slice-predicate) (mapcar #'string column-names))
(map nil op
(cassandra_8.3.0:get-slice keyspace key column-parent slice-predicate consistency-level)))
(t
(setf slice-range (cassandra_8.3.0:make-slicerange :reversed reversed :count count :start start :finish finish))
(setf (cassandra_8.3.0:slicepredicate-slice-range slice-predicate) slice-range)
(let ((last-column nil))
(loop (let ((slice (cassandra_8.3.0:get-slice keyspace key column-parent slice-predicate consistency-level)))
(when last-column (pop slice))
(unless slice (return))
(loop (unless slice (return))
(when (minusp (decf count)) (return))
(funcall op (setf last-column (cassandra_8.3.0:columnorsupercolumn-column (pop slice)))))
(setf (cassandra_8.3.0:slicerange-start slice-range)
(cassandra_8.3.0:column-name last-column)))))))))
;;; multiget: 0.6 only
(defmethod multiget ((keyspace cassandra_2.1.0:keyspace) &key
keys column-path
(consistency-level (keyspace-consistency-level keyspace)))
(cassandra_2.1.0:multiget keyspace (keyspace-name keyspace) keys column-path consistency-level))
;;; multiget_slice
(defmethod multiget-slice ((keyspace cassandra_2.1.0:keyspace) &key
keys column-parent predicate
(consistency-level (keyspace-consistency-level keyspace)))
(cassandra_2.1.0:multiget-slice keyspace (keyspace-name keyspace) keys column-parent predicate consistency-level))
(defmethod multiget-slice ((keyspace cassandra_8.3.0:keyspace) &key
keys column-parent predicate
(consistency-level (keyspace-consistency-level keyspace)))
(cassandra_8.3.0:multiget-slice keyspace keys column-parent predicate consistency-level))
;;; get_count
(defmethod get-count ((keyspace cassandra_2.1.0:keyspace) &key
key column-parent predicate
(consistency-level (keyspace-consistency-level keyspace)))
(when predicate (warn "Predicate is ignored: ~a; ~a" keyspace predicate))
(cassandra_2.1.0:get-count keyspace (keyspace-name keyspace) key column-parent consistency-level))
(defmethod get-count ((keyspace cassandra_8.3.0:keyspace) &key
key column-parent predicate
(consistency-level (keyspace-consistency-level keyspace)))
(cassandra_8.3.0:get-count keyspace key column-parent predicate consistency-level))
;;; multiget_count : >= 0.7, ? but with a keyspace name ?
(defmethod multiget-count ((keyspace cassandra_8.3.0:keyspace) &key
keys column-parent predicate
(consistency-level (keyspace-consistency-level keyspace)))
(cassandra_8.3.0:multiget-count keyspace (keyspace-name keyspace) keys column-parent predicate consistency-level))
;;; get_range_slice : <= 0.6
(defmethod get-range-slice ((keyspace cassandra_2.1.0:keyspace) &key
column-parent predicate start-key finish-key row-count
(consistency-level (keyspace-consistency-level keyspace)))
(cassandra_2.1.0:get-range-slice keyspace (keyspace-name keyspace) column-parent predicate
start-key finish-key row-count consistency-level))
;;; get_range_slices
(defmethod get-range-slices ((keyspace cassandra_2.1.0:keyspace) &key
key (start-key key) (finish-key key)
column-family super-column (start "") (finish "") (column-names nil cn-s) reversed count
(consistency-level (keyspace-consistency-level keyspace)))
(unless count (setf count (keyspace-slice-size keyspace)))
(let ((key-range (cassandra_2.1.0:make-keyrange :start-key start-key :end-key finish-key :count count))
(column-parent (cassandra_2.1.0:make-columnparent :column-family column-family))
(slice-predicate (cassandra_2.1.0:make-slicepredicate)))
(when super-column
(setf (cassandra_2.1.0:columnparent-super-column column-parent) super-column))
(if cn-s
(setf (cassandra_2.1.0:slicepredicate-column-names slice-predicate) (mapcar #'string column-names))
(setf (cassandra_2.1.0:slicepredicate-slice-range slice-predicate)
(cassandra_2.1.0:make-slicerange :reversed reversed :count most-positive-i32 :start start :finish finish)))
(cassandra_2.1.0:get-range-slices keyspace (keyspace-name keyspace) column-parent slice-predicate key-range consistency-level)))
(defmethod get-range-slices ((keyspace cassandra_8.3.0:keyspace) &key
key (start-key key) (finish-key key)
column-family super-column (start "") (finish "") (column-names nil cn-s) reversed count
(consistency-level (keyspace-consistency-level keyspace)))
(unless count (setf count (keyspace-slice-size keyspace)))
(let ((key-range (cassandra_8.3.0:make-keyrange :start-key start-key :end-key finish-key :count count))
(column-parent (cassandra_2.1.0:make-columnparent :column-family column-family))
(slice-predicate (cassandra_2.1.0:make-slicepredicate)))
(when super-column
(setf (cassandra_2.1.0:columnparent-super-column column-parent) super-column))
(if cn-s
(setf (cassandra_2.1.0:slicepredicate-column-names slice-predicate) (mapcar #'string column-names))
(setf (cassandra_2.1.0:slicepredicate-slice-range slice-predicate)
(cassandra_2.1.0:make-slicerange :reversed reversed :count count :start start :finish finish)))
(cassandra_8.3.0:get-range-slices keyspace column-parent slice-predicate key-range consistency-level)))
(defmethod map-range-slices (op (keyspace cassandra_2.1.0:keyspace) &key
key (start-key key) (finish-key key)
column-family super-column (start "") (finish "") (column-names nil cn-s) reversed
(count (keyspace-slice-size keyspace))
(consistency-level (keyspace-consistency-level keyspace)))
(let ((key-range (cassandra_2.1.0:make-keyrange :start-key start-key :end-key finish-key :count (keyspace-slice-size keyspace)))
(column-parent (cassandra_2.1.0:make-columnparent :column-family column-family))
(slice-predicate (cassandra_2.1.0:make-slicepredicate))
(slice-range nil))
(when super-column
(setf (cassandra_2.1.0:columnparent-super-column column-parent) super-column))
(cond (cn-s
(setf (cassandra_2.1.0:slicepredicate-column-names slice-predicate) (mapcar #'string column-names)))
(t
(setf slice-range (cassandra_2.1.0:make-slicerange :reversed reversed :count (keyspace-slice-size keyspace) :start start :finish finish))
(setf (cassandra_2.1.0:slicepredicate-slice-range slice-predicate) slice-range)))
(let ((last-key-slice nil))
(loop (let ((slice (cassandra_2.1.0:get-range-slices keyspace (keyspace-name keyspace) column-parent slice-predicate key-range consistency-level)))
(when last-key-slice (pop slice))
(unless slice (return))
(loop (unless slice (return))
(when (and count (minusp (decf count))) (return))
(setf last-key-slice (pop slice))
(funcall op last-key-slice)
(setf (cassandra_2.1.0:keyrange-start-key key-range)
(cassandra_2.1.0:keyslice-key last-key-slice))))))))
(defmethod map-range-slices (op (keyspace cassandra_8.3.0:keyspace) &key
key (start-key key) (finish-key key)
column-family super-column (start "") (finish "") (column-names nil cn-s) reversed
(count (keyspace-slice-size keyspace))
(consistency-level (keyspace-consistency-level keyspace)))
(let ((key-range (cassandra_8.3.0:make-keyrange :start-key start-key :end-key finish-key :count (keyspace-slice-size keyspace)))
(column-parent (cassandra_8.3.0:make-columnparent :column-family column-family))
(slice-predicate (cassandra_8.3.0:make-slicepredicate))
(slice-range nil))
(when super-column
(setf (cassandra_8.3.0:columnparent-super-column column-parent) super-column))
(cond (cn-s
(setf (cassandra_8.3.0:slicepredicate-column-names slice-predicate) (mapcar #'string column-names)))
(t
(setf slice-range (cassandra_8.3.0:make-slicerange :reversed reversed :count (keyspace-slice-size keyspace) :start start :finish finish))
(setf (cassandra_8.3.0:slicepredicate-slice-range slice-predicate) slice-range)))
(let ((last-key-slice nil))
(loop (let ((slice (cassandra_8.3.0:get-range-slices keyspace column-parent slice-predicate key-range consistency-level)))
(when last-key-slice (pop slice))
(unless slice (return))
(loop (unless slice (return))
(when (and count (minusp (decf count))) (return))
(setf last-key-slice (pop slice))
(funcall op last-key-slice)
(setf (cassandra_8.3.0:keyrange-start-key key-range)
(cassandra_8.3.0:keyslice-key last-key-slice))))))))
;;; scan
(defmethod scan ((keyspace cassandra_8.3.0:keyspace) &key
column-parent row-predicate column-predicate
(consistency-level (keyspace-consistency-level keyspace)))
(cassandra_8.3.0:scan keyspace column-parent row-predicate column-predicate consistency-level))
;;; scan-count : >= 0.7
(defmethod scan-count ((keyspace cassandra_8.3.0:keyspace) &key
column-parent row-predicate column-predicate
(consistency-level (keyspace-consistency-level keyspace)))
(cassandra_8.3.0:scan-count keyspace column-parent row-predicate column-predicate consistency-level))
;;; insert
(defmethod insert ((keyspace cassandra_2.1.0:keyspace) &key
key column-family super-column column value ttl
timestamp (clock (keyspace-clock keyspace timestamp))
(consistency-level (keyspace-consistency-level keyspace)))
(when ttl (warn "TTL is ignored: ~a; ~a" keyspace ttl))
(let ((column-path (cassandra_2.1.0:make-columnpath :column-family column-family
:column column)))
(when super-column (setf (cassandra_2.1.0:columnpath-super-column column-path) super-column))
(cassandra_2.1.0:insert keyspace (keyspace-name keyspace) key column-path value (cassandra_8.3.0:clock-timestamp clock) consistency-level)))
(defmethod insert ((keyspace cassandra_8.3.0:keyspace) &key
key column-family super-column column value ttl
timestamp (clock (keyspace-clock keyspace timestamp))
(consistency-level (keyspace-consistency-level keyspace)))
(let ((column-parent (cassandra_8.3.0:make-columnparent :column-family column-family))
(column (cassandra_8.3.0:make-column :name column :value value :clock clock)))
(when super-column (setf (cassandra_8.3.0:columnparent-super-column column-parent) super-column))
(when ttl (setf (cassandra_8.3.0:column-ttl column) ttl))
(cassandra_8.3.0:insert keyspace key column-parent column consistency-level)))
;;; batch_insert : <= 0.6
(defmethod batch-insert ((keyspace cassandra_2.1.0:keyspace) &key
key cfmap
(consistency-level (keyspace-consistency-level keyspace)))
(cassandra_2.1.0:batch-insert keyspace (keyspace-name keyspace) key cfmap consistency-level))
;;; remove
(defmethod remove ((keyspace cassandra_2.1.0:keyspace) &key
(key (error "key is required."))
(column-family (error "column-family is required."))
super-column column
timestamp (clock (keyspace-clock keyspace timestamp))
(consistency-level (keyspace-consistency-level keyspace)))
(let ((column-path (cassandra_2.1.0:make-columnpath :column-family column-family)))
(when column (setf (cassandra_2.1.0:columnpath-column column-path) column))
(when super-column (setf (cassandra_2.1.0:columnpath-super-column column-path) super-column))
(cassandra_2.1.0:remove keyspace (keyspace-name keyspace) key column-path (cassandra_8.3.0:clock-timestamp clock) consistency-level)))
(defmethod remove ((keyspace cassandra_8.3.0:keyspace) &key
(key (error "key is required."))
(column-family (error "column-family is required."))
super-column column
timestamp (clock (keyspace-clock keyspace timestamp))
(consistency-level (keyspace-consistency-level keyspace)))
(let ((column-path (cassandra_8.3.0:make-columnpath :column-family column-family)))
(when column (setf (cassandra_2.1.0:columnpath-column column-path) column))
(when super-column (setf (cassandra_8.3.0:columnpath-super-column column-path) super-column))
(cassandra_8.3.0:remove keyspace key column-path clock consistency-level)))
;;; batch_mutate
(defmethod batch-mutate ((keyspace cassandra_2.1.0:keyspace) &key
mutation-map
(consistency-level (keyspace-consistency-level keyspace)))
(cassandra_2.1.0:batch-mutate keyspace (keyspace-name keyspace) mutation-map consistency-level))
(defmethod batch-mutate ((keyspace cassandra_8.3.0:keyspace) &key
mutation-map
(consistency-level (keyspace-consistency-level keyspace)))
(cassandra_8.3.0:batch-mutate keyspace mutation-map consistency-level))
(defgeneric make-standard-mutation-map (keyspace family-name key &rest plist)
(:documentation "Construct a mutation script for a standard column family given a FAMILY-NAME, a row KEY,
and a name/value PLIST for the individual columns.")
(:method ((keyspace cassandra_2.1.0:keyspace) column-family-name key &rest name-value-plist)
(declare (dynamic-extent name-value-plist))
(let* ((clock (keyspace-clock keyspace))
(timestamp (cassandra_8.3.0:clock-timestamp clock)))
(thrift:map key (thrift:map column-family-name
(loop for (column-name value) on name-value-plist by #'cddr
when value ; skip null values
collect (cassandra_2.1.0:make-mutation
:column-or-supercolumn (cassandra_2.1.0:make-columnorsupercolumn
:column (cassandra_2.1.0:make-column
:name column-name
:value value
:timestamp timestamp))))))))
(:method ((keyspace cassandra_8.3.0:keyspace) column-family-name key &rest name-value-plist)
(declare (dynamic-extent name-value-plist))
(let ((clock (keyspace-clock keyspace)))
(thrift:map key (thrift:map column-family-name
(loop for (column-name value) on name-value-plist by #'cddr
when value ; skip null values
collect (cassandra_8.3.0:make-mutation
:column-or-supercolumn (cassandra_8.3.0:make-columnorsupercolumn
:column (cassandra_8.3.0:make-column
:name column-name
:value value
:clock clock)))))))))
(defgeneric make-super-mutation-map (keyspace family-name key super-column-key &rest plist)
(:documentation "Construct a mutation script for a super column family given a FAMILY-NAME, a row KEY,
a SUPER-COLUMN-KEY, and a name/value PLIST for the individual columns.")
(:method ((keyspace cassandra_2.1.0:keyspace) column-family-name key super-column-key &rest name-value-plist)
(declare (dynamic-extent name-value-plist))
(let* ((clock (keyspace-clock keyspace))
(timestamp (cassandra_8.3.0:clock-timestamp clock)))
(thrift:map key (thrift:map column-family-name
(list (cassandra_2.1.0:make-mutation
:column-or-supercolumn
(cassandra_2.1.0:make-columnorsupercolumn
:super-column (cassandra_2.1.0:make-supercolumn
:name super-column-key
:columns (loop for (column-name value)
on name-value-plist by #'cddr
when value ; skip null values
collect (cassandra_2.1.0:make-column
:name column-name
:value value
:timestamp timestamp))))))))))
(:method ((keyspace cassandra_8.3.0:keyspace) column-family-name key super-column-key &rest name-value-plist)
(declare (dynamic-extent name-value-plist))
(let* ((clock (keyspace-clock keyspace)))
(thrift:map key (thrift:map column-family-name
(list (cassandra_8.3.0:make-mutation
:column-or-supercolumn
(cassandra_8.3.0:make-columnorsupercolumn
:super-column (cassandra_8.3.0:make-supercolumn
:name super-column-key
:columns (loop for (column-name value)
on name-value-plist by #'cddr
when value ; skip null values
collect (cassandra_8.3.0:make-column
:name column-name
:value value
:clock clock)))))))))))
#+(or)
(make-standard-mutation-map (allocate-instance (find-class 'cassandra_8.3.0:keyspace)) "SPOCIndex" "spoc-1"
:subject "s1" :predicate "p1" :object "o1" :context "c1")
;;; truncate : >= 0.7
(defmethod truncate ((keyspace cassandra_8.3.0:keyspace) &key
column-family)
(cassandra_8.3.0:truncate keyspace column-family))
;;; check_schema_agreement : >= 0.7
(defmethod check-schema-agreement ((keyspace cassandra_8.3.0:keyspace))
(cassandra_8.3.0:check-schema-agreement keyspace))
;;; get_string_property : <= 0.6
(defmethod get-string-property ((keyspace cassandra_2.1.0:keyspace) &key property)
(cassandra_2.1.0:get-string-property keyspace property))
;;; get_string_list_property : <= 0.6
(defmethod get-string-list-property ((keyspace cassandra_2.1.0:keyspace) &key property)
(cassandra_2.1.0:get-string-list-property keyspace property))
;;; describe_keyspaces
(defmethod describe-keyspaces ((keyspace keyspace))
;; get by with the earliest version
(cassandra_2.1.0:describe-keyspaces keyspace))
(defmethod describe-keyspaces ((keyspace cassandra_2.1.0:keyspace))
(cassandra_2.1.0:describe-keyspaces keyspace))
(defmethod describe-keyspaces ((keyspace cassandra_8.3.0:keyspace))
(cassandra_8.3.0:describe-keyspaces keyspace))
;;; describe_cluster_name
(defmethod describe-cluster-name ((keyspace cassandra_2.1.0:keyspace))
(cassandra_2.1.0:describe-cluster-name keyspace))
(defmethod describe-cluster-name ((keyspace cassandra_8.3.0:keyspace))
(cassandra_8.3.0:describe-cluster-name keyspace))
;;; describe_version
(defmethod describe-version ((keyspace keyspace))
;; get by with the earliest version
(cassandra_2.1.0:describe-version keyspace))
(defmethod describe-version ((keyspace cassandra_2.1.0:keyspace))
(cassandra_2.1.0:describe-version keyspace))
(defmethod describe-version ((keyspace cassandra_8.3.0:keyspace))
(cassandra_8.3.0:describe-version keyspace))
;;; describe_ring
(defmethod describe-ring ((keyspace cassandra_2.1.0:keyspace))
(cassandra_2.1.0:describe-ring keyspace (keyspace-name keyspace)))
(defmethod describe-ring ((keyspace cassandra_8.3.0:keyspace))
(cassandra_8.3.0:describe-ring keyspace (keyspace-name keyspace)))
;;; describe_keyspace
(defmethod describe-keyspace ((keyspace cassandra_2.1.0:keyspace))
(cassandra_2.1.0:describe-keyspace keyspace (keyspace-name keyspace)))
(defmethod describe-keyspace ((keyspace cassandra_8.3.0:keyspace))
(cassandra_8.3.0:describe-keyspace keyspace (keyspace-name keyspace)))
(defmethod system-add-column-family ((keyspace cassandra_8.3.0:keyspace) &key cf-def)
(cassandra_8.3.0:system-add-column-family keyspace cf-def))
(defmethod system-drop-column-family ((keyspace cassandra_8.3.0:keyspace) column-family)
(cassandra_8.3.0:system-drop-column-family keyspace column-family))
(defmethod system-rename-column-family ((keyspace cassandra_8.3.0:keyspace) &key old-name new-name)
(cassandra_8.3.0:system-rename-column-family keyspace old-name new-name))
(defmethod system-add-keyspace ((keyspace cassandra_8.3.0:keyspace) ks-def)
(cassandra_8.3.0:system-add-keyspace keyspace ks-def))
(defmethod system-drop-keyspace ((keyspace cassandra_8.3.0:keyspace) keyspace-name)
(cassandra_8.3.0:system-drop-keyspace keyspace keyspace-name))
(defmethod system-rename-keyspace ((keyspace cassandra_8.3.0:keyspace) old-name new-name)
(cassandra_8.3.0:system-rename-keyspace keyspace old-name new-name))