cassandra-driver 2.1.7-java → 3.0.0.beta.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +31 -53
  3. data/lib/cassandra.rb +22 -3
  4. data/lib/cassandra/aggregate.rb +109 -0
  5. data/lib/cassandra/argument.rb +51 -0
  6. data/lib/cassandra/auth/providers/password.rb +7 -4
  7. data/lib/cassandra/cluster.rb +14 -3
  8. data/lib/cassandra/cluster/client.rb +56 -34
  9. data/lib/cassandra/cluster/connector.rb +6 -6
  10. data/lib/cassandra/cluster/control_connection.rb +204 -251
  11. data/lib/cassandra/cluster/metadata.rb +2 -0
  12. data/lib/cassandra/cluster/schema.rb +131 -209
  13. data/lib/cassandra/cluster/schema/cql_type_parser.rb +104 -0
  14. data/lib/cassandra/cluster/schema/fetchers.rb +1174 -0
  15. data/lib/cassandra/cluster/schema/{type_parser.rb → fqcn_type_parser.rb} +7 -3
  16. data/lib/cassandra/column.rb +2 -2
  17. data/lib/cassandra/driver.rb +27 -9
  18. data/lib/cassandra/errors.rb +179 -25
  19. data/lib/cassandra/execution/info.rb +8 -1
  20. data/lib/cassandra/execution/options.rb +34 -0
  21. data/lib/cassandra/execution/trace.rb +42 -10
  22. data/lib/cassandra/function.rb +150 -0
  23. data/lib/cassandra/future.rb +66 -35
  24. data/lib/cassandra/host.rb +7 -4
  25. data/lib/cassandra/keyspace.rb +112 -13
  26. data/lib/cassandra/load_balancing.rb +1 -1
  27. data/lib/cassandra/protocol.rb +9 -3
  28. data/lib/cassandra/protocol/coder.rb +434 -155
  29. data/lib/cassandra/protocol/cql_byte_buffer.rb +43 -0
  30. data/lib/cassandra/protocol/cql_protocol_handler.rb +4 -1
  31. data/lib/cassandra/protocol/request.rb +4 -0
  32. data/lib/cassandra/protocol/requests/auth_response_request.rb +5 -1
  33. data/lib/cassandra/protocol/requests/batch_request.rb +7 -2
  34. data/lib/cassandra/protocol/requests/credentials_request.rb +5 -1
  35. data/lib/cassandra/protocol/requests/execute_request.rb +16 -10
  36. data/lib/cassandra/protocol/requests/prepare_request.rb +12 -3
  37. data/lib/cassandra/protocol/requests/query_request.rb +20 -11
  38. data/lib/cassandra/protocol/responses/already_exists_error_response.rb +4 -4
  39. data/lib/cassandra/protocol/responses/error_response.rb +14 -14
  40. data/lib/cassandra/protocol/responses/function_failure_error_response.rb +41 -0
  41. data/lib/cassandra/protocol/responses/prepared_result_response.rb +12 -9
  42. data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +5 -3
  43. data/lib/cassandra/protocol/responses/read_failure_error_response.rb +43 -0
  44. data/lib/cassandra/protocol/responses/read_timeout_error_response.rb +4 -4
  45. data/lib/cassandra/protocol/responses/ready_response.rb +5 -1
  46. data/lib/cassandra/protocol/responses/result_response.rb +3 -3
  47. data/lib/cassandra/protocol/responses/rows_result_response.rb +2 -2
  48. data/lib/cassandra/protocol/responses/schema_change_event_response.rb +25 -24
  49. data/lib/cassandra/protocol/responses/schema_change_result_response.rb +20 -23
  50. data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +2 -2
  51. data/lib/cassandra/protocol/responses/unavailable_error_response.rb +4 -4
  52. data/lib/cassandra/protocol/responses/unprepared_error_response.rb +4 -4
  53. data/lib/cassandra/protocol/responses/write_failure_error_response.rb +45 -0
  54. data/lib/cassandra/protocol/responses/write_timeout_error_response.rb +4 -4
  55. data/lib/cassandra/protocol/v1.rb +38 -13
  56. data/lib/cassandra/protocol/v3.rb +34 -29
  57. data/lib/cassandra/protocol/v4.rb +334 -0
  58. data/lib/cassandra/result.rb +10 -9
  59. data/lib/cassandra/retry.rb +17 -3
  60. data/lib/cassandra/retry/policies/default.rb +9 -3
  61. data/lib/cassandra/session.rb +15 -7
  62. data/lib/cassandra/statement.rb +5 -0
  63. data/lib/cassandra/statements/batch.rb +36 -12
  64. data/lib/cassandra/statements/bound.rb +2 -1
  65. data/lib/cassandra/statements/prepared.rb +106 -35
  66. data/lib/cassandra/statements/simple.rb +4 -2
  67. data/lib/cassandra/table.rb +70 -105
  68. data/lib/cassandra/time.rb +98 -0
  69. data/lib/cassandra/time_uuid.rb +1 -1
  70. data/lib/cassandra/tuple.rb +7 -0
  71. data/lib/cassandra/types.rb +472 -272
  72. data/lib/cassandra/udt.rb +10 -0
  73. data/lib/cassandra/util.rb +32 -1
  74. data/lib/cassandra/uuid.rb +6 -1
  75. data/lib/cassandra/uuid/generator.rb +7 -7
  76. data/lib/cassandra/version.rb +1 -1
  77. data/lib/cassandra_murmur3.jar +0 -0
  78. data/lib/datastax/cassandra.rb +5 -2
  79. metadata +27 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08356521233eb103e2f2bf262476dd4c7a62895c
