td-client 0.8.15 → 0.8.16

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,4 +1,9 @@
1
1
 
2
+ == 2012-05-10 version 0.8.16
3
+
4
+ * Added bulk import feature
5
+
6
+
2
7
  == 2012-04-26 version 0.8.15
3
8
 
4
9
  * Result model replaces ResultSet model
@@ -156,6 +156,63 @@ class Client
156
156
  Job.new(self, job_id, :export, nil)
157
157
  end
158
158
 
159
+ # => nil
160
+ def create_bulk_import(name, database, table)
161
+ @api.create_bulk_import(name, database, table)
162
+ end
163
+
164
+ # => nil
165
+ def delete_bulk_import(name)
166
+ @api.delete_bulk_import(name)
167
+ end
168
+
169
+ # => nil
170
+ def freeze_bulk_import(name)
171
+ @api.freeze_bulk_import(name)
172
+ end
173
+
174
+ # => nil
175
+ def unfreeze_bulk_import(name)
176
+ @api.unfreeze_bulk_import(name)
177
+ end
178
+
179
+ # => Job
180
+ def perform_bulk_import(name)
181
+ job_id = @api.perform_bulk_import(name)
182
+ Job.new(self, job_id, :bulk_import, nil)
183
+ end
184
+
185
+ # => nil
186
+ def commit_bulk_import(name)
187
+ @api.commit_bulk_import(name)
188
+ end
189
+
190
+ # => records:[row:Hash]
191
+ def bulk_import_error_records(name, &block)
192
+ @api.bulk_import_error_records(name, &block)
193
+ end
194
+
195
+ # => [BulkImport]
196
+ def bulk_imports
197
+ @api.list_bulk_imports.map {|data|
198
+ BulkImport.new(self, data)
199
+ }
200
+ end
201
+
202
+ # => nil
203
+ def bulk_import_upload_part(name, part_name, stream, size)
204
+ @api.bulk_import_upload_part(name, part_name, stream, size)
205
+ end
206
+
207
+ # => nil
208
+ def bulk_import_delete_part(name, part_name)
209
+ @api.bulk_import_delete_part(name, part_name)
210
+ end
211
+
212
+ def list_bulk_import_parts(name)
213
+ @api.list_bulk_import_parts(name)
214
+ end
215
+
159
216
  # => first_time:Time
160
217
  def create_schedule(name, opts)
161
218
  raise ArgumentError, "'cron' option is required" unless opts[:cron] || opts['cron']
@@ -401,6 +401,147 @@ class API
401
401
  return js['job_id'].to_s
402
402
  end
403
403
 
