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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +106 -39
  3. data/lib/cassandra.rb +396 -148
  4. data/lib/cassandra/address_resolution.rb +1 -1
  5. data/lib/cassandra/address_resolution/policies/ec2_multi_region.rb +1 -1
  6. data/lib/cassandra/address_resolution/policies/none.rb +1 -1
  7. data/lib/cassandra/aggregate.rb +21 -7
  8. data/lib/cassandra/argument.rb +2 -2
  9. data/lib/cassandra/attr_boolean.rb +33 -0
  10. data/lib/cassandra/auth.rb +6 -5
  11. data/lib/cassandra/auth/providers.rb +1 -1
  12. data/lib/cassandra/auth/providers/password.rb +5 -13
  13. data/lib/cassandra/cassandra_logger.rb +80 -0
  14. data/lib/cassandra/cluster.rb +49 -9
  15. data/lib/cassandra/cluster/client.rb +835 -209
  16. data/lib/cassandra/cluster/connection_pool.rb +2 -2
  17. data/lib/cassandra/cluster/connector.rb +86 -27
  18. data/lib/cassandra/cluster/control_connection.rb +222 -95
  19. data/lib/cassandra/cluster/failed_connection.rb +1 -1
  20. data/lib/cassandra/cluster/metadata.rb +14 -8
  21. data/lib/cassandra/cluster/options.rb +68 -22
  22. data/lib/cassandra/cluster/registry.rb +81 -17
  23. data/lib/cassandra/cluster/schema.rb +70 -8
  24. data/lib/cassandra/cluster/schema/cql_type_parser.rb +15 -10
  25. data/lib/cassandra/cluster/schema/fetchers.rb +601 -241
  26. data/lib/cassandra/cluster/schema/fqcn_type_parser.rb +39 -38
  27. data/lib/cassandra/cluster/schema/partitioners.rb +1 -1
  28. data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +6 -8
  29. data/lib/cassandra/cluster/schema/partitioners/ordered.rb +1 -1
  30. data/lib/cassandra/cluster/schema/partitioners/random.rb +1 -1
  31. data/lib/cassandra/cluster/schema/replication_strategies.rb +1 -1
  32. data/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +19 -18
  33. data/lib/cassandra/cluster/schema/replication_strategies/none.rb +1 -1
  34. data/lib/cassandra/cluster/schema/replication_strategies/simple.rb +1 -1
  35. data/lib/cassandra/column.rb +4 -23
  36. data/lib/cassandra/column_container.rb +322 -0
  37. data/lib/cassandra/compression.rb +1 -1
  38. data/lib/cassandra/compression/compressors/lz4.rb +7 -8
  39. data/lib/cassandra/compression/compressors/snappy.rb +4 -3
  40. data/lib/cassandra/driver.rb +107 -46
  41. data/lib/cassandra/errors.rb +303 -52
  42. data/lib/cassandra/execution/info.rb +16 -5
  43. data/lib/cassandra/execution/options.rb +102 -55
  44. data/lib/cassandra/execution/trace.rb +16 -9
  45. data/lib/cassandra/executors.rb +1 -1
  46. data/lib/cassandra/function.rb +19 -13
  47. data/lib/cassandra/function_collection.rb +85 -0
  48. data/lib/cassandra/future.rb +101 -49
  49. data/lib/cassandra/host.rb +25 -5
  50. data/lib/cassandra/index.rb +118 -0
  51. data/lib/cassandra/keyspace.rb +169 -33
  52. data/lib/cassandra/listener.rb +1 -1
  53. data/lib/cassandra/load_balancing.rb +2 -2
  54. data/lib/cassandra/load_balancing/policies.rb +1 -1
  55. data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +39 -25
  56. data/lib/cassandra/load_balancing/policies/round_robin.rb +8 -1
  57. data/lib/cassandra/load_balancing/policies/token_aware.rb +22 -13
  58. data/lib/cassandra/load_balancing/policies/white_list.rb +18 -5
  59. data/lib/cassandra/materialized_view.rb +90 -0
  60. data/lib/cassandra/null_logger.rb +27 -6
  61. data/lib/cassandra/protocol.rb +1 -1
  62. data/lib/cassandra/protocol/coder.rb +81 -42
  63. data/lib/cassandra/protocol/cql_byte_buffer.rb +58 -44
  64. data/lib/cassandra/protocol/cql_protocol_handler.rb +57 -54
  65. data/lib/cassandra/protocol/request.rb +6 -7
  66. data/lib/cassandra/protocol/requests/auth_response_request.rb +3 -3
  67. data/lib/cassandra/protocol/requests/batch_request.rb +17 -8
  68. data/lib/cassandra/protocol/requests/credentials_request.rb +3 -3
  69. data/lib/cassandra/protocol/requests/execute_request.rb +39 -20
  70. data/lib/cassandra/protocol/requests/options_request.rb +1 -1
  71. data/lib/cassandra/protocol/requests/prepare_request.rb +5 -5
  72. data/lib/cassandra/protocol/requests/query_request.rb +28 -23
  73. data/lib/cassandra/protocol/requests/register_request.rb +2 -2
  74. data/lib/cassandra/protocol/requests/startup_request.rb +8 -8
  75. data/lib/cassandra/protocol/requests/void_query_request.rb +1 -1
  76. data/lib/cassandra/protocol/response.rb +3 -4
  77. data/lib/cassandra/protocol/responses/already_exists_error_response.rb +12 -2
  78. data/lib/cassandra/protocol/responses/auth_challenge_response.rb +4 -5
  79. data/lib/cassandra/protocol/responses/auth_success_response.rb +4 -5
  80. data/lib/cassandra/protocol/responses/authenticate_response.rb +4 -5
  81. data/lib/cassandra/protocol/responses/error_response.rb +104 -17
  82. data/lib/cassandra/protocol/responses/event_response.rb +3 -4
  83. data/lib/cassandra/protocol/responses/function_failure_error_response.rb +13 -2
  84. data/lib/cassandra/protocol/responses/prepared_result_response.rb +14 -9
  85. data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +14 -9
  86. data/lib/cassandra/protocol/responses/read_failure_error_response.rb +26 -4
  87. data/lib/cassandra/protocol/responses/read_timeout_error_response.rb +22 -3
  88. data/lib/cassandra/protocol/responses/ready_response.rb +6 -7
  89. data/lib/cassandra/protocol/responses/result_response.rb +11 -10
  90. data/lib/cassandra/protocol/responses/rows_result_response.rb +8 -7
  91. data/lib/cassandra/protocol/responses/schema_change_event_response.rb +8 -8
  92. data/lib/cassandra/protocol/responses/schema_change_result_response.rb +19 -13
  93. data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +5 -6
  94. data/lib/cassandra/protocol/responses/status_change_event_response.rb +5 -6
  95. data/lib/cassandra/protocol/responses/supported_response.rb +4 -5
  96. data/lib/cassandra/protocol/responses/topology_change_event_response.rb +4 -5
  97. data/lib/cassandra/protocol/responses/unavailable_error_response.rb +20 -3
  98. data/lib/cassandra/protocol/responses/unprepared_error_response.rb +11 -2
  99. data/lib/cassandra/protocol/responses/void_result_response.rb +4 -5
  100. data/lib/cassandra/protocol/responses/write_failure_error_response.rb +26 -4
  101. data/lib/cassandra/protocol/responses/write_timeout_error_response.rb +22 -3
  102. data/lib/cassandra/protocol/v1.rb +98 -37
  103. data/lib/cassandra/protocol/v3.rb +121 -50
  104. data/lib/cassandra/protocol/v4.rb +172 -68
  105. data/lib/cassandra/reconnection.rb +1 -1
  106. data/lib/cassandra/reconnection/policies.rb +1 -1
  107. data/lib/cassandra/reconnection/policies/constant.rb +2 -4
  108. data/lib/cassandra/reconnection/policies/exponential.rb +6 -6
  109. data/lib/cassandra/result.rb +55 -20
  110. data/lib/cassandra/retry.rb +8 -8
  111. data/lib/cassandra/retry/policies.rb +1 -1
  112. data/lib/cassandra/retry/policies/default.rb +1 -1
  113. data/lib/cassandra/retry/policies/downgrading_consistency.rb +4 -2
  114. data/lib/cassandra/retry/policies/fallthrough.rb +1 -1
  115. data/lib/cassandra/session.rb +24 -16
  116. data/lib/cassandra/statement.rb +1 -1
  117. data/lib/cassandra/statements.rb +1 -1
  118. data/lib/cassandra/statements/batch.rb +16 -10
  119. data/lib/cassandra/statements/bound.rb +10 -3
  120. data/lib/cassandra/statements/prepared.rb +62 -18
  121. data/lib/cassandra/statements/simple.rb +23 -10
  122. data/lib/cassandra/statements/void.rb +1 -1
  123. data/lib/cassandra/table.rb +53 -185
  124. data/lib/cassandra/time.rb +11 -6
  125. data/lib/cassandra/time_uuid.rb +12 -14
  126. data/lib/cassandra/timestamp_generator.rb +37 -0
  127. data/lib/cassandra/timestamp_generator/simple.rb +38 -0
  128. data/lib/cassandra/timestamp_generator/ticking_on_duplicate.rb +58 -0
  129. data/lib/cassandra/tuple.rb +4 -4
  130. data/lib/cassandra/types.rb +109 -71
  131. data/lib/cassandra/udt.rb +66 -50
  132. data/lib/cassandra/util.rb +155 -15
  133. data/lib/cassandra/uuid.rb +20 -21
  134. data/lib/cassandra/uuid/generator.rb +7 -5
  135. data/lib/cassandra/version.rb +2 -2
  136. data/lib/cassandra_murmur3.jar +0 -0
  137. data/lib/datastax/cassandra.rb +1 -1
  138. metadata +27 -16
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -48,21 +48,27 @@ module Cassandra
48
48
  #
