Class: TableStoreClient
- Inherits:
-
Object
- Object
- TableStoreClient
- Defined in:
- lib/tablestore/table_store_client.rb
Instance Method Summary collapse
- #decode_batch_get_row(body) ⇒ Object
- #decode_get_range_request(api_name, headers, body) ⇒ Object
- #decode_get_row(body) ⇒ Object
- #decode_put_row(body) ⇒ Object
- #encode_get_range_request(request) ⇒ Object
- #encode_get_row(table_name, primary_key, columns_to_get, column_filter, max_version) ⇒ Object
- #encode_put_row(table_name, row, condition) ⇒ Object
- #encode_update_row(teble_name, row, condition) ⇒ Object
- #make_batch_get_row(request) ⇒ Object
- #make_batch_write_row(request) ⇒ Object
- #make_column_condition(column_condition) ⇒ Object
- #make_composite_condition(condition) ⇒ Object
- #make_condition(proto, condition) ⇒ Object
- #make_put_row_item(proto, put_row_item) ⇒ Object
- #make_relation_condition(condition) ⇒ Object
- #make_repeated_column_names(proto, columns_to_get) ⇒ Object
- #make_update_row_item(proto, update_row_item) ⇒ Object
- #parse_batch_write_row(proto) ⇒ Object
- #parse_get_row_item(proto) ⇒ Object
- #parse_write_row_item(row_item) ⇒ Object
Instance Method Details
#decode_batch_get_row(body) ⇒ Object
149 150 151 152 153 154 155 156 157 |
# File 'lib/tablestore/table_store_client.rb', line 149 def decode_batch_get_row(body) proto = BatchGetRowResponse.new proto.parse_from_string(body) rows = [] proto.tables.each do |table_item| rows << parse_get_row_item(table_item.rows) end rows end |
#decode_get_range_request(api_name, headers, body) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tablestore/table_store_client.rb', line 22 def decode_get_range_request(api_name, headers, body) proto = GetRangeResponse.new proto.parse_from_string(body) #capacity_unit = parse_capacity_unit(proto.consumed.capacity_unit) next_start_pk = nil row_list = [] # if proto.next_start_primary_key.length != 0 # inputStream = PlainBufferInputStream.new(proto.next_start_primary_key) # codedInputStream = PlainBufferCodedInputStream.new(inputStream) # next_start_pk, att = codedInputStream.read_row # end if proto.rows.length != 0 inputStream = PlainBufferInputStream.new(proto.rows) codedInputStream = PlainBufferCodedInputStream.new(inputStream) row_list = codedInputStream.read_rows end #next_token = proto.next_token row_list #return capacity_unit, next_start_pk, row_list, next_token end |
#decode_get_row(body) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/tablestore/table_store_client.rb', line 81 def decode_get_row(body) proto = GetRowResponse.new proto.parse_from_string(body) return_row = nil if proto.row.length > 0 inputStream = PlainBufferInputStream.new(proto.row) codedInputStream = PlainBufferCodedInputStream.new(inputStream) return_row = codedInputStream.read_row end return_row end |
#decode_put_row(body) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/tablestore/table_store_client.rb', line 94 def decode_put_row(body) proto = PutRowResponse.new proto.parse_from_string(body) return_row = nil if proto.row.length != 0 inputStream = PlainBufferInputStream.new(proto.row) codedInputStream = PlainBufferCodedInputStream.new(inputStream) return_row = codedInputStream.read_row end return_row end |
#encode_get_range_request(request) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/tablestore/table_store_client.rb', line 11 def encode_get_range_request(request) proto = GetRangeRequest.new proto.table_name = request[:table_name] proto.direction = request[:direction] proto.inclusive_start_primary_key = serialize_primary_key(request[:inclusive_start_primary_key]) proto.exclusive_end_primary_key = serialize_primary_key(request[:exclusive_end_primary_key]) proto.max_versions = request[:max_version] proto.limit = request[:limit] proto.serialize_to_string end |
#encode_get_row(table_name, primary_key, columns_to_get, column_filter, max_version) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/tablestore/table_store_client.rb', line 57 def encode_get_row(table_name, primary_key, columns_to_get, column_filter, max_version) proto = GetRowRequest.new proto.table_name = table_name make_repeated_column_names(proto.columns_to_get, columns_to_get) if column_filter proto.filter = make_column_condition(column_filter).serialize_to_string end proto.primary_key = serialize_primary_key(primary_key) proto.max_versions = max_version if max_version proto.serialize_to_string end |
#encode_put_row(table_name, row, condition) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/tablestore/table_store_client.rb', line 47 def encode_put_row(table_name, row, condition) proto = PutRowRequest.new proto.table_name = table_name condition = Condition.new(RowExistenceExpectation::IGNORE) if condition.nil? contion_proto = Condition.new proto.condition = make_condition(contion_proto, condition) proto.row = serialize_for_put_row(row.primary_key, row.attribute_columns) proto.serialize_to_string end |
#encode_update_row(teble_name, row, condition) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/tablestore/table_store_client.rb', line 69 def encode_update_row(teble_name, row, condition) proto = UpdateRowRequest.new proto.table_name = table_name condition = Condition.new(RowExistenceExpectation::IGNORE) if condition.nil? proto.condition = condition if return_type == ReturnType::RT_PK proto.return_content.return_type = RT_PK end proto.row_change = serialize_for_update_row(row.primary_key, row.attribute_columns) proto end |
#make_batch_get_row(request) ⇒ Object
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 |
# File 'lib/tablestore/table_store_client.rb', line 106 def make_batch_get_row(request) proto = BatchGetRowRequest.new request.items.each do |item| table_value = item[1] table_item = TableInBatchGetRowRequest.new table_item.table_name = table_value.table_name make_repeated_column_names(table_item.columns_to_get, table_value.columns_to_get) if table_value.column_filter table_item.filter = make_column_condition(table_value.column_filter).serialize_to_string end table_value.primary_keys.each do |pk| table_item.primary_key << serialize_primary_key(pk) end if table_value.token table_value.token.each do |tk| table_item.token << tk end end if table_value.max_version table_item.max_versions = table_value.max_version end if table_value.time_range if table_value.time_range.is_a?(Array) table_item.time_range.start_time = table_value.time_range[0] table_item.time_range.end_time = table_value.time_range[1] elsif table_value.is_a?(Fixnum) table_item.time_range.specific_time = table_value.time_range end end if table_value.start_column table_item.start_column = table_value.start_column end if table_value.end_column table_item.end_column = table_value.end_column end proto.tables << table_item end proto.serialize_to_string end |
#make_batch_write_row(request) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/tablestore/table_store_client.rb', line 159 def make_batch_write_row(request) proto = BatchWriteRowRequest.new request.items.each do |item| table_value = item[1] table_item = TableInBatchWriteRowRequest.new table_item.table_name = table_value.table_name table_value.row_items.each do |row_item| if row_item.type == Metadata::BatchWriteRowType::PUT row = RowInBatchWriteRowRequest.new table_item.rows << make_put_row_item(row, row_item) end if row_item.type == Metadata::BatchWriteRowType::UPDATE row = RowInBatchWriteRowRequest.new table_item.rows << make_update_row_item(row, row_item) end end proto.tables << table_item end proto.serialize_to_string end |
#make_column_condition(column_condition) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/tablestore/table_store_client.rb', line 236 def make_column_condition(column_condition) return if column_condition.nil? proto = Filter.new proto.type = column_condition.get_type # condition if column_condition.is_a?(Metadata::CompositeColumnCondition) proto.filter = make_composite_condition(column_condition) elsif column_condition.is_a?(Metadata::SingleColumnCondition) proto.filter = make_relation_condition(column_condition) else raise TableStoreClientError.new("expect CompositeColumnCondition, SingleColumnCondition but not #{column_condition.class}") end proto end |
#make_composite_condition(condition) ⇒ Object
252 253 254 255 256 257 258 259 260 261 |
# File 'lib/tablestore/table_store_client.rb', line 252 def make_composite_condition(condition) proto = CompositeColumnValueFilter.new proto.combinator = condition.get_combinator condition.sub_conditions.each do |sub| proto.sub_filters << make_column_condition(sub) end proto.serialize_to_string end |
#make_condition(proto, condition) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/tablestore/table_store_client.rb', line 224 def make_condition(proto, condition) raise TableStoreClientError.new("condition should be an instance of Condition, not #{condition.class}") unless condition.is_a?(Metadata::Condition) expectation_str = condition.get_row_existence_expectation proto.row_existence = expectation_str raise TableStoreClientError.new("row_existence_expectation should be one of [#{join(', ')}], not #{expectation_str}") if proto.row_existence.nil? if condition.get_column_condition proto.column_condition = make_column_condition(condition.column_condition).serialize_to_string end proto end |
#make_put_row_item(proto, put_row_item) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/tablestore/table_store_client.rb', line 181 def make_put_row_item(proto, put_row_item) condition = put_row_item.condition if condition.nil? condition = Metadata::Condition.new(Metadata::RowExistenceExpectation::IGNORE, nil) end condition_proto = Condition.new proto.condition = make_condition(condition_proto, condition) if put_row_item.return_type == ReturnType::RT_PK proto.return_content.return_type = RT_PK end proto.row_change = serialize_for_put_row(put_row_item.row.primary_key, put_row_item.row.attribute_columns) proto.type = PUT proto end |
#make_relation_condition(condition) ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/tablestore/table_store_client.rb', line 263 def make_relation_condition(condition) proto = SingleColumnValueFilter.new proto.comparator = condition.get_comparator proto.column_name = condition.get_column_name proto.column_value = serialize_column_value(condition.get_column_value) proto.filter_if_missing = !condition.pass_if_missing proto.latest_version_only = condition.latest_version_only proto.serialize_to_string end |
#make_repeated_column_names(proto, columns_to_get) ⇒ Object
214 215 216 217 218 219 220 221 222 |
# File 'lib/tablestore/table_store_client.rb', line 214 def make_repeated_column_names(proto, columns_to_get) if columns_to_get.nil? return end columns_to_get.each do |column_name| proto << column_name end end |
#make_update_row_item(proto, update_row_item) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/tablestore/table_store_client.rb', line 197 def make_update_row_item(proto, update_row_item) condition = update_row_item.condition if condition.nil? condition = Condition.new(RowExistenceExpectation::IGNORE, nil) end condition_proto = Condition.new proto.condition = make_condition(condition_proto, condition) if update_row_item.return_type == ReturnType::RT_PK proto.return_content.return_type = RT_PK end proto.row_change = serialize_for_update_row(update_row_item.row.primary_key, update_row_item.row.attribute_columns) proto.type = UPDATE proto end |
#parse_batch_write_row(proto) ⇒ Object
306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/tablestore/table_store_client.rb', line 306 def parse_batch_write_row(proto) result_list = {} proto.each do |table_item| table_name = table_item.table_name result_list[table_name] = [] table_item.rows.each do |row_item| row = parse_write_row_item(row_item) result_list[table_name] << row end end result_list end |
#parse_get_row_item(proto) ⇒ Object
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 |
# File 'lib/tablestore/table_store_client.rb', line 275 def parse_get_row_item(proto) row_list = [] proto.each do |row_item| primary_key_columns = nil attribute_columns = nil if row_item.is_ok # error_code = nil # error_message = nil # capacity_unit = parse_capacity_unit(row_item.consumed.capacity_unit) if row_item.row.length != 0 inputStream = PlainBufferInputStream.new(row_item.row) codedInputStream = PlainBufferCodedInputStream.new(inputStream) primary_key_columns, attribute_columns = codedInputStream.read_row end else # error_code = row_item.error.code # error_message = row_item.error.HasField('message') ? row_item.error.message : '' # if row_item.HasField('consumed') # capacity_unit = parse_capacity_unit(row_item.consumed.capacity_unit) # else # capacity_unit = nil # end end row_list << {pk: primary_key_columns, attr: attribute_columns} if primary_key_columns end row_list end |
#parse_write_row_item(row_item) ⇒ Object
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/tablestore/table_store_client.rb', line 321 def parse_write_row_item(row_item) primary_key_columns = nil if row_item.is_ok error_code = nil = nil if row_item.row.length != 0 inputStream = PlainBufferInputStream.new(row_item.row) codedInputStream = PlainBufferCodedInputStream.new(inputStream) primary_key_columns, attribute_columns = codedInputStream.read_row end end primary_key_columns #BatchWriteRowResponseItem.new(row_item.is_ok, error_code, error_message, consumed, primary_key_columns) end |