404
+ ####
405
+ ## Bulk import API
406
+ ##
407
+
408
+ # => nil
409
+ def create_bulk_import(name, db, table, opts={})
410
+ params = opts.dup
411
+ code, body, res = post("/v3/bulk_import/create/#{e name}/#{e db}/#{e table}", params)
412
+ if code != "200"
413
+ raise_error("Create bulk import failed", res)
414
+ end
415
+ return nil
416
+ end
417
+
418
+ # => nil
419
+ def delete_bulk_import(name, opts={})
420
+ params = opts.dup
421
+ code, body, res = post("/v3/bulk_import/delete/#{e name}", params)
422
+ if code != "200"
423
+ raise_error("Delete bulk import failed", res)
424
+ end
425
+ return nil
426
+ end
427
+
428
+ # => result:[data:Hash]
429
+ def list_bulk_imports(opts={})
430
+ params = opts.dup
431
+ code, body, res = get("/v3/bulk_import/list", params)
432
+ if code != "200"
433
+ raise_error("List bulk imports failed", res)
434
+ end
435
+ js = checked_json(body, %w[bulk_imports])
436
+ return js['bulk_imports']
437
+ end
438
+
439
+ def list_bulk_import_parts(name, opts={})
440
+ params = opts.dup
441
+ code, body, res = get("/v3/bulk_import/list_parts/#{e name}", params)
442
+ if code != "200"
443
+ raise_error("List bulk import parts failed", res)
444
+ end
445
+ js = checked_json(body, %w[parts])
446
+ return js['parts']
447
+ end
448
+
449
+ # => nil
450
+ def bulk_import_upload_part(name, part_name, stream, size, opts={})
451
+ code, body, res = put("/v3/bulk_import/upload_part/#{e name}/#{e part_name}", stream, size)
452
+ if code[0] != ?2
453
+ raise_error("Upload a part failed", res)
454
+ end
455
+ return nil
456
+ end
457
+
458
+ # => nil
459
+ def bulk_import_delete_part(name, part_name, opts={})
460
+ params = opts.dup
461
+ code, body, res = post("/v3/bulk_import/delete_part/#{e name}/#{e part_name}", params)
462
+ if code[0] != ?2
463
+ raise_error("Delete a part failed", res)
464
+ end
465
+ return nil
466
+ end
467
+
468
+ # => nil
469
+ def freeze_bulk_import(name, opts={})
470
+ params = opts.dup
471
+ code, body, res = post("/v3/bulk_import/freeze/#{e name}", params)
472
+ if code != "200"
473
+ raise_error("Freeze bulk import failed", res)
474
+ end
475
+ return nil
476
+ end
477
+
478
+ # => nil
479
+ def unfreeze_bulk_import(name, opts={})
480
+ params = opts.dup
481
+ code, body, res = post("/v3/bulk_import/unfreeze/#{e name}", params)
482
+ if code != "200"
483
+ raise_error("Unfreeze bulk import failed", res)
484
+ end
485
+ return nil
486
+ end
487
+
488
+ # => jobId:String
489
+ def perform_bulk_import(name, opts={})
490
+ params = opts.dup
491
+ code, body, res = post("/v3/bulk_import/perform/#{e name}", params)
492
+ if code != "200"
493
+ raise_error("Perform bulk import failed", res)
494
+ end
495
+ js = checked_json(body, %w[job_id])
496
+ return js['job_id'].to_s
497
+ end
498
+
499
+ # => nil
500
+ def commit_bulk_import(name, opts={})
501
+ params = opts.dup
502
+ code, body, res = post("/v3/bulk_import/commit/#{e name}", params)
503
+ if code != "200"
504
+ raise_error("Commit bulk import failed", res)
505
+ end
506
+ return nil
507
+ end
508
+
509
+ # => data...
510
+ def bulk_import_error_records(name, opts={}, &block)
511
+ params = opts.dup
512
+ code, body, res = get("/v3/bulk_import/error_records/#{e name}", params)
513
+ if code != "200"
514
+ raise_error("Commit bulk import failed", res)
515
+ end
516
+ if body.empty?
517
+ if block
518
+ return nil
519
+ else
520
+ return []
521
+ end
522
+ end
523
+ require 'zlib'
524
+ require 'stringio'
525
+ require 'msgpack'
526
+ u = MessagePack::Unpacker.new(Zlib::GzipReader.new(StringIO.new(body)))
527
+ if block
528
+ begin
529
+ u.each(&block)
530
+ rescue EOFError
531
+ end
532
+ nil
533
+ else
534
+ result = []
535
+ begin
536
+ u.each {|row|
537
+ result << row
538
+ }
539
+ rescue EOFError
540
+ end
541
+ return result
542
+ end
543
+ end
544
+
404
545
  ####
405
546
  ## Schedule API
406
547
  ##
@@ -343,6 +343,37 @@ class Result < Model
343
343
  end
344
344
 
345
345
 
346
+ class BulkImport < Model
347
+ def initialize(client, data={})
348
+ super(client)
349
+ @name = data['name']
350
+ @database = data['database']
351
+ @table = data['table']
352
+ @status = data['status']
353
+ @upload_frozen = data['upload_frozen']
354
+ @job_id = data['job_id']
355
+ @valid_records = data['valid_records']
356
+ @error_records = data['error_records']
357
+ @valid_parts = data['valid_parts']
358
+ @error_parts = data['error_parts']
359
+ end
360
+
361
+ attr_reader :name
362
+ attr_reader :database
363
+ attr_reader :table
364
+ attr_reader :status
365
+ attr_reader :job_id
366
+ attr_reader :valid_records
367
+ attr_reader :error_records
368
+ attr_reader :valid_parts
369
+ attr_reader :error_parts
370
+
371
+ def upload_frozen?
372
+ @upload_frozen
373
+ end
374
+ end
375
+
376
+
346
377
  class AggregationSchema < Model
347
378
  def initialize(client, name, relation_key, logs=nil, attributes=nil, timezone=nil)
348
379
  super(client)
@@ -1,5 +1,5 @@
1
1
  module TreasureData
2
2
 
3
- VERSION = '0.8.15'
3
+ VERSION = '0.8.16'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: td-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.15
4
+ version: 0.8.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-27 00:00:00.000000000Z
12
+ date: 2012-05-10 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: msgpack
16
- requirement: &70230453942020 !ruby/object:Gem::Requirement
16
+ requirement: &70147243679900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.4.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70230453942020
24
+ version_requirements: *70147243679900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &70230453937480 !ruby/object:Gem::Requirement
27
+ requirement: &70147243665900 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.4.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70230453937480
35
+ version_requirements: *70147243665900
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70230453936700 !ruby/object:Gem::Requirement
38
+ requirement: &70147243665220 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 2.8.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70230453936700
46
+ version_requirements: *70147243665220
47
47
  description:
48
48
  email:
49
49
  executables: []