49
49
  # @raise [ArgumentError] if cql statement given is not a String
50
50
  def initialize(cql, params = nil, type_hints = nil, idempotent = false)
51
- Util.assert_instance_of(::String, cql) { "cql must be a string, #{cql.inspect} given" }
51
+ Util.assert_instance_of(::String, cql) do
52
+ "cql must be a string, #{cql.inspect} given"
53
+ end
52
54
 
53
55
  params ||= EMPTY_LIST
54
56
 
55
57
  if params.is_a?(::Hash)
56
58
  params_names = []
57
- params = params.each_with_object([]) do |(name, value), params|
59
+ params = params.each_with_object([]) do |(name, value), collector|
58
60
  params_names << name
59
- params << value
61
+ collector << value
60
62
  end
61
63
  if type_hints && !type_hints.empty?
62
- Util.assert_instance_of(::Hash, type_hints) { "type_hints must be a Hash when using named params" }
64
+ Util.assert_instance_of(::Hash, type_hints) do
65
+ 'type_hints must be a Hash when using named params'
66
+ end
63
67
  end
64
68
  else
65
- Util.assert_instance_of(::Array, params) { "params must be an Array or a Hash, #{params.inspect} given" }
69
+ Util.assert_instance_of(::Array, params) do
70
+ "params must be an Array or a Hash, #{params.inspect} given"
71
+ end
66
72
  params_names = EMPTY_LIST
