cassie 1.0.0.beta.26 → 1.0.0.beta.27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cassie/statements/README.md +142 -77
- data/lib/cassie/statements/statement.rb +4 -3
- data/lib/cassie/statements/statement/idempotency.rb +7 -3
- data/lib/cassie/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc7caa19b667525c10964c15b1c8c0560280bbb7
|
4
|
+
data.tar.gz: 4c77f29fbdc4fff2693125498ebc00a9497218e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d8b604b1c52dea54e403534c6d4244464ed22eee9791a432da16a19534c1929358c0f1b5de03fc86c5c3fc7f858f01f45f9a1370f52f4f8c7d06891e5069b79
|
7
|
+
data.tar.gz: 1f09cc8256cdd66eb76b827216008287b8cd9a524ab1349fe3a29b832aeeb1148f3fb3ba5da80ff0ded2abd1cea0ca3798569c8622a61e119dace401d17e97b6
|
@@ -88,7 +88,7 @@ Cassie provides 3 base classes for these 3 kinds of queries. Subclass `Cassie::D
|
|
88
88
|
* `result` attribute, populated by execution
|
89
89
|
* instrumentation and logging of execution
|
90
90
|
|
91
|
-
|
91
|
+
A typical use of a `Definition` subclass would be for a static DDL query. Override the `statement` method, returning a CQL statement (`String` or `Cassandra::Statements`) that will be executed with the `Cassandra` driver.
|
92
92
|
|
93
93
|
##### `Cassie::Modification`
|
94
94
|
Includes core functionality for prepared statement execution.
|
@@ -280,9 +280,11 @@ set :id, term: "now()"
|
|
280
280
|
```
|
281
281
|
|
282
282
|
```ruby
|
283
|
-
|
283
|
+
update :post_counts
|
284
|
+
|
285
|
+
set :comments_count, "comments_count + 1"
|
284
286
|
|
285
|
-
|
287
|
+
non_idempotent
|
286
288
|
```
|
287
289
|
|
288
290
|
A value will be fetched and placed as an argument in the statement if the provided term includes a positional marker ('?').
|
@@ -351,80 +353,6 @@ Arbitrary strings are supported as well in case the DSL gets in the way.
|
|
351
353
|
#=> SELECT cowboy, coder FROM posts_by_author;
|
352
354
|
```
|
353
355
|
|
354
|
-
#### Consistency configuration
|
355
|
-
|
356
|
-
The [consistency level](http://datastax.github.io/ruby-driver/v2.1.6/api/cassandra/#consistencies-constant) for a query is determined by your `Cassie::configuration` by default, falling to back to the `Cassandra` default if none is given.
|
357
|
-
|
358
|
-
```ruby
|
359
|
-
Cassie.configuration[:consistency]
|
360
|
-
#=> nil
|
361
|
-
|
362
|
-
Cassie.cluster.instance_variable_get(:@execution_options).consistency
|
363
|
-
#=> :one
|
364
|
-
```
|
365
|
-
|
366
|
-
Cassie queries allow for a consistency level to be defined on the object, subclass, base class, and global levels. If none is found, it will default to the `cluster` default when the query is executed.
|
367
|
-
|
368
|
-
Object writer:
|
369
|
-
```ruby
|
370
|
-
query = MyQuery.new
|
371
|
-
query.consistency = :all
|
372
|
-
query.execute
|
373
|
-
```
|
374
|
-
Override Object reader:
|
375
|
-
```ruby
|
376
|
-
select_from :posts_by_author_category
|
377
|
-
|
378
|
-
where :author_id, :eq
|
379
|
-
where :category, :eq, if: :filter_by_category?
|
380
|
-
|
381
|
-
def filter_by_category?
|
382
|
-
#true or false, as makes sense for your query
|
383
|
-
end
|
384
|
-
|
385
|
-
def consistency
|
386
|
-
#dynamically determine a query object's consistency level
|
387
|
-
if filter_by_category?
|
388
|
-
:quorum
|
389
|
-
else
|
390
|
-
super
|
391
|
-
end
|
392
|
-
end
|
393
|
-
```
|
394
|
-
|
395
|
-
Class writer
|
396
|
-
```ruby
|
397
|
-
select_from :posts_by_author_category
|
398
|
-
|
399
|
-
where :author_id, :eq
|
400
|
-
where :category, :eq
|
401
|
-
|
402
|
-
consistency :quorum
|
403
|
-
```
|
404
|
-
|
405
|
-
Cassie query classes
|
406
|
-
```ruby
|
407
|
-
# lib/tasks/interesting_task.rake
|
408
|
-
require_relative "interesting_worker"
|
409
|
-
|
410
|
-
task :interesting_task do
|
411
|
-
Cassie::Modification.consistency = :all
|
412
|
-
|
413
|
-
InterestingWorker.new.perform
|
414
|
-
end
|
415
|
-
```
|
416
|
-
|
417
|
-
Cassie global default
|
418
|
-
```ruby
|
419
|
-
# lib/tasks/interesting_task.rake
|
420
|
-
require_relative "interesting_worker"
|
421
|
-
|
422
|
-
task :interesting_task do
|
423
|
-
Cassie::Statements.default_consistency = :all
|
424
|
-
|
425
|
-
InterestingWorker.new.perform
|
426
|
-
end
|
427
|
-
```
|
428
356
|
|
429
357
|
#### Execution and Result
|
430
358
|
|
@@ -698,6 +626,123 @@ By default, this works for ascending and descending orderings when paging in the
|
|
698
626
|
|
699
627
|
Custom policies can be defined by setting `Query.partition_linker` for more complex schemas. See the `SimplePolicy` source for an example.
|
700
628
|
|
629
|
+
#### Consistency configuration
|
630
|
+
|
631
|
+
The [consistency level](http://datastax.github.io/ruby-driver/api/cassandra/#consistencies-constant) for a query is determined by your `Cassie::configuration` by default, falling to back to the `Cassandra` default if none is given.
|
632
|
+
|
633
|
+
```ruby
|
634
|
+
Cassie.configuration[:consistency]
|
635
|
+
#=> nil
|
636
|
+
|
637
|
+
Cassie.cluster.instance_variable_get(:@execution_options).consistency
|
638
|
+
#=> :one
|
639
|
+
```
|
640
|
+
|
641
|
+
Cassie queries allow for a consistency level to be defined on the object, subclass, base class, and global levels. If none is found, it will default to the `cluster` default when the query is executed.
|
642
|
+
|
643
|
+
Object writer:
|
644
|
+
```ruby
|
645
|
+
query = MyQuery.new
|
646
|
+
query.consistency = :all
|
647
|
+
query.execute
|
648
|
+
```
|
649
|
+
Override Object reader:
|
650
|
+
```ruby
|
651
|
+
select_from :posts_by_author_category
|
652
|
+
|
653
|
+
where :author_id, :eq
|
654
|
+
where :category, :eq, if: :filter_by_category?
|
655
|
+
|
656
|
+
def filter_by_category?
|
657
|
+
#true or false, as makes sense for your query
|
658
|
+
end
|
659
|
+
|
660
|
+
def consistency
|
661
|
+
#dynamically determine a query object's consistency level
|
662
|
+
if filter_by_category?
|
663
|
+
:quorum
|
664
|
+
else
|
665
|
+
super
|
666
|
+
end
|
667
|
+
end
|
668
|
+
```
|
669
|
+
|
670
|
+
Class writer
|
671
|
+
```ruby
|
672
|
+
select_from :posts_by_author_category
|
673
|
+
|
674
|
+
where :author_id, :eq
|
675
|
+
where :category, :eq
|
676
|
+
|
677
|
+
consistency :quorum
|
678
|
+
```
|
679
|
+
|
680
|
+
Cassie query classes
|
681
|
+
```ruby
|
682
|
+
# lib/tasks/interesting_task.rake
|
683
|
+
require_relative "interesting_worker"
|
684
|
+
|
685
|
+
task :interesting_task do
|
686
|
+
Cassie::Modification.consistency = :all
|
687
|
+
|
688
|
+
InterestingWorker.new.perform
|
689
|
+
end
|
690
|
+
```
|
691
|
+
|
692
|
+
Cassie global default
|
693
|
+
```ruby
|
694
|
+
# lib/tasks/interesting_task.rake
|
695
|
+
require_relative "interesting_worker"
|
696
|
+
|
697
|
+
task :interesting_task do
|
698
|
+
Cassie::Statements.default_consistency = :all
|
699
|
+
|
700
|
+
InterestingWorker.new.perform
|
701
|
+
end
|
702
|
+
```
|
703
|
+
|
704
|
+
#### Idempotentcy configuration
|
705
|
+
|
706
|
+
Cassie statements are set as [idempotent](http://datastax.github.io/ruby-driver/api/cassandra/statements/simple/) by default. This setting influences how [retries](http://datastax.github.io/ruby-driver/features/retry_policies/) are handled.
|
707
|
+
|
708
|
+
Mark queries that are not idempotent, so that the driver won't automatically retry for certain failure scenarios.
|
709
|
+
|
710
|
+
Similar to other settings, there is a `Cassie::Statements.default_idempotency`, class level setting, and object level setting.
|
711
|
+
|
712
|
+
```ruby
|
713
|
+
class MyQuery < Cassie::Modification
|
714
|
+
update :counter_table
|
715
|
+
|
716
|
+
set :counter, term: :counter_val
|
717
|
+
|
718
|
+
def counter_val
|
719
|
+
"counter + 1"
|
720
|
+
end
|
721
|
+
end
|
722
|
+
```
|
723
|
+
```
|
724
|
+
MyQuery.idempotent?
|
725
|
+
# => true
|
726
|
+
```
|
727
|
+
|
728
|
+
```ruby
|
729
|
+
class MyQuery < Cassie::Modification
|
730
|
+
update :counter_table
|
731
|
+
|
732
|
+
set :counter, term: :counter_val
|
733
|
+
|
734
|
+
non_idempotent
|
735
|
+
|
736
|
+
def counter_val
|
737
|
+
"counter + 1"
|
738
|
+
end
|
739
|
+
end
|
740
|
+
```
|
741
|
+
```
|
742
|
+
MyQuery.idempotent?
|
743
|
+
# => false
|
744
|
+
```
|
745
|
+
|
701
746
|
#### Prepared statements
|
702
747
|
|
703
748
|
A `Cassie::Query` will use prepared statements by default, cacheing prepared statements across all `Query`, `Modification`, and `Definition` objects, keyed by the unbound CQL string.
|
@@ -728,6 +773,26 @@ set_1 = query.fetch([1, 2, 3])
|
|
728
773
|
set_2 = query.fetch([7, 8, 9, 10, 11, 12])
|
729
774
|
```
|
730
775
|
|
776
|
+
#### Custom queries
|
777
|
+
|
778
|
+
For certain queries, it may be more effective to write your own CQL. The recommended way is to override `cql` and `params`.
|
779
|
+
|
780
|
+
```ruby
|
781
|
+
class MySpecialQuery < Cassandra::Modification
|
782
|
+
map_from :resource
|
783
|
+
|
784
|
+
def cql
|
785
|
+
"UPDATE my_table SET udt.field = ? WHERE id = ?;"
|
786
|
+
end
|
787
|
+
|
788
|
+
def params
|
789
|
+
[field, id]
|
790
|
+
end
|
791
|
+
end
|
792
|
+
```
|
793
|
+
|
794
|
+
This will preserve using other features such as consistency, idempotency, prepared statements, etc.
|
795
|
+
|
731
796
|
#### Non-positional (unbound) statements
|
732
797
|
|
733
798
|
Cassie Query features are built around using bound statements with positional arguments. However, overriding `#statement`, returning something that a `Cassandra::Session` can execute, will result in an unbound, unprepared statement.
|
@@ -48,16 +48,16 @@ module Cassie::Statements
|
|
48
48
|
statement.to_s
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
def logger
|
53
53
|
Cassie::Statements.logger
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def cql
|
57
57
|
return @cql if defined?(@cql)
|
58
58
|
""
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def params
|
62
62
|
return @params if defined?(@params)
|
63
63
|
nil
|
@@ -69,6 +69,7 @@ module Cassie::Statements
|
|
69
69
|
if self.class.type
|
70
70
|
send "build_#{self.class.type}_cql_and_params"
|
71
71
|
end
|
72
|
+
|
72
73
|
[cql, params]
|
73
74
|
end
|
74
75
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Cassie::Statements
|
2
2
|
def self.default_idempotency
|
3
3
|
return @default_idempotency if defined?(@default_idempotency)
|
4
|
-
|
4
|
+
true
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.default_idempotency=(val)
|
@@ -34,7 +34,11 @@ module Cassie::Statements
|
|
34
34
|
self.idempotent = val
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
|
+
def non_idempotent
|
39
|
+
self.idempotent = false
|
40
|
+
end
|
41
|
+
|
38
42
|
def idempotent?
|
39
43
|
!!idempotent
|
40
44
|
end
|
@@ -44,7 +48,7 @@ module Cassie::Statements
|
|
44
48
|
return @idempotent if defined?(@idempotent)
|
45
49
|
self.class.idempotent
|
46
50
|
end
|
47
|
-
|
51
|
+
|
48
52
|
def idempotent?
|
49
53
|
!!idempotent
|
50
54
|
end
|
data/lib/cassie/version.rb
CHANGED