zillabyte-cli 0.0.21 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/zillabyte/api/data.rb +5 -0
- data/lib/zillabyte/api.rb +10 -9
- data/lib/zillabyte/cli/apps.rb +5 -3
- data/lib/zillabyte/cli/query.rb +71 -0
- data/lib/zillabyte/cli/relations.rb +34 -33
- data/lib/zillabyte-cli/version.rb +1 -1
- metadata +3 -5
- data/lib/zillabyte/cli/apps.rb.orig +0 -1158
- data/lib/zillabyte/cli/templates/ruby/Gemfile.lock +0 -81
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OTcxYjQ2YjVjYTYxNmZkN2ExNzAzZDA5ZTg1ZGNlMzQ2OTA0YTUxNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
N2FhNTYxODc2NjMxYjVkOGIzZDVjODEyODEzY2Y4YmU1YTczNThjOA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTQ1OTZjMzU4MjM2ODBlYWM0ZGZlMWM5NDdhYzFhMzlkNzg0ZDlmOTA4NTNj
|
10
|
+
ZWNhMWMzMDljZjNiYzQ3MzQ4NWUxYWQyMzVhZmM4NDUzZTdkNTkwOWE4MGQx
|
11
|
+
YjQwOTBkMzViNGViNDYzZjc2MTI4NTFiODZiYTY2YzY0MzEzNTg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTI5NThiMzMyMTVhYTA3Y2FkZGFhMmI0ZGE2OWExNzg2ZTcxYTI2NmFlMDE3
|
14
|
+
NzA2YjE4NTg1YTVlODJhNGZkZjJkMWM4YzYzZjZjODQ5ODg1MTdjZmIwNTE0
|
15
|
+
YjQ5OTYxMzcxYmY4NzliNjJlOTg2YzM1ZTUxNmZhYWVlNGJlZGY=
|
data/lib/zillabyte/api/data.rb
CHANGED
@@ -86,6 +86,7 @@ class Zillabyte::API::Data < Zillabyte::API::Base
|
|
86
86
|
:expects => 200,
|
87
87
|
:method => :post,
|
88
88
|
:path => "/relations/#{CGI.escape(id)}/append",
|
89
|
+
# :headers => {"Content-Type" => "application/octet-stream"},
|
89
90
|
:body => options.to_json
|
90
91
|
)
|
91
92
|
hash = res.body
|
@@ -93,4 +94,8 @@ class Zillabyte::API::Data < Zillabyte::API::Base
|
|
93
94
|
|
94
95
|
end
|
95
96
|
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
|
96
101
|
end
|
data/lib/zillabyte/api.rb
CHANGED
@@ -53,6 +53,16 @@ class Zillabyte::API
|
|
53
53
|
end
|
54
54
|
|
55
55
|
|
56
|
+
def connection
|
57
|
+
@connection
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def headers
|
62
|
+
@options[:headers]
|
63
|
+
end
|
64
|
+
|
65
|
+
|
56
66
|
def host
|
57
67
|
@options[:host]
|
58
68
|
end
|
@@ -65,15 +75,6 @@ class Zillabyte::API
|
|
65
75
|
end
|
66
76
|
|
67
77
|
type = nil
|
68
|
-
if params[:body]
|
69
|
-
begin
|
70
|
-
param_hash = JSON.parse(params[:body])
|
71
|
-
type = param_hash["type"]
|
72
|
-
rescue JSON::ParserError => e
|
73
|
-
@session.error("invalid parameters", type)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
78
|
begin
|
78
79
|
|
79
80
|
# If a block is given, then we assume we're streaming (i.e. for logs)
|
data/lib/zillabyte/cli/apps.rb
CHANGED
@@ -823,15 +823,17 @@ class Zillabyte::Command::Apps < Zillabyte::Command::Base
|
|
823
823
|
header_written = false;
|
824
824
|
messages.each do |msg|
|
825
825
|
obj = JSON.parse(msg)
|
826
|
-
|
826
|
+
t = obj['tuple']
|
827
|
+
m = obj['meta'] || {}
|
828
|
+
if t
|
827
829
|
if header_written == false
|
828
|
-
keys = [
|
830
|
+
keys = [t.keys, m.keys].flatten
|
829
831
|
csv << keys
|
830
832
|
table << keys
|
831
833
|
table << :separator
|
832
834
|
header_written = true
|
833
835
|
end
|
834
|
-
vals = [
|
836
|
+
vals = [t.values, m.values].flatten
|
835
837
|
csv << vals
|
836
838
|
table << vals
|
837
839
|
end
|
data/lib/zillabyte/cli/query.rb
CHANGED
@@ -238,6 +238,77 @@ class Zillabyte::Command::Query < Zillabyte::Command::Base
|
|
238
238
|
alias_command "sql", "query:sql"
|
239
239
|
|
240
240
|
|
241
|
+
|
242
|
+
|
243
|
+
# query:pull QUERY FILE
|
244
|
+
#
|
245
|
+
# executes a queries and downloads the results to FILE
|
246
|
+
#
|
247
|
+
# pulls query data to OUTPUT.gz
|
248
|
+
def pull
|
249
|
+
|
250
|
+
query = options[:query] || shift_argument
|
251
|
+
file = options[:file] || shift_argument
|
252
|
+
type = options[:type]
|
253
|
+
error("no query given", type) if query.nil?
|
254
|
+
error("no file given", type) if file.nil?
|
255
|
+
file = "#{file}.gz" unless File.extname(file) == ".gz"
|
256
|
+
|
257
|
+
options[:query] = query
|
258
|
+
|
259
|
+
res = api.request(
|
260
|
+
:expects => 200,
|
261
|
+
:method => :post,
|
262
|
+
:path => "/query_pull",
|
263
|
+
:body => options.to_json
|
264
|
+
)
|
265
|
+
res = res.body
|
266
|
+
|
267
|
+
p res
|
268
|
+
if(res["uri"])
|
269
|
+
display "Waiting for download." if type.nil?
|
270
|
+
File.open(file, "w") do |f|
|
271
|
+
f.write open(res["uri"]).read
|
272
|
+
end
|
273
|
+
elsif(res["s3_credentials"])
|
274
|
+
display "Pulling query results." if type.nil?
|
275
|
+
s3 = AWS::S3.new(res["s3_credentials"])
|
276
|
+
bucket = s3.buckets[res["s3_bucket"]]
|
277
|
+
obj = bucket.objects.with_prefix("#{res["s3_file_key"]}/")
|
278
|
+
|
279
|
+
while(true)
|
280
|
+
keys = obj.collect(&:key)
|
281
|
+
if keys.length > 0 and keys.include?("#{res["s3_file_key"]}/manifest")
|
282
|
+
display "Starting to write to file..." if type.nil?
|
283
|
+
File.open(file, "w") do |f|
|
284
|
+
obj.each do |o|
|
285
|
+
if o.key == "#{res["s3_file_key"]}/manifest"
|
286
|
+
next
|
287
|
+
end
|
288
|
+
f.write(o.read)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
break
|
292
|
+
else
|
293
|
+
sleep(3)
|
294
|
+
obj = bucket.objects.with_prefix("#{res["s3_file_key"]}/")
|
295
|
+
end
|
296
|
+
end
|
297
|
+
else
|
298
|
+
throw "bad response: #{res}"
|
299
|
+
end
|
300
|
+
|
301
|
+
if type == "json"
|
302
|
+
display "{}"
|
303
|
+
else
|
304
|
+
display "results downloaded to file #{file}"
|
305
|
+
end
|
306
|
+
|
307
|
+
end
|
308
|
+
alias_command "sql:pull", "query:pull"
|
309
|
+
|
310
|
+
|
311
|
+
|
241
312
|
# query:pull:s3 QUERY S3_KEY S3_SECRET S3_BUCKET s3_FILE_KEY
|
242
313
|
#
|
243
314
|
# pulls query data to S3_BUCKET/FILE_KEY/part***.gz
|
@@ -4,6 +4,7 @@ require "csv"
|
|
4
4
|
require "open-uri"
|
5
5
|
require "aws-sdk"
|
6
6
|
require "json"
|
7
|
+
require "base64"
|
7
8
|
|
8
9
|
|
9
10
|
# manage custom relations
|
@@ -12,6 +13,7 @@ class Zillabyte::Command::Relations < Zillabyte::Command::Base
|
|
12
13
|
|
13
14
|
MAX_POLL_SECONDS = 60 * 5
|
14
15
|
POLL_SLEEP = 1
|
16
|
+
APPENDS_ROWS_SLICE = 5_000;
|
15
17
|
|
16
18
|
# relations
|
17
19
|
#
|
@@ -163,20 +165,30 @@ class Zillabyte::Command::Relations < Zillabyte::Command::Base
|
|
163
165
|
type = options[:type]
|
164
166
|
|
165
167
|
filetype = options[:filetype]
|
166
|
-
filetype ||= File.extname(file).gsub(".", "")
|
168
|
+
filetype ||= File.extname(file || "").gsub(".", "")
|
167
169
|
error("no id given", type) if id.nil?
|
168
170
|
error("no file given", type) if file.nil?
|
169
|
-
|
170
|
-
|
171
|
+
|
171
172
|
relation = self.api.data.get(id, options)
|
172
173
|
columns = relation["columns"].map{|col| {col["index"] => col["type"]}}
|
173
|
-
|
174
|
+
raw_rows = sanity_check_file(file,filetype,{"columns" => columns}, type)
|
174
175
|
|
175
|
-
|
176
|
+
total_rows = 0
|
177
|
+
display("uploading content.", false)
|
178
|
+
raw_rows.each_slice(APPENDS_ROWS_SLICE) do |rows|
|
179
|
+
|
180
|
+
display(".", false)
|
181
|
+
res = self.api.data.append(id, {:gzip_rows => Base64.encode64(gzip(rows.to_json()))})
|
182
|
+
# res = self.api.data.append(id, {:rows => rows})
|
183
|
+
|
184
|
+
break unless res["size"]
|
185
|
+
total_rows += res["size"]
|
186
|
+
end
|
187
|
+
|
176
188
|
if type == "json"
|
177
|
-
display
|
189
|
+
display({:rows => total_rows}.to_json)
|
178
190
|
else
|
179
|
-
display "relation ##{id} appended #{
|
191
|
+
display "relation ##{id} appended #{total_rows} rows"
|
180
192
|
end
|
181
193
|
|
182
194
|
end
|
@@ -431,32 +443,9 @@ class Zillabyte::Command::Relations < Zillabyte::Command::Base
|
|
431
443
|
|
432
444
|
|
433
445
|
|
434
|
-
def get_relation_properties(schema, is_public, description, aliases)
|
435
|
-
|
436
|
-
|
437
|
-
aliases = ask.strip
|
438
|
-
end
|
439
|
-
while true
|
440
|
-
aliases = aliases.strip.split(",").map{|x| x.strip}.uniq
|
441
|
-
all_valid = true
|
442
|
-
aliases.each do |a|
|
443
|
-
if(!(a =~ /^[a-zA-Z0-9\_]+$/i))
|
444
|
-
display "\"#{a}\" contains illegal characters. Only letters, numbers and underscore are allowed in alias names."
|
445
|
-
display "If you would like to give alias names to your relation, please enter them below. (comma separated, only letters, number and underscore allowed)"
|
446
|
-
aliases = ask.strip
|
447
|
-
all_valid = false
|
448
|
-
break
|
449
|
-
end
|
450
|
-
end
|
451
|
-
break if all_valid
|
452
|
-
end
|
453
|
-
display "Will use the following aliases for this relation: #{aliases}" if !aliases.empty?
|
454
|
-
|
455
|
-
if description.nil?
|
456
|
-
display "Enter a description for your relation (defaults to empty string)."
|
457
|
-
description = ask.strip
|
458
|
-
end
|
459
|
-
|
446
|
+
def get_relation_properties(schema, is_public, description = "", aliases = nil)
|
447
|
+
|
448
|
+
description ||= ""
|
460
449
|
valid_types=["string", "integer", "float"]
|
461
450
|
meta_names=["id", "confidence", "since", "source"]
|
462
451
|
if schema.nil?
|
@@ -606,4 +595,16 @@ class Zillabyte::Command::Relations < Zillabyte::Command::Base
|
|
606
595
|
# end
|
607
596
|
# alias_command "rl:status", "relations:status"
|
608
597
|
|
598
|
+
|
599
|
+
def gzip(string)
|
600
|
+
wio = StringIO.new("w")
|
601
|
+
w_gz = Zlib::GzipWriter.new(wio)
|
602
|
+
w_gz.write(string)
|
603
|
+
w_gz.close
|
604
|
+
compressed = wio.string
|
605
|
+
compressed
|
606
|
+
end
|
607
|
+
|
608
|
+
|
609
|
+
|
609
610
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zillabyte-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zillabyte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -257,7 +257,6 @@ files:
|
|
257
257
|
- lib/zillabyte/api.rb
|
258
258
|
- lib/zillabyte/auth.rb
|
259
259
|
- lib/zillabyte/cli/apps.rb
|
260
|
-
- lib/zillabyte/cli/apps.rb.orig
|
261
260
|
- lib/zillabyte/cli/auth.rb
|
262
261
|
- lib/zillabyte/cli/base.rb
|
263
262
|
- lib/zillabyte/cli/config.rb
|
@@ -279,7 +278,6 @@ files:
|
|
279
278
|
- lib/zillabyte/cli/templates/python/zillabyte.conf.yaml
|
280
279
|
- lib/zillabyte/cli/templates/ruby/app.rb
|
281
280
|
- lib/zillabyte/cli/templates/ruby/Gemfile
|
282
|
-
- lib/zillabyte/cli/templates/ruby/Gemfile.lock
|
283
281
|
- lib/zillabyte/cli/templates/ruby/zillabyte.conf.yaml
|
284
282
|
- lib/zillabyte/cli/version.rb
|
285
283
|
- lib/zillabyte/cli/zillalogs.rb
|
@@ -318,7 +316,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
318
316
|
version: '0'
|
319
317
|
requirements: []
|
320
318
|
rubyforge_project:
|
321
|
-
rubygems_version: 2.0.
|
319
|
+
rubygems_version: 2.0.7
|
322
320
|
signing_key:
|
323
321
|
specification_version: 4
|
324
322
|
summary: The Official Zillabyte CLI Gem
|