67
73
  end
68
74
 
@@ -71,19 +77,26 @@ module Cassandra
71
77
  if type_hints.is_a?(::Hash)
72
78
  type_hints = params_names.map {|name| type_hints[name] }
73
79
  else
74
- Util.assert_instance_of(::Array, type_hints) { "type_hints must be an Array or a Hash, #{type_hints.inspect} given" }
80
+ Util.assert_instance_of(::Array, type_hints) do
81
+ "type_hints must be an Array or a Hash, #{type_hints.inspect} given"
82
+ end
75
83
  end
76
84
 
77
85
  @cql = cql
78
86
  @params = params
79
- @params_types = params.each_with_index.map {|value, index| (!type_hints.empty? && type_hints[index] && type_hints[index].is_a?(Type)) ? type_hints[index] : Util.guess_type(value)}
87
+ @params_types = params.each_with_index.map do |value, index|
88
+ (!type_hints.empty? && type_hints[index] && type_hints[index].is_a?(Type)) ?
89
+ type_hints[index] :
90
+ Util.guess_type(value)
91
+ end
80
92
  @params_names = params_names
81
93
  @idempotent = idempotent
82
94
  end
83
95
 
84
96
  # @return [String] a CLI-friendly simple statement representation
85
97
  def inspect
86
- "#<#{self.class.name}:0x#{self.object_id.to_s(16)} @cql=#{@cql.inspect} @params=#{@params.inspect}>"
98
+ "#<#{self.class.name}:0x#{object_id.to_s(16)} @cql=#{@cql.inspect} " \
99
+ "@params=#{@params.inspect}>"
87
100
  end