4
- data.tar.gz: f1e63737fcd6e12d503a869cddcb70bea74bff52
3
+ metadata.gz: 1e6a787e376fb3c3593c39dfda36008493460d81
4
+ data.tar.gz: a2a29ca90926d5bd17a77c3604b79a364acd7824
5
5
  SHA512:
6
- metadata.gz: 614a6ac21232965b662687fe1af769287e2d8928af0ee890ccd5ae3625c78fd667210ca694f139622b78dd10a265c3889fe35ca20a5cb0ff0252fdbc27e42b82
7
- data.tar.gz: 682a1aa7519916253ee9e3c28a0b877c71c7efeab3a7616dbdfd3f9638e8840e5ddac246f8fd628d8146beaa3420dd33619553f9cbcda464b23a2b4f1f8fa66f
6
+ metadata.gz: d0f391e939675d5f22d8e057c9e2a75324e07762c6fd669c5768df8cb118b3d0a38daec56e81871351d80f913b3fe03d5000e3f1f5627522388780acb7accd64
7
+ data.tar.gz: 01e6930ee06ca09812de451671c4598119ebb2982619c3e663522e35938f3e6d3c846859b0192e28e00604e2fc00dcbc3c0fcdf51a6736241aa96db48fce591b
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Datastax Ruby Driver for Apache Cassandra
2
2
 
