tablestore-ruby-sdk 0.0.0

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.
@@ -0,0 +1,22 @@
1
+ require 'rest-client'
2
+ require 'tablestore/error'
3
+
4
+ NETWORK_IO_TIME_COUNT_FLAG = false
5
+ NETWORK_IO_TIME = 0
6
+
7
+ class ConnectionPool
8
+ NUM_POOLS = 5
9
+
10
+ def initialize(host, path, timeout=0, maxsize=50)
11
+ @host = host
12
+ @path = path
13
+ end
14
+
15
+ def send_receive(url, request_headers, request_body)
16
+ response = RestClient.post(url, request_body, request_headers)
17
+ response_headers = response.headers
18
+ response_body = response.body
19
+
20
+ return response.status, response_headers, response_body
21
+ end
22
+ end
@@ -0,0 +1,36 @@
1
+ require 'digest/crc'
2
+
3
+ module Digest
4
+ class CRC8Auto < CRC
5
+
6
+ WIDTH = 8
7
+
8
+ TABLE = [
9
+ 0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d,
10
+ 0x70, 0x77, 0x7e, 0x79, 0x6c, 0x6b, 0x62, 0x65, 0x48, 0x4f, 0x46, 0x41, 0x54, 0x53, 0x5a, 0x5d,
11
+ 0xe0, 0xe7, 0xee, 0xe9, 0xfc, 0xfb, 0xf2, 0xf5, 0xd8, 0xdf, 0xd6, 0xd1, 0xc4, 0xc3, 0xca, 0xcd,
12
+ 0x90, 0x97, 0x9e, 0x99, 0x8c, 0x8b, 0x82, 0x85, 0xa8, 0xaf, 0xa6, 0xa1, 0xb4, 0xb3, 0xba, 0xbd,
13
+ 0xc7, 0xc0, 0xc9, 0xce, 0xdb, 0xdc, 0xd5, 0xd2, 0xff, 0xf8, 0xf1, 0xf6, 0xe3, 0xe4, 0xed, 0xea,
14
+ 0xb7, 0xb0, 0xb9, 0xbe, 0xab, 0xac, 0xa5, 0xa2, 0x8f, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9d, 0x9a,
15
+ 0x27, 0x20, 0x29, 0x2e, 0x3b, 0x3c, 0x35, 0x32, 0x1f, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0d, 0x0a,
16
+ 0x57, 0x50, 0x59, 0x5e, 0x4b, 0x4c, 0x45, 0x42, 0x6f, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7d, 0x7a,
17
+ 0x89, 0x8e, 0x87, 0x80, 0x95, 0x92, 0x9b, 0x9c, 0xb1, 0xb6, 0xbf, 0xb8, 0xad, 0xaa, 0xa3, 0xa4,
18
+ 0xf9, 0xfe, 0xf7, 0xf0, 0xe5, 0xe2, 0xeb, 0xec, 0xc1, 0xc6, 0xcf, 0xc8, 0xdd, 0xda, 0xd3, 0xd4,
19
+ 0x69, 0x6e, 0x67, 0x60, 0x75, 0x72, 0x7b, 0x7c, 0x51, 0x56, 0x5f, 0x58, 0x4d, 0x4a, 0x43, 0x44,
20
+ 0x19, 0x1e, 0x17, 0x10, 0x05, 0x02, 0x0b, 0x0c, 0x21, 0x26, 0x2f, 0x28, 0x3d, 0x3a, 0x33, 0x34,
21
+ 0x4e, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5c, 0x5b, 0x76, 0x71, 0x78, 0x7f, 0x6a, 0x6d, 0x64, 0x63,
22
+ 0x3e, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2c, 0x2b, 0x06, 0x01, 0x08, 0x0f, 0x1a, 0x1d, 0x14, 0x13,
23
+ 0xae, 0xa9, 0xa0, 0xa7, 0xb2, 0xb5, 0xbc, 0xbb, 0x96, 0x91, 0x98, 0x9f, 0x8a, 0x8d, 0x84, 0x83,
24
+ 0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb, 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3
25
+ ].freeze
26
+
27
+ def crc8(crc, data)
28
+ @crc = crc
29
+ data.each_byte do |b|
30
+ @crc = ((@table[(@crc ^ b) & 0xff] ^ (@crc << 8)) & 0xff)
31
+ end
32
+
33
+ return self
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,57 @@
1
+
2
+ class OTSError
3
+
4
+ end
5
+
6
+ class TableStoreClientError < ::StandardError
7
+ attr_accessor :message
8
+ attr_accessor :http_status
9
+
10
+ def initialize(message, http_status = nil)
11
+ @message = message
12
+ @http_status = http_status
13
+ end
14
+
15
+ def get_http_status
16
+ @http_status
17
+ end
18
+
19
+ def get_error_message
20
+ @message
21
+ end
22
+ end
23
+
24
+ class TableStoreServiceError < ::StandardError
25
+ attr_accessor :message
26
+ attr_accessor :http_status
27
+ attr_accessor :code
28
+ attr_accessor :request_id
29
+
30
+ def initialize(http_status, code, message, request_id = '')
31
+ @http_status = http_status
32
+ @code = code
33
+ @message = message
34
+ @request_id = request_id
35
+ end
36
+
37
+ def self.string
38
+ "ErrorCode: #{@code}, ErrorMessage: #{@message}, RequestID: #{@request_id}"
39
+ end
40
+
41
+ def get_http_status
42
+ @http_status
43
+ end
44
+
45
+ def get_error_message
46
+ @message
47
+ end
48
+
49
+ def get_error_code
50
+ @code
51
+ end
52
+
53
+ def get_request_id
54
+ @request_id
55
+ end
56
+ end
57
+
@@ -0,0 +1,51 @@
1
+
2
+ VERSION = '0.0.1'
3
+ ALL_DATA_TYPE = [
4
+ 'OTSClient',
5
+ # Data Types
6
+ 'INF_MIN',
7
+ 'INF_MAX',
8
+ 'PK_AUTO_INCR',
9
+ 'TableMeta',
10
+ 'TableOptions',
11
+ 'CapacityUnit',
12
+ 'ReservedThroughput',
13
+ 'ReservedThroughputDetails',
14
+ 'ColumnType',
15
+ 'ReturnType',
16
+ 'Column',
17
+ 'Direction',
18
+ 'UpdateTableResponse',
19
+ 'DescribeTableResponse',
20
+ 'RowDataItem',
21
+ 'Condition',
22
+ 'Row',
23
+ 'RowItem',
24
+ 'PutRowItem',
25
+ 'UpdateRowItem',
26
+ 'DeleteRowItem',
27
+ 'BatchGetRowRequest',
28
+ 'TableInBatchGetRowItem',
29
+ 'BatchGetRowResponse',
30
+ 'BatchWriteRowType',
31
+ 'BatchWriteRowRequest',
32
+ 'TableInBatchWriteRowItem',
33
+ 'BatchWriteRowResponse',
34
+ 'BatchWriteRowResponseItem',
35
+ 'TableStoreClientError',
36
+ 'TableStoreServiceError',
37
+ 'DefaultRetryPolicy',
38
+ 'LogicalOperator',
39
+ 'ComparatorType',
40
+ 'ColumnConditionType',
41
+ 'ColumnCondition',
42
+ 'CompositeColumnCondition',
43
+ 'SingleColumnCondition',
44
+ 'RowExistenceExpectation',
45
+ ]
46
+
47
+ require 'client'
48
+ require 'metadata'
49
+ require 'error'
50
+ require 'retry'
51
+ require 'const'
@@ -0,0 +1,413 @@
1
+
2
+ ALL = [
3
+ 'INF_MIN',
4
+ 'INF_MAX',
5
+ 'PK_AUTO_INCR',
6
+ 'TableMeta',
7
+ 'TableOptions',
8
+ 'CapacityUnit',
9
+ 'ReservedThroughput',
10
+ 'ReservedThroughputDetails',
11
+ 'ColumnType',
12
+ 'ReturnType',
13
+ 'Column',
14
+ 'Direction',
15
+ 'UpdateType',
16
+ 'UpdateTableResponse',
17
+ 'DescribeTableResponse',
18
+ 'RowDataItem',
19
+ 'Condition',
20
+ 'Row',
21
+ 'RowItem',
22
+ 'PutRowItem',
23
+ 'UpdateRowItem',
24
+ 'DeleteRowItem',
25
+ 'BatchGetRowRequest',
26
+ 'TableInBatchGetRowItem',
27
+ 'BatchGetRowResponse',
28
+ 'BatchWriteRowType',
29
+ 'BatchWriteRowRequest',
30
+ 'TableInBatchWriteRowItem',
31
+ 'BatchWriteRowResponse',
32
+ 'BatchWriteRowResponseItem',
33
+ 'LogicalOperator',
34
+ 'ComparatorType',
35
+ 'ColumnConditionType',
36
+ 'ColumnCondition',
37
+ 'CompositeColumnCondition',
38
+ 'SingleColumnCondition',
39
+ 'RowExistenceExpectation',
40
+ ]
41
+
42
+ module Metadata
43
+ class RowExistenceExpectation
44
+ IGNORE = "IGNORE"
45
+ EXPECT_EXIST = "EXPECT_EXIST"
46
+ EXPECT_NOT_EXIST = "EXPECT_NOT_EXIST"
47
+
48
+ VALUES = [
49
+ IGNORE,
50
+ EXPECT_EXIST,
51
+ EXPECT_NOT_EXIST,
52
+ ]
53
+
54
+ MEMBERS = [
55
+ "RowExistenceExpectation::IGNORE",
56
+ "RowExistenceExpectation::EXPECT_EXIST",
57
+ "RowExistenceExpectation::EXPECT_NOT_EXIST",
58
+ ]
59
+ end
60
+
61
+ class LogicalOperator
62
+ NOT = 1
63
+ AND = 2
64
+ OR = 3
65
+
66
+ VALUES = [
67
+ NOT,
68
+ AND,
69
+ OR
70
+ ]
71
+
72
+ MEMBERS = [
73
+ "LogicalOperator::NOT",
74
+ "LogicalOperator::AND",
75
+ "LogicalOperator::OR"
76
+ ]
77
+ end
78
+
79
+ class ComparatorType
80
+ EQUAL = 1
81
+ NOT_EQUAL = 2
82
+ GREATER_THAN = 3
83
+ GREATER_EQUAL = 4
84
+ LESS_THAN = 5
85
+ LESS_EQUAL = 6
86
+
87
+ VALUES = [
88
+ EQUAL,
89
+ NOT_EQUAL,
90
+ GREATER_THAN,
91
+ GREATER_EQUAL,
92
+ LESS_THAN,
93
+ LESS_EQUAL,
94
+ ]
95
+
96
+ MEMBERS = [
97
+ "ComparatorType::EQUAL",
98
+ "ComparatorType::NOT_EQUAL",
99
+ "ComparatorType::GREATER_THAN",
100
+ "ComparatorType::GREATER_EQUAL",
101
+ "ComparatorType::LESS_THAN",
102
+ "ComparatorType::LESS_EQUAL",
103
+ ]
104
+ end
105
+
106
+ class Condition
107
+ def initialize(row_existence_expectation, column_condition = nil)
108
+ @row_existence_expectation = nil
109
+ @column_condition = nil
110
+
111
+ set_row_existence_expectation(row_existence_expectation)
112
+
113
+ set_column_condition(column_condition) if @column_condition.present?
114
+ end
115
+
116
+ def set_row_existence_expectation(row_existence_expectation)
117
+ raise TableStoreClientError.new("Expect input row_existence_expectation should be one of #{RowExistenceExpectation::MEMBERS.to_s}, but #{row_existence_expectation}") unless RowExistenceExpectation::VALUES.include? row_existence_expectation
118
+ @row_existence_expectation = row_existence_expectation
119
+ end
120
+
121
+ def set_column_condition(column_condition)
122
+ @column_condition = column_condition
123
+ end
124
+
125
+ def get_row_existence_expectation
126
+ @row_existence_expectation
127
+ end
128
+
129
+ def get_column_condition
130
+ @column_condition
131
+ end
132
+ end
133
+
134
+ class Row
135
+ def initialize(primary_key, attribute_columns=nil)
136
+ @primary_key = primary_key
137
+ @attribute_columns = attribute_columns
138
+ end
139
+
140
+ def primary_key
141
+ @primary_key
142
+ end
143
+
144
+ def attribute_columns
145
+ @attribute_columns
146
+ end
147
+ end
148
+
149
+ class RowItem
150
+ def initialize(row_type, row, condition, return_type = nil)
151
+ @type = row_type
152
+ @condition = condition
153
+ @row = row
154
+ @return_type = return_type
155
+ end
156
+
157
+ def type
158
+ @type
159
+ end
160
+
161
+ def condition
162
+ @condition
163
+ end
164
+
165
+ def row
166
+ @row
167
+ end
168
+
169
+ def return_type
170
+ @return_type
171
+ end
172
+ end
173
+
174
+ class ColumnConditionType
175
+ COMPOSITE_COLUMN_CONDITION = 2
176
+ SINGLE_COLUMN_CONDITION = 1
177
+ end
178
+
179
+ class CompositeColumnCondition
180
+ def initialize(combinator)
181
+ @sub_conditions = []
182
+ set_combinator(combinator)
183
+ end
184
+
185
+ def get_type
186
+ ColumnConditionType::COMPOSITE_COLUMN_CONDITION
187
+ end
188
+
189
+ def set_combinator(combinator)
190
+ unless LogicalOperator::VALUES.include?combinator
191
+ raise TableStoreClientError.new("Expect input combinator should be one of #{LogicalOperator::MEMBERS.to_s}, but #{combinator}")
192
+ end
193
+ @combinator = combinator
194
+ end
195
+
196
+ def get_combinator
197
+ @combinator
198
+ end
199
+
200
+ def add_sub_condition(condition)
201
+ @sub_conditions<< condition
202
+ end
203
+
204
+ def clear_sub_condition
205
+ @sub_conditions = []
206
+ end
207
+
208
+ def sub_conditions
209
+ @sub_conditions
210
+ end
211
+ end
212
+
213
+ class SingleColumnCondition
214
+ def initialize(column_name, column_value, comparator, pass_if_missing = true, latest_version_only = true)
215
+ @column_name = column_name
216
+ @column_value = column_value
217
+
218
+ @comparator = nil
219
+ @pass_if_missing = nil
220
+ @latest_version_only = nil
221
+
222
+ set_comparator(comparator)
223
+ set_pass_if_missing(pass_if_missing)
224
+ set_latest_version_only(latest_version_only)
225
+ end
226
+
227
+ def get_type
228
+ ColumnConditionType::SINGLE_COLUMN_CONDITION
229
+ end
230
+
231
+ def set_pass_if_missing(pass_if_missing)
232
+ @pass_if_missing = pass_if_missing
233
+ end
234
+
235
+ def get_pass_if_missing
236
+ @pass_if_missing
237
+ end
238
+
239
+ def set_latest_version_only(latest_version_only)
240
+ @latest_version_only = latest_version_only
241
+ end
242
+
243
+ def get_latest_version_only
244
+ @latest_version_only
245
+ end
246
+
247
+ def set_column_name(column_name)
248
+ if column_name.nil?
249
+ raise TableStoreClientError.new("The input column_name of SingleColumnCondition should not be None")
250
+ end
251
+ @column_name = column_name
252
+ end
253
+
254
+ def get_column_name
255
+ @column_name
256
+ end
257
+
258
+ def set_column_value(column_value)
259
+ if column_value.nil
260
+ raise TableStoreClientError.new("The input column_value of SingleColumnCondition should not be None")
261
+ end
262
+ @column_value = column_value
263
+ end
264
+
265
+ def get_column_value
266
+ @column_value
267
+ end
268
+
269
+ def set_comparator(comparator)
270
+ @comparator = comparator
271
+ end
272
+
273
+ def get_comparator
274
+ @comparator
275
+ end
276
+
277
+ def pass_if_missing
278
+ @pass_if_missing
279
+ end
280
+
281
+ def latest_version_only
282
+ @latest_version_only
283
+ end
284
+ end
285
+
286
+ class BatchGetRowRequest
287
+ def initialize
288
+ @items = {}
289
+ end
290
+
291
+ def items
292
+ @items
293
+ end
294
+
295
+ def add(table_item)
296
+ """
297
+ 说明:添加tablestore.metadata.TableInBatchGetRowItem对象
298
+ 注意:对象内部存储tablestore.metadata.TableInBatchGetRowItem对象采用‘字典’的形式,Key是表
299
+ 的名字,因此如果插入同表名的对象,那么之前的对象将被覆盖。
300
+ """
301
+ unless table_item.is_a?(TableInBatchGetRowItem)
302
+ raise TableStoreClientError.new("The input table_item should be an instance of TableInBatchGetRowItem, not #{table_item.class}")
303
+ end
304
+ @items[table_item.table_name] = table_item
305
+ end
306
+ end
307
+
308
+ class TableInBatchWriteRowItem
309
+ def initialize(table_name, row_items)
310
+ @table_name = table_name
311
+ @row_items = row_items
312
+ end
313
+
314
+ def row_items
315
+ @row_items
316
+ end
317
+
318
+ def table_name
319
+ @table_name
320
+ end
321
+ end
322
+
323
+ class BatchWriteRowRequest
324
+ def initialize
325
+ @items = {}
326
+ end
327
+
328
+ def add(table_item)
329
+ """
330
+ 说明:添加tablestore.metadata.TableInBatchWriteRowItem对象
331
+ 注意:对象内部存储tablestore.metadata.TableInBatchWriteRowItem对象采用‘字典’的形式,Key是表
332
+ 的名字,因此如果插入同表名的对象,那么之前的对象将被覆盖。
333
+ """
334
+ unless table_item.is_a?(TableInBatchWriteRowItem)
335
+ raise TableStoreClientError.new("The input table_item should be an instance of TableInBatchWriteRowItem, not #{table_item.class}")
336
+ end
337
+
338
+ @items[table_item.table_name] = table_item
339
+ end
340
+
341
+ def items
342
+ @items
343
+ end
344
+ end
345
+
346
+ class TableInBatchGetRowItem
347
+ def initialize(table_name, primary_keys, columns_to_get=nil,
348
+ column_filter=nil, max_version=nil, time_range=nil,
349
+ start_column=nil, end_column=nil, token=nil)
350
+ @table_name = table_name
351
+ @primary_keys = primary_keys
352
+ @columns_to_get = columns_to_get
353
+ @column_filter = column_filter
354
+ @max_version = max_version
355
+ @time_range = time_range
356
+ @start_column = start_column
357
+ @end_column = end_column
358
+ @token = token
359
+ end
360
+
361
+ def table_name
362
+ @table_name
363
+ end
364
+
365
+ def primary_keys
366
+ @primary_keys
367
+ end
368
+
369
+ def columns_to_get
370
+ @columns_to_get
371
+ end
372
+
373
+ def column_filter
374
+ @column_filter
375
+ end
376
+
377
+ def max_version
378
+ @max_version
379
+ end
380
+
381
+ def time_range
382
+ @time_range
383
+ end
384
+
385
+ def start_column
386
+ @start_column
387
+ end
388
+
389
+ def end_column
390
+ @end_column
391
+ end
392
+
393
+ def token
394
+ @token
395
+ end
396
+ end
397
+
398
+ class BatchWriteRowType
399
+ PUT = "put"
400
+ UPDATE = "update"
401
+ DELETE = "delete"
402
+ end
403
+
404
+ class INF_MIN
405
+ end
406
+
407
+ class INF_MAX
408
+ end
409
+
410
+ class PK_AUTO_INCR
411
+ end
412
+ end
413
+