88
101
 
89
102
  # @param other [Object, Cassandra::Statements::Simple] object to compare
@@ -94,7 +107,7 @@ module Cassandra
94
107
  @params == other.params
95
108
  end
96
109
 
97
- alias :== :eql?
110
+ alias == eql?
98
111
  end
99
112
  end
100
113
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -20,193 +20,74 @@ module Cassandra
20
20
  # Represents a cassandra table
21
21
  # @see Cassandra::Keyspace#each_table
22
22
  # @see Cassandra::Keyspace#table
23
- class Table
24
- # @private
25
- class Options
26
- attr_reader :comment, :read_repair_chance, :local_read_repair_chance,
27
- :gc_grace_seconds, :caching, :bloom_filter_fp_chance,
28
- :populate_io_cache_on_flush, :memtable_flush_period_in_ms,
29
- :default_time_to_live, :speculative_retry, :index_interval,
30
- :replicate_on_write, :compaction_strategy, :compact_storage,
31
- :compression_parameters
32
-
33
- def initialize(comment, read_repair_chance, local_read_repair_chance,
34
- gc_grace_seconds, caching, bloom_filter_fp_chance,
35
- populate_io_cache_on_flush, memtable_flush_period_in_ms,
36
- default_time_to_live, speculative_retry, index_interval,
37
- replicate_on_write, min_index_interval, max_index_interval,
38
- compaction_strategy, compression_parameters, compact_storage)
39
- @comment = comment
40
- @read_repair_chance = read_repair_chance
41
- @local_read_repair_chance = local_read_repair_chance
42
- @gc_grace_seconds = gc_grace_seconds
43
- @caching = caching
44
- @bloom_filter_fp_chance = bloom_filter_fp_chance
45
- @populate_io_cache_on_flush = populate_io_cache_on_flush
46
- @memtable_flush_period_in_ms = memtable_flush_period_in_ms
47
- @default_time_to_live = default_time_to_live
48
- @speculative_retry = speculative_retry
49
- @index_interval = index_interval
50
- @replicate_on_write = replicate_on_write
51
- @min_index_interval = min_index_interval
52
- @max_index_interval = max_index_interval
53
- @compaction_strategy = compaction_strategy
54
- @compression_parameters = compression_parameters
55
- @compact_storage = compact_storage
56
- end
57
-
58
- def replicate_on_write?
59
- @replicate_on_write
60
- end
61
-
62
- def populate_io_cache_on_flush?
63
- @populate_io_cache_on_flush
64
- end
65
-
66
- def compact_storage?
67
- @compact_storage
68
- end
69
-
70
- def to_cql
71
- options = []
72
-
73
- options << 'COMPACT STORAGE' if @compact_storage
74
- options << "bloom_filter_fp_chance = #{Util.encode_object(@bloom_filter_fp_chance)}" unless @bloom_filter_fp_chance.nil?
75
- options << "caching = #{Util.encode_object(@caching)}" unless @caching.nil?
76
- options << "comment = #{Util.encode_object(@comment)}" unless @comment.nil?
77
- options << "compaction = #{@compaction_strategy.to_cql}" unless @compaction_strategy.nil?
78
- options << "compression = #{Util.encode_object(@compression_parameters)}" unless @compression_parameters.nil?
79
- options << "dclocal_read_repair_chance = #{Util.encode_object(@local_read_repair_chance)}" unless @local_read_repair_chance.nil?
80
- options << "default_time_to_live = #{Util.encode_object(@default_time_to_live)}" unless @default_time_to_live.nil?
81
- options << "gc_grace_seconds = #{Util.encode_object(@gc_grace_seconds)}" unless @gc_grace_seconds.nil?
82
- options << "index_interval = #{Util.encode_object(@index_interval)}" unless @index_interval.nil?
83
- options << "max_index_interval = #{Util.encode_object(@max_index_interval)}" unless @max_index_interval.nil?
84
- options << "memtable_flush_period_in_ms = #{Util.encode_object(@memtable_flush_period_in_ms)}" unless @memtable_flush_period_in_ms.nil?
85
- options << "min_index_interval = #{Util.encode_object(@min_index_interval)}" unless @min_index_interval.nil?
86
- options << "populate_io_cache_on_flush = '#{@populate_io_cache_on_flush}'" unless @populate_io_cache_on_flush.nil?
87
- options << "read_repair_chance = #{Util.encode_object(@read_repair_chance)}" unless @read_repair_chance.nil?
88
- options << "replicate_on_write = '#{@replicate_on_write}'" unless @replicate_on_write.nil?
89
- options << "speculative_retry = #{Util.encode_object(@speculative_retry)}" unless @speculative_retry.nil?
90
-
91
- options.join("\nAND ")
92
- end
93
-
94
- def eql?(other)
95
- other.is_a?(Options) &&
96
- @comment == other.comment &&
97
- @read_repair_chance == other.read_repair_chance &&
98
- @local_read_repair_chance == other.local_read_repair_chance &&
99
- @gc_grace_seconds == other.gc_grace_seconds &&
100
- @caching == other.caching &&
101
- @bloom_filter_fp_chance == other.bloom_filter_fp_chance &&
102
- @populate_io_cache_on_flush == other.populate_io_cache_on_flush &&
103
- @memtable_flush_period_in_ms == other.memtable_flush_period_in_ms &&
104
- @default_time_to_live == other.default_time_to_live &&
105
- @speculative_retry == other.speculative_retry &&
106
- @index_interval == other.index_interval &&
107
- @replicate_on_write == other.replicate_on_write &&
108
- @compaction_strategy == other.compaction_strategy &&
109
- @compression_parameters == other.compression_parameters &&
110
- @compact_storage == other.compact_storage
111
- end
112
- alias :== :eql?
113
- end
114
-
115
- # @private
116
- class Compaction
117
- attr_reader :klass, :options
23
+ class Table < ColumnContainer
24
+ # @return [Array<Symbol>] an array of order values (`:asc` or `:desc`) that apply to the
25
+ # `clustering_columns` array.
26
+ attr_reader :clustering_order
118
27
 