3
- *If you're reading this on GitHub, please note that this is the readme for the development version and that some
4
- features described here might not yet have been released. You can view the documentation for the latest released
5
- version [here](http://docs.datastax.com/en/developer/ruby-driver/latest).*
3
+ *If you're reading this on GitHub, please note that this is the readme for the development version and that some features described here might not yet have been released. You can [find the documentation for latest version through ruby driver docs](http://datastax.github.io/ruby-driver/) or via the release tags, [e.g. v1.0.0-beta.3](https://github.com/datastax/ruby-driver/tree/v1.0.0-beta.3).*
6
4
 
7
5
  [![Build Status](https://travis-ci.org/datastax/ruby-driver.svg?branch=master)](https://travis-ci.org/datastax/ruby-driver)
8
6
 
@@ -10,36 +8,36 @@ A Ruby client driver for Apache Cassandra. This driver works exclusively with
10
8
  the Cassandra Query Language version 3 (CQL3) and Cassandra's native protocol.
11
9
 
12
10
  - Code: https://github.com/datastax/ruby-driver
13
- - Docs: http://docs.datastax.com/en/developer/ruby-driver
11
+ - Docs: http://datastax.github.io/ruby-driver/
14
12
  - Jira: https://datastax-oss.atlassian.net/browse/RUBY
15
13
  - Mailing List: https://groups.google.com/a/lists.datastax.com/forum/#!forum/ruby-driver-user
16
14
  - IRC: #datastax-drivers on [irc.freenode.net](http://freenode.net>)
17
- - Twitter: Follow the latest news about DataStax Drivers - [@stamhankar999](http://twitter.com/stamhankar999), [@avalanche123](http://twitter.com/avalanche123), [@al3xandru](https://twitter.com/al3xandru)
15
+ - Twitter: Follow the latest news about DataStax Drivers - [@avalanche123](http://twitter.com/avalanche123), [@mfiguiere](http://twitter.com/mfiguiere), [@al3xandru](https://twitter.com/al3xandru)
18
16
 
19
17
  This driver is based on [the cql-rb gem](https://github.com/iconara/cql-rb) by [Theo Hultberg](https://github.com/iconara) and we added support for:
20
18
 
21
- * [Asynchronous execution](http://docs.datastax.com/en/developer/ruby-driver/2.1/features/asynchronous_io/)
22
- * One-off, [prepared](http://docs.datastax.com/en/developer/ruby-driver/2.1/features/basics/prepared_statements/) and [batch statements](http://docs.datastax.com/en/developer/ruby-driver/2.1/features/basics/batch_statements/)
23
- * Automatic peer discovery and cluster metadata with [support for change notifications](http://docs.datastax.com/en/developer/ruby-driver/2.1/features/state_listeners/)
24
- * Various [load-balancing](http://docs.datastax.com/en/developer/ruby-driver/2.1/features/load_balancing/), [retry](http://docs.datastax.com/en/developer/ruby-driver/2.1/features/retry_policies/) and [reconnection](http://docs.datastax.com/en/developer/ruby-driver/2.1/features/reconnection/) policies with [ability to write your own](http://docs.datastax.com/en/developer/ruby-driver/2.1/features/load_balancing/implementing_a_policy/)
25
- * [SSL encryption](http://docs.datastax.com/en/developer/ruby-driver/2.1/features/security/ssl_encryption/)
26
- * [Flexible and robust error handling](http://docs.datastax.com/en/developer/ruby-driver/2.1/features/error_handling/)
27
- * [Per-request execution information and tracing](http://docs.datastax.com/en/developer/ruby-driver/2.1/features/debugging/)
28
- * [Configurable address resolution](http://docs.datastax.com/en/developer/ruby-driver/2.1/features/address_resolution/)
19
+ * [Asynchronous execution](http://datastax.github.io/ruby-driver/features/asynchronous_io/)
20
+ * One-off, [prepared](http://datastax.github.io/ruby-driver/features/basics/prepared_statements/) and [batch statements](http://datastax.github.io/ruby-driver/features/basics/batch_statements/)
21
+ * Automatic peer discovery and cluster metadata with [support for change notifications](http://datastax.github.io/ruby-driver/features/state_listeners/)
22
+ * Various [load-balancing](http://datastax.github.io/ruby-driver/features/load_balancing/), [retry](http://datastax.github.io/ruby-driver/features/retry_policies/) and [reconnection](http://datastax.github.io/ruby-driver/features/reconnection/) policies with [ability to write your own](http://datastax.github.io/ruby-driver/features/load_balancing/implementing_a_policy/)
23
+ * [SSL encryption](http://datastax.github.io/ruby-driver/features/security/ssl_encryption/)
24
+ * [Flexible and robust error handling](http://datastax.github.io/ruby-driver/features/error_handling/)
25
+ * [Per-request execution information and tracing](http://datastax.github.io/ruby-driver/features/debugging/)
26
+ * [Configurable address resolution](http://datastax.github.io/ruby-driver/features/address_resolution/)
29
27
 
30
28
  [Check out the slides from Ruby Driver Explained](https://speakerdeck.com/avalanche123/ruby-driver-explained) for a detailed overview of the Ruby Driver architecture.
31
29
 
32
- ## Compatibility
30
+ ## Compability
33
31
 
34
32
  This driver works exclusively with the Cassandra Query Language v3 (CQL3) and Cassandra's native protocol. The current version works with:
35
33
 
36
34
  * Apache Cassandra versions 1.2, 2.0 and 2.1
37
- * DataStax Enterprise 3.1-4.8
38
- * Ruby (MRI) 2.2, 2.3
35
+ * DataStax Enterprise 3.1, 3.2, 4.0 and 4.5
36
+ * Ruby (MRI) 1.9.3, 2.0, 2.1 and 2.2
39
37
  * JRuby 1.7
38
+ * Rubinius 2.2
40
39
 
41
- __Note__: JRuby 1.6 is not officially supported, although 1.6.8 should work. Rubinius is not supported.
42
- MRI 1.9.3, 2.0, 2.1, and JRuby 9k are not officially supported, but they should work.
40
+ __Note__: JRuby 1.6 is not officially supported, although 1.6.8 should work.
43
41
 
44
42
  ## Quick start
45
43
 
@@ -68,9 +66,9 @@ __Note__: The host you specify is just a seed node, the driver will automaticall
68
66
 
69
67
  Read more:
70
68
 
71
- * [`Cassandra.cluster` options](http://docs.datastax.com/en/developer/ruby-driver/2.1/api/#cluster-class_method)
72
- * [`Session#execute_async` options](http://docs.datastax.com/en/developer/ruby-driver/2.1/api/session/#execute_async-instance_method)
73
- * [Usage documentation](http://docs.datastax.com/en/developer/ruby-driver/2.1/features)
69
+ * [`Cassandra.cluster` options](http://datastax.github.io/ruby-driver/api/#cluster-class_method)
70
+ * [`Session#execute_async` options](http://datastax.github.io/ruby-driver/api/session/#execute_async-instance_method)
71
+ * [Usage documentation](http://datastax.github.io/ruby-driver/features)
74
72
 
75
73
  ## Installation
76
74
 
@@ -86,51 +84,30 @@ Install via Gemfile
86
84
  gem 'cassandra-driver'
87
85
  ```
88
86
 
89
- __Note__: if you want to use compression you should also install [snappy](http://rubygems.org/gems/snappy) or [lz4-ruby](http://rubygems.org/gems/lz4-ruby). [Read more about compression.](http://docs.datastax.com/en/developer/ruby-driver/2.1/features/#compression)
87
+ __Note__: if you want to use compression you should also install [snappy](http://rubygems.org/gems/snappy) or [lz4-ruby](http://rubygems.org/gems/lz4-ruby). [Read more about compression.](http://datastax.github.io/ruby-driver/features/#compression)
90
88
 
91
89
 
92
90
  ## Upgrading from cql-rb
93
91
 
94
- Some of the new features added to the driver have unfortunately led to changes in the original cql-rb API.
95
- In the examples directory, you can find [an example of how to wrap the ruby driver to achieve almost complete
96
- interface parity with cql-rb](https://github.com/datastax/ruby-driver/blob/v2.1.7/examples/cql-rb-wrapper.rb)
97
- to assist you with gradual upgrade.
92
+ Some of the new features added to the driver have unfortunately led to changes in the original cql-rb API. In the examples directory, you can find [an example of how to wrap the ruby driver to achieve almost complete interface parity with cql-rb](https://github.com/datastax/ruby-driver/blob/master/examples/cql-rb-wrapper.rb) to assist you with gradual upgrade.
98
93
 
99
- ## What's new in v2.1
100
- See the [changelog](https://github.com/datastax/ruby-driver/blob/master/CHANGELOG.md) for details on patch releases.
94
+ ## What's new in v2.1.3
101
95
 
102
96
  Features:
103
97
 
104
98
  * Apache Cassandra native protocol v3
105
- * [User-defined types](http://docs.datastax.com/en/developer/ruby-driver/2.1/features/basics/user_defined_types/) and [tuples](http://docs.datastax.com/en/developer/ruby-driver/2.1/features/basics/datatypes/#using-tuples)
106
- * [Schema metadata includes user-defined types](http://docs.datastax.com/en/developer/ruby-driver/2.1/api/keyspace/#type-instance_method)
107
- * [Named arguments](http://docs.datastax.com/en/developer/ruby-driver/2.1/features/basics/prepared_statements/#an-insert-statement-is-prepared-with-named-parameters)
108
- * [Public types api for type definition and introspection](http://docs.datastax.com/en/developer/ruby-driver/2.1/api/types/)
109
- * Add support for disabling nagle algorithm (tcp nodelay), enabled by default.
110
- * Add support for client-side timestamps, disabled by default.
111
- * Add support for serial consistency in batch requests.
112
- * Add support for `type_hints` to override type-guessing for non-prepared statements.
113
-
99
+ * [User-defined types](http://datastax.github.io/ruby-driver/features/basics/user_defined_types/) and [tuples](http://datastax.github.io/ruby-driver/features/basics/datatypes/#using-tuples)
100
+ * [Schema metadata includes user-defined types](http://datastax.github.io/ruby-driver/api/keyspace/#type-instance_method)
101
+ * [Named arguments](http://datastax.github.io/ruby-driver/features/basics/prepared_statements/#an-insert-statement-is-prepared-with-named-parameters)
102
+ * [Public types api for type definition and introspection](http://datastax.github.io/ruby-driver/api/types/)
114
103
 
115
104
  Breaking Changes:
116
105
 
117
106
  * Splat style positional arguments support, deprecated in 2.0.0, has been dropped
118
- * Setting `:synchronize_schema` to `true` will no longer perform the initial
119
- fetching if schema metadata.
120
107
 
121
108
  Bug Fixes:
122
109
 
123
110
  * [[RUBY-93](https://datastax-oss.atlassian.net/browse/RUBY-93)] Reconnection can overflow the stack
124
- * [[RUBY-95](https://datastax-oss.atlassian.net/browse/RUBY-95)] Speed up generation of large token maps
125
- * [[RUBY-97](https://datastax-oss.atlassian.net/browse/RUBY-97)] Allow disabling of the initial population of schema metadata
126
- * [[RUBY-98](https://datastax-oss.atlassian.net/browse/RUBY-98)] Use of undefined class variable in `Table#create_partition_key`
127
- * [[RUBY-102](https://datastax-oss.atlassian.net/browse/RUBY-102)] Allow custom types in schema metadata
128
- * [[RUBY-103](https://datastax-oss.atlassian.net/browse/RUBY-103)] Don't regenerate schema metadata for the same replication strategies and options
129
- * [[RUBY-116](https://datastax-oss.atlassian.net/browse/RUBY-116)] fix thread leak on connection error
130
- * [[RUBY-119](https://datastax-oss.atlassian.net/browse/RUBY-119)] Use `require 'datastax/cassandra'` to avoid namespace conflicts
131
- * [[RUBY-128](https://datastax-oss.atlassian.net/browse/RUBY-128)] Fix decoding of large values in maps, sets and lists.
132
- * [[RUBY-202](https://datastax-oss.atlassian.net/browse/RUBY-202)] Allow password authenticator to be used for LDAP authentication.
133
- * [[RUBY-255](https://datastax-oss.atlassian.net/browse/RUBY-255)] ControlConnection.peer_ip ignores peers that are missing critical information in system.peers.
134
111
 
135
112
  ## Code examples
136
113
 
@@ -169,10 +146,11 @@ Prereleases will be stable, in the sense that they will have finished and proper
169
146
 
170
147
  ## Known bugs & limitations
171
148
 
149
+ * JRuby 1.6 is not officially supported, although 1.6.8 should work, if you're stuck in JRuby 1.6.8 try and see if it works for you.
172
150
  * Because the driver reactor is using `IO.select`, the maximum number of tcp connections allowed is 1024.
173
151
  * Because the driver uses `IO#write_nonblock`, Windows is not supported.
174
152
 
175
- Please [refer to the usage documentation for more information on common pitfalls](http://docs.datastax.com/en/developer/ruby-driver/2.1/features/)
153
+ Please [refer to the usage documentation for more information on common pitfalls](http://datastax.github.io/ruby-driver/features/)
176
154
 
177
155
  ## Contributing
178
156
 
@@ -182,12 +160,12 @@ For contributing read [CONTRIBUTING.md](https://github.com/datastax/ruby-driver/
182
160
 
183
161
  This driver is based on the original work of [Theo Hultberg](https://github.com/iconara) on [cql-rb](https://github.com/iconara/cql-rb/) and adds a series of advanced features that are common across all other DataStax drivers for Apache Cassandra.
184
162
 
185
- The development effort to provide an up to date, high performance, fully featured Ruby Driver for Apache Cassandra will continue on this project, while [cql-rb](https://github.com/iconara/cql-rb/) has been discontinued.
163
+ The development effort to provide an up to date, high performance, fully featured Ruby Driver for Apache Cassandra will continue on this project, while [cql-rb](https://github.com/iconara/cql-rb/) will be discontinued.
186
164
 
187
165
 
188
166
  ## Copyright
189
167
 
190
- Copyright 2013-2016 DataStax, Inc.
168
+ Copyright 2013-2015 DataStax, Inc.
191
169
 
192
170
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
193
171
 
@@ -195,4 +173,4 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
195
173
 
196
174
  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
197
175
 
198
- [1]: http://docs.datastax.com/en/developer/ruby-driver/2.1/api
176
+ [1]: http://datastax.github.io/ruby-driver/api
data/lib/cassandra.rb CHANGED
@@ -31,6 +31,7 @@ require 'resolv'
31
31
  require 'openssl'
32
32
  require 'securerandom'
33
33
  require 'time'
34
+ require 'date'
34
35
 
35
36
  module Cassandra
36
37
  # A list of all supported request consistencies
@@ -59,7 +60,7 @@ module Cassandra
59
60
  #
60
61
  # @option options [Integer] :port (9042) cassandra native protocol port.
61
62
  #
62
- # @option options [Boolean] :nodelay (false) when set to `true`, disables
63
+ # @option options [Boolean] :nodelay (true) when set to `true`, disables
63
64
  # nagle algorithm.
64
65
  #
65
66
  # @option options [String] :datacenter (nil) name of current datacenter.
@@ -167,8 +168,8 @@ module Cassandra
167
168
  # initial listeners. A list of initial cluster state listeners. Note that a
168
169
  # `:load_balancing` policy is automatically registered with the cluster.
169
170
  #
170
- # @option options [Symbol] :consistency (:one) default consistency to use for
171
- # all requests. Must be one of {Cassandra::CONSISTENCIES}.
171
+ # @option options [Symbol] :consistency (:local_one) default consistency
172
+ # to use for all requests. Must be one of {Cassandra::CONSISTENCIES}.
172
173
  #
173
174
  # @option options [Boolean] :trace (false) whether or not to trace all
174
175
  # requests by default.
@@ -521,12 +522,27 @@ module Cassandra
521
522
 
522
523
  # @private
523
524
  EMPTY_LIST = [].freeze
525
+ # @private
526
+ NOT_SET = ::Object.new
527
+ # @private
528
+ NULL_BYTE = "\x00".freeze
529
+
530
+ # @private
531
+ # ensures that:
532
+ # ::Date.jd(DATE_OFFSET, ::Date::GREGORIAN)
533
+ # => -5877641-06-23
534
+ # ::Date.jd(DATE_OFFSET + 2 ** 31, ::Date::GREGORIAN)
535
+ # => 1970-1-1
536
+ # ::Date.jd(DATE_OFFSET + 2 ** 32, ::Date::GREGORIAN)
537
+ # => 5881580-07-12
538
+ DATE_OFFSET = (::Time.utc(1970, 1, 1).to_date.jd - 2 ** 31)
524
539
  end
525
540
 
526
541
  require 'cassandra/uuid'
527
542
  require 'cassandra/time_uuid'
528
543
  require 'cassandra/tuple'
529
544
  require 'cassandra/udt'
545
+ require 'cassandra/time'
530
546
 
531
547
  require 'cassandra/types'
532
548
 
@@ -546,6 +562,9 @@ require 'cassandra/result'
546
562
  require 'cassandra/statement'
547
563
  require 'cassandra/statements'
548
564
 
565
+ require 'cassandra/aggregate'
566
+ require 'cassandra/argument'
567
+ require 'cassandra/function'
549
568
  require 'cassandra/column'
550
569
  require 'cassandra/table'
551
570
  require 'cassandra/keyspace'
@@ -0,0 +1,109 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2015 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ module Cassandra
20
+ # Represents a cassandra user defined aggregate
21
+ # @see Cassandra::Keyspace#each_aggregate
22
+ # @see Cassandra::Keyspace#aggregate
23
+ # @see Cassandra::Keyspace#has_aggregate?
24
+ class Aggregate
25
+ # @private
26
+ attr_reader :keyspace
27
+ # @return [String] aggregate name
28
+ attr_reader :name
29
+ # @return [Cassandra::Type] aggregate return type
30
+ attr_reader :type
31
+ # @return [Array<Cassandra::Type>] aggregate argument types
32
+ attr_reader :argument_types
33
+ # @return [Cassandra::Type] aggregate state type
34
+ attr_reader :state_type
35
+ # @return [Object, nil] the initial value of the aggregate state or nil
36
+ attr_reader :initial_state
37
+ # @return [Cassandra::Function] the state function used by this aggregate
38
+ attr_reader :state_function
39
+ # @return [Cassandra::Function] the final function used by this aggregate
40
+ attr_reader :final_function
41
+
42
+ # @private
43
+ def initialize(keyspace, name, type, argument_types, state_type, initial_state, state_function, final_function)
44
+ @keyspace = keyspace
45
+ @name = name
46
+ @type = type
47
+ @argument_types = argument_types
48
+ @state_type = state_type
49
+ @initial_state = initial_state
50
+ @state_function = state_function
51
+ @final_function = final_function
52
+ end
53
+
54
+ # @private
55
+ def eql?(other)
56
+ other.is_a?(Aggregate) && \
57
+ @keyspace == other.keyspace && \
58
+ @name == other.name && \
59
+ @type == other.type && \
60
+ @argument_types == other.argument_types && \
61
+ @state_type == other.state_type && \
62
+ @initial_state == other.initial_state && \
63
+ @state_function == other.state_function && \
64
+ @final_function == other.final_function
65
+ end
66
+ alias :== :eql?
67
+
68
+ # @private
69
+ def hash
70
+ @hash ||= begin
71
+ h = 17
72
+ h = 31 * h + @keyspace.hash
73
+ h = 31 * h + @name.hash
74
+ h = 31 * h + @type.hash
75
+ h = 31 * h + @argument_types.hash
76
+ h = 31 * h + @state_type.hash
77
+ h = 31 * h + @initial_state.hash
78
+ h = 31 * h + @state_function.hash
79
+ h = 31 * h + @final_function.hash
80
+ h
81
+ end
82
+ end
83
+
84
+ # @private
85
+ def inspect
86
+ "#<Cassandra::Aggregate:0x#{self.object_id.to_s(16)} @keyspace=#{@keyspace.inspect}, @name=#{@name.inspect}, @type=#{@type.inspect}, @argument_types=#{@argument_types.inspect}, @initial_state=#{@initial_state.inspect}, @state_function=#{@state_function.inspect}, @final_function=#{@final_function.inspect}>"
87
+ end
88
+
89
+ # @return [String] a cql representation of this aggregate
90
+ def to_cql
91
+ cql = "CREATE AGGREGATE simplex.average("
92
+ first = true
93
+ @argument_types.each do |type|
94
+ if first
95
+ first = false
96
+ else
97
+ cql << ', '
98
+ end
99
+ cql << type.to_s
100
+ end
101
+ cql << ")"
102
+ cql << "\n SFUNC #{@state_function.name}"
103
+ cql << "\n STYPE #{@state_type}"
104
+ cql << "\n FINALFUNC #{@final_function.name}" if @final_function
105
+ cql << "\n INITCOND #{@initial_state}"
106
+ cql << ";"
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2015 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ module Cassandra
20
+ # Represents a function argument
21
+ class Argument
22
+ # @return [String] column name
23
+ attr_reader :name
24
+ # @return [Cassandra::Type] column type
25
+ attr_reader :type
26
+
27
+ # @private
28
+ def initialize(name, type)
29
+ @name = name
30
+ @type = type
31
+ end
32
+
33
+ # @private
34
+ def eql?(other)
35
+ other.is_a?(Argument) && \
36
+ @name == other.name && \
37
+ @type == other.type
38
+ end
39
+ alias :== :eql?
40
+
41
+ # @private
42
+ def hash
43
+ @hash ||= begin
44
+ h = 17
45
+ h = 31 * h + @name.hash
46
+ h = 31 * h + @type.hash
47
+ h
48
+ end
49
+ end
50
+ end
51
+ end
@@ -53,11 +53,14 @@ module Cassandra
53
53
  @password = password
54
54
  end
55
55
 
56
- # Returns a Password Authenticator
57
- # @param authentication_class [String] ignored
58
- # @return [Cassandra::Auth::Authenticator]
56
+ # Returns a Password Authenticator only if `org.apache.cassandra.auth.PasswordAuthenticator` is given.
57
+ # @param authentication_class [String] must equal to `org.apache.cassandra.auth.PasswordAuthenticator`
58
+ # @return [Cassandra::Auth::Authenticator] when `authentication_class == "org.apache.cassandra.auth.PasswordAuthenticator"`
59
+ # @return [nil] for all other values of `authentication_class`
59
60
  def create_authenticator(authentication_class)
60
- Authenticator.new(@username, @password)
61
+ if authentication_class == PASSWORD_AUTHENTICATOR_FQCN
62
+ Authenticator.new(@username, @password)
63
+ end
61
64
  end
62
65
 
63
66
  private
@@ -136,8 +136,19 @@ module Cassandra
136
136
  # Trigger an asynchronous schema metadata refresh
137
137
  # @return [Cassandra::Future<nil>] a future that will be fulfilled when
138
138
  # schema metadata has been refreshed
139
- def_delegator :@control_connection, :refresh_schema_async_maybe_retry, \
140
- :refresh_schema_async
139
+ def refresh_schema_async
140
+ promise = @futures.promise
141
+ @control_connection.send(:refresh_maybe_retry, :schema).on_complete do |f|
142
+ if f.resolved?
143
+ promise.fulfill(nil)
144
+ else
145
+ f.on_failure do |e|
146
+ promise.break(e)
147
+ end
148
+ end
149
+ end
150
+ promise.future
151
+ end
141
152
 
142
153
  # Synchronously refresh schema metadata
143
154
  #
@@ -233,7 +244,7 @@ module Cassandra
233
244
  close_async.get
234
245
  end
235
246
 
236
- # @return [String] a CLI-friendly cluster representation
247
+ # @private
237
248
  def inspect
238
249
  "#<#{self.class.name}:0x#{self.object_id.to_s(16)}>"
239
250
  end