119
- def initialize(klass, options)
120
- @klass = klass
121
- @options = options
122
- end
123
-
124
- def to_cql
125
- compaction = {'class' => @klass}
126
- compaction.merge!(@options)
127
-
128
- Util.encode_hash(compaction)
129
- end
130
-
131
- def eql?(other)
132
- other.is_a?(Compaction) &&
133
- @klass == other.klass &&
134
- @options == other.options
135
- end
136
- alias :== :eql?
137
- end
138
-
139
- # @private
140
- attr_reader :keyspace
141
- # @return [String] table name
142
- attr_reader :name
143
28
  # @private
144
- attr_reader :options
145
- # @private
146
- attr_reader :partition_key
147
-
148
- # @private
149
- def initialize(keyspace, name, partition_key, clustering_columns, columns, options, clustering_order)
150
- @keyspace = keyspace
151
- @name = name
152
- @partition_key = partition_key
153
- @clustering_columns = clustering_columns
154
- @columns = columns
155
- @options = options
156
- @clustering_order = clustering_order
29
+ def initialize(keyspace,
30
+ name,
31
+ partition_key,
32
+ clustering_columns,
33
+ other_columns,
34
+ options,
35
+ clustering_order,
36
+ id)
37
+ super(keyspace, name, partition_key, clustering_columns, other_columns, options, id)
38
+ @clustering_order = clustering_order.freeze
39
+ @indexes = []
40
+ @indexes_hash = {}
157
41
  end
158
42
 
159
- # @param name [String] column name
160
- # @return [Boolean] whether this table has a given column
161
- def has_column?(name)
162
- @columns.has_key?(name)
43
+ # @param name [String] index name
44
+ # @return [Boolean] whether this table has a given index
45
+ def has_index?(name)
46
+ @indexes_hash.key?(name)
163
47
  end
164
48
 
165
- # @param name [String] column name
166
- # @return [Cassandra::Column, nil] a column or nil
167
- def column(name)
168
- @columns[name]
49
+ # @param name [String] index name
50
+ # @return [Cassandra::Index, nil] an index or nil
51
+ def index(name)
52
+ @indexes_hash[name]
169
53
  end
170
54
 
171
- # Yield or enumerate each column defined in this table
172
- # @overload each_column
173
- # @yieldparam column [Cassandra::Column] current column
55
+ # Yield or enumerate each index bound to this table
56
+ # @overload each_index
57
+ # @yieldparam index [Cassandra::Index] current index
174
58
  # @return [Cassandra::Table] self
175
- # @overload each_column
176
- # @return [Array<Cassandra::Column>] a list of columns
177
- def each_column(&block)
59
+ # @overload each_index
60
+ # @return [Array<Cassandra::Index>] a list of indexes
61
+ def each_index(&block)
178
62
  if block_given?
179
- @columns.each_value(&block)
63
+ @indexes.each(&block)
180
64
  self
181
65
  else
182
- @columns.values
66
+ @indexes.freeze
183
67
  end
184
68
  end
185
- alias :columns :each_column
69
+ alias indexes each_index
186
70
 
187
71
  # @return [String] a cql representation of this table
188
72
  def to_cql
189
- cql = "CREATE TABLE #{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)} (\n"
190
- primary_key = nil
191
- if @partition_key.one? && @clustering_columns.empty?
192
- primary_key = @partition_key.first.name
193
- end
73
+ cql = "CREATE TABLE #{Util.escape_name(@keyspace.name)}.#{Util.escape_name(@name)} (\n"
74
+ primary_key = @partition_key.first.name if @partition_key.one? && @clustering_columns.empty?
194
75
 
195
76
  first = true
196
- @columns.each do |(_, column)|
77
+ @columns.each do |column|
197
78
  if first
198
79
  first = false
199
80
  else
200
- cql << ",\n" unless first
81
+ cql << ",\n"
201
82
  end
202
- cql << " #{column.name} #{type_to_cql(column.type, column.frozen?)}"
83
+ cql << " #{Util.escape_name(column.name)} #{type_to_cql(column.type, column.frozen?)}"
203
84
  cql << ' PRIMARY KEY' if primary_key && column.name == primary_key
204
85
  end
205
86
 
206
87
  unless primary_key
207
88
  cql << ",\n PRIMARY KEY ("
208
89
  if @partition_key.one?
209
- cql << @partition_key.first.name
90
+ cql << Util.escape_name(@partition_key.first.name)
210
91
  else
211
92
  cql << '('
212
93
  first = true
@@ -216,12 +97,12 @@ module Cassandra
216
97
  else
217
98
  cql << ', '
218
99
  end
219
- cql << column.name
100
+ cql << Util.escape_name(column.name)
220
101
  end
221
102
  cql << ')'
222
103
  end
223
104
  @clustering_columns.each do |column|
224
- cql << ", #{column.name}"
105
+ cql << ", #{Util.escape_name(column.name)}"
225
106
  end
226
107
  cql << ')'
227
108
  end
@@ -229,7 +110,7 @@ module Cassandra
229
110
  cql << "\n)\nWITH "
230
111
 
231
112
  if @clustering_order.any? {|o| o != :asc}
232
- cql << "CLUSTERING ORDER BY ("
113
+ cql << 'CLUSTERING ORDER BY ('
233
114
  first = true
234
115
  @clustering_columns.zip(@clustering_order) do |column, order|
235
116
  if first
@@ -237,7 +118,7 @@ module Cassandra
237
118
  else
238
119
  cql << ', '
239
120
  end
240
- cql << "#{column.name} #{order.to_s.upcase}"
121
+ cql << "#{Util.escape_name(column.name)} #{order.to_s.upcase}"
241
122
  end
242
123
  cql << ")\n AND "
243
124
  end
@@ -248,22 +129,19 @@ module Cassandra
248
129
  end
249
130
 
250
131
  # @private
251
- def inspect
252
- "#<#{self.class.name}:0x#{self.object_id.to_s(16)} @keyspace=#{@keyspace} @name=#{@name}>"
132
+ def add_index(index)
133
+ @indexes << index
134
+ @indexes_hash[index.name] = index
253
135
  end
254
136
 
255
137
  # @private
256
138
  def eql?(other)
257
139
  other.is_a?(Table) &&
258
- @keyspace == other.keyspace &&
259
- @name == other.name &&
260
- @partition_key == other.partition_key &&
261
- @clustering_columns == other.clustering_columns &&
262
- @columns == other.raw_columns &&
263
- @options == other.options &&
264
- @clustering_order == other.clustering_order
140
+ super.eql?(other) &&
141
+ @clustering_order == other.clustering_order &&
142
+ @indexes == other.indexes
265
143
  end
266
- alias :== :eql?
144
+ alias == eql?
267
145
 
268
146
  private
269
147
 
@@ -273,7 +151,7 @@ module Cassandra
273
151
  when :tuple
274
152
  "frozen <#{type}>"
275
153
  when :udt
276
- if @keyspace == type.keyspace
154
+ if @keyspace.name == type.keyspace
277
155
  "frozen <#{Util.escape_name(type.name)}>"
278
156
  else
279
157
  "frozen <#{Util.escape_name(type.keyspace)}.#{Util.escape_name(type.name)}>"
@@ -282,19 +160,9 @@ module Cassandra
282
160
  if is_frozen
283
161
  "frozen <#{type}>"
284
162
  else
285
- "#{type}"
163
+ type.to_s
286
164
  end
287
165
  end
288
166
  end
289
-
290
- attr_reader :clustering_columns, :clustering_order
291
- protected :clustering_columns, :clustering_order
292
-
293
- protected
294
-
295
- # @private
296
- def raw_columns
297
- @columns
298
- end
299
167
  end
300
168
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -35,7 +35,7 @@ module Cassandra
35
35
  # @private
36
36
  def initialize(nanoseconds = 0)
37
37
  if nanoseconds < 0 && nanoseconds > NANOSECONDS_IN_DAY - 1
38
- raise ::ArgumentError, "value must be between 0 and " \
38
+ raise ::ArgumentError, 'value must be between 0 and ' \
39
39
  "#{NANOSECONDS_IN_DAY}, #{value.inspect} given"
40
40
  end
41
41
 
@@ -57,18 +57,23 @@ module Cassandra
57
57
  # @return [Integer] an integer between 0 and 60, the number of full seconds
58
58
  # since the last full minutes that this time represents
59
59
  def seconds
60
- (@nanoseconds - (hours * NANOSECONDS_IN_HOUR) - (minutes * NANOSECONDS_IN_MINUTE)) / NANOSECONDS_IN_SECOND
60
+ (@nanoseconds -
61
+ (hours * NANOSECONDS_IN_HOUR) -
62
+ (minutes * NANOSECONDS_IN_MINUTE)) / NANOSECONDS_IN_SECOND
61
63
  end
62
64
 
63
65
  # @return [Integer] an integer between 0 and 60, the number of full
64
66
  # miliseconds since the last full second that this time represents
65
67
  def miliseconds
66
- (@nanoseconds - (hours * NANOSECONDS_IN_HOUR) - (minutes * NANOSECONDS_IN_MINUTE) - (seconds * NANOSECONDS_IN_SECOND)) / NANOSECONDS_IN_MILISECOND
68
+ (@nanoseconds -
69
+ (hours * NANOSECONDS_IN_HOUR) -
70
+ (minutes * NANOSECONDS_IN_MINUTE) -
71
+ (seconds * NANOSECONDS_IN_SECOND)) / NANOSECONDS_IN_MILISECOND
67
72
  end
68
73
 
69
74
  # @return [String] a "%H:%M%S.%3N" formatted time string
70
75
  def to_s
71
- '%.2d:%.2d:%.2d.%.3d' % [hours, minutes, seconds, miliseconds]
76
+ format('%.2d:%.2d:%.2d.%.3d', hours, minutes, seconds, miliseconds)
72
77
  end
73
78
 
74
79
  # @return [Integer] an integer between 0 and 86400000000000, the number of
@@ -81,7 +86,7 @@ module Cassandra
81
86
  def eql?(other)
82
87
  other.is_a?(Time) && other.to_nanoseconds == @nanoseconds
83
88
  end
84
- alias :== :eql?
89
+ alias == eql?
85
90
 
86
91
  # @private
87
92
  def <=>(other)