zillabyte-cli 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 22d9cc6afd2e4518c3b9e30f5bdef4ce6e04d401
4
- data.tar.gz: 075831a2470881c465517981241b81d3c8515758
5
- SHA512:
6
- metadata.gz: 55df4217f4fe7e95a68722b993e550b2c950367b0f7e0e239036e7f7f0152fcd4eea6e268339f5c877817f58f402029e41403e8f2e7e0644e8eb09dd74a79510
7
- data.tar.gz: 014b495c10c3850dc318936a32491fd51d3f751a84117973e241bb33de194027c36ae5b5fb8ac147763addda6d6d40ec79091353b0e5de5c32ad09ec68d6626a
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MTk1OGRiMDFjYmZkNTBiNTE0YjI5MGVmZjEzZTQ0MzVlNjMzMGM4Mw==
5
+ data.tar.gz: !binary |-
6
+ ZWJmODIwODA3MzAwNWJiN2JkY2U0ODAyMDI5OTI5ZjU4ZGI4MmZkMA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MzE4ZjNhMmU0YjVjM2EyNWE5ZWM4ODJmY2I4ZDA1YWQ1Zjk5OTY3NTkzNmMw
10
+ NDk0NjI1MmIxYjg4YjhiY2M1ZWYwNjcxNDU5ZTExMmJlMTk5MDRhNGQwMmVi
11
+ YTdmNDdhYjRiZmE2ZTI0ZDEzMDBiMzJlMTI4MDg4NTJjMGVhYjU=
12
+ data.tar.gz: !binary |-
13
+ YTQ0MDdmYTAyOTYwZmJjM2E5ZDFjYzc3OGI1MzNkNDMzMDkyZTlmM2EzMjMx
14
+ NmQ2NzNjNmQ5NWU1YzJkZmViYTkyZjU1MTcyMTZmYzlhMmNlZDM5MTU1MTA2
15
+ YjU0ZjVmZDA3NTNiMzY3NjAzZTI5YTg0NzdjMWQ1YTM2ZTU3NmY=
@@ -1,5 +1,5 @@
1
1
  module Zillabyte
2
2
  module CLI
3
- VERSION = "0.9.5"
3
+ VERSION = "0.9.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,139 +1,139 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zillabyte-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - zillabyte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-29 00:00:00.000000000 Z
11
+ date: 2014-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: netrc
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.7.7
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.7.7
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rest-client
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: 1.6.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.6.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: excon
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0.31'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.31'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: terminal-table
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.4'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.4'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: activesupport
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
89
  version: 3.2.11
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
96
  version: 3.2.11
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: multi_json
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ~>
102
102
  - !ruby/object:Gem::Version
103
103
  version: '1.0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ~>
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: colorize
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ~>
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0.6'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ~>
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0.6'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: indentation
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ~>
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0.1'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ~>
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0.1'
139
139
  description: The Official Zillabyte CLI Gem
@@ -145,16 +145,9 @@ executables:
145
145
  extensions: []
146
146
  extra_rdoc_files: []
147
147
  files:
148
- - Gemfile
149
- - LICENSE
150
- - README.md
151
148
  - bin/zb
152
149
  - bin/zbd
153
150
  - bin/zillabyte
154
- - lib/#zillabyte-cli.rb#
155
- - lib/zillabyte-cli.rb
156
- - lib/zillabyte-cli/version.rb
157
- - lib/zillabyte/api.rb
158
151
  - lib/zillabyte/api/apps.rb
159
152
  - lib/zillabyte/api/base.rb
160
153
  - lib/zillabyte/api/components.rb
@@ -163,15 +156,12 @@ files:
163
156
  - lib/zillabyte/api/keys.rb
164
157
  - lib/zillabyte/api/logs.rb
165
158
  - lib/zillabyte/api/metrics.rb
166
- - lib/zillabyte/api/queries.rb
167
159
  - lib/zillabyte/api/semantic_tags.rb
168
160
  - lib/zillabyte/api/settings.rb
169
161
  - lib/zillabyte/api/sources.rb
170
162
  - lib/zillabyte/api/zillalogs.rb
163
+ - lib/zillabyte/api.rb
171
164
  - lib/zillabyte/auth.rb
172
- - lib/zillabyte/cli.rb
173
- - lib/zillabyte/cli/#logs.rb#
174
- - lib/zillabyte/cli/#repl.rb#
175
165
  - lib/zillabyte/cli/apps.rb
176
166
  - lib/zillabyte/cli/auth.rb
177
167
  - lib/zillabyte/cli/base.rb
@@ -187,7 +177,6 @@ files:
187
177
  - lib/zillabyte/cli/host.rb
188
178
  - lib/zillabyte/cli/keys.rb
189
179
  - lib/zillabyte/cli/nuke.rb
190
- - lib/zillabyte/cli/query.rb
191
180
  - lib/zillabyte/cli/repl.rb
192
181
  - lib/zillabyte/cli/rpc.rb
193
182
  - lib/zillabyte/cli/sources.rb
@@ -196,69 +185,67 @@ files:
196
185
  - lib/zillabyte/cli/templates/apps/python/app.py
197
186
  - lib/zillabyte/cli/templates/apps/python/requirements.txt
198
187
  - lib/zillabyte/cli/templates/apps/python/zillabyte.conf.yaml
188
+ - lib/zillabyte/cli/templates/apps/ruby/app.rb.erb
199
189
  - lib/zillabyte/cli/templates/apps/ruby/Gemfile
200
190
  - lib/zillabyte/cli/templates/apps/ruby/README.md
201
- - lib/zillabyte/cli/templates/apps/ruby/app.rb.erb
202
191
  - lib/zillabyte/cli/templates/apps/ruby/zillabyte.conf.yaml
203
192
  - lib/zillabyte/cli/templates/components/js/simple_function.js
204
193
  - lib/zillabyte/cli/templates/components/js/zillabyte.conf.yaml
205
194
  - lib/zillabyte/cli/templates/components/python/component.py
206
195
  - lib/zillabyte/cli/templates/components/python/requirements.txt
207
196
  - lib/zillabyte/cli/templates/components/python/zillabyte.conf.yaml
208
- - lib/zillabyte/cli/templates/components/ruby/Gemfile
209
197
  - lib/zillabyte/cli/templates/components/ruby/component.rb.erb
198
+ - lib/zillabyte/cli/templates/components/ruby/Gemfile
210
199
  - lib/zillabyte/cli/templates/components/ruby/zillabyte.conf.yaml
211
- - lib/zillabyte/cli/templates/python/#simple_function.py#
212
200
  - lib/zillabyte/cli/untitled.md
213
201
  - lib/zillabyte/cli/version.rb
214
202
  - lib/zillabyte/cli/zillalogs.rb
203
+ - lib/zillabyte/cli.rb
215
204
  - lib/zillabyte/command.rb
216
- - lib/zillabyte/common.rb
217
205
  - lib/zillabyte/common/log_fetcher.rb
218
206
  - lib/zillabyte/common/session.rb
219
207
  - lib/zillabyte/common/tar.rb
208
+ - lib/zillabyte/common.rb
220
209
  - lib/zillabyte/helpers.rb
221
- - lib/zillabyte/queries.rb
222
- - lib/zillabyte/runner.rb
223
210
  - lib/zillabyte/runner/app_runner.rb
224
211
  - lib/zillabyte/runner/component_operation.rb
225
212
  - lib/zillabyte/runner/component_runner.rb
226
213
  - lib/zillabyte/runner/multilang_operation.rb
227
214
  - lib/zillabyte/runner/operation.rb
228
- - zillabyte-cli.gemspec
215
+ - lib/zillabyte/runner.rb
216
+ - lib/zillabyte-cli/version.rb
217
+ - lib/zillabyte-cli.rb
218
+ - LICENSE
219
+ - README.md
229
220
  - zillabyte_emails.csv
230
221
  - zillaconf.json
222
+ - Gemfile
223
+ - zillabyte-cli.gemspec
231
224
  homepage: http://www.zillabyte.com
232
225
  licenses:
233
226
  - MIT
234
227
  metadata: {}
235
- post_install_message: |2
236
-
237
- Getting Started with Zillabyte
238
- ==============================
239
-
240
- (1) Register for an auth token at http://zillabyte.com
241
- (2) Log in by running 'zillabyte login' in the command line
242
- (3) Build an empty app by running 'zillabyte apps:init'
243
- Or... check out our Quick Starts by visiting http://docs.zillabyte.com/
244
-
245
- Questions, comments? Please visit us at http://docs.zillabyte.com
228
+ post_install_message: ! "\nGetting Started with Zillabyte\n==============================\n\n(1)
229
+ Register for an auth token at http://zillabyte.com\n(2) Log in by running 'zillabyte
230
+ login' in the command line\n(3) Build an empty app by running 'zillabyte apps:init'\n
231
+ \ Or... check out our Quick Starts by visiting http://docs.zillabyte.com/\n\nQuestions,
232
+ comments? Please visit us at http://docs.zillabyte.com\n"
246
233
  rdoc_options: []
247
234
  require_paths:
248
235
  - lib
249
236
  required_ruby_version: !ruby/object:Gem::Requirement
250
237
  requirements:
251
- - - ">="
238
+ - - ! '>='
252
239
  - !ruby/object:Gem::Version
253
240
  version: '0'
254
241
  required_rubygems_version: !ruby/object:Gem::Requirement
255
242
  requirements:
256
- - - ">="
243
+ - - ! '>='
257
244
  - !ruby/object:Gem::Version
258
245
  version: '0'
259
246
  requirements: []
260
247
  rubyforge_project:
261
- rubygems_version: 2.2.2
248
+ rubygems_version: 2.0.7
262
249
  signing_key:
263
250
  specification_version: 4
264
251
  summary: The Official Zillabyte CLI Gem
@@ -1,5 +0,0 @@
1
- require "zillabyte-cli/version"
2
- require "zillabyte/api"
3
- require "zillabyte/cli"
4
- require "zillabyte/common"
5
- require "zillabyte/queries"
@@ -1,83 +0,0 @@
1
- require("zillabyte/api/base")
2
-
3
- class Zillabyte::API::Queries < Zillabyte::API::Base
4
-
5
-
6
- # GET /sxp
7
- def sxp(expression, method, options = {})
8
-
9
- options = {
10
- 'sxp' => expression
11
- }.merge(options)
12
-
13
- res = request(
14
- :expects => 200,
15
- :method => method,
16
- :path => "/query_sxp",
17
- :body => options.to_json
18
- )
19
-
20
- res.body
21
-
22
- end
23
-
24
- def pull_to_s3(query, options)
25
- options = {
26
- 'query' => query
27
- }.merge(options)
28
-
29
- res = @api.request(
30
- :expects => 200,
31
- :method => :post,
32
- :path => "/query_pull_to_s3",
33
- :body => options.to_json
34
- )
35
- res.body
36
- end
37
-
38
-
39
- # GET /sql
40
- def sql(expression, method, options = {})
41
-
42
- options = {
43
- 'sql' => expression
44
- }.merge(options)
45
-
46
- res = request(
47
- :expects => 200,
48
- :method => method,
49
- :path => "/query_sql",
50
- :body => options.to_json
51
- )
52
-
53
- res.body
54
-
55
- end
56
-
57
-
58
-
59
- def agnostic(expression, options = {})
60
- case expression
61
- when Array
62
- res = sxp(expression, :post, options)
63
- when String
64
- res = sql(expression, :post, options)
65
- col_aliases = res["column_aliases"] #save the column aliases
66
- else
67
- throw "unknown expression type: #{expression}"
68
- end
69
-
70
- options[:job_id] = res["job_id"]
71
- res = {'status' => nil}
72
- while(res['status'] != 'completed')
73
- res = sql(expression, :get, options)
74
- sleep(1) if res['status'] != 'completed'
75
- end
76
- res["return"]["column_aliases"] = col_aliases if col_aliases #send the column aliases back too
77
- res["return"]
78
- end
79
-
80
-
81
-
82
-
83
- end
@@ -1,12 +0,0 @@
1
- require "zillabyte/cli/base"
2
-
3
- # manage custom logs
4
- #
5
- class Zillabyte::Command::Logs < Zillabyte::Command::Base
6
-
7
-
8
-
9
-
10
-
11
-
12
- end
@@ -1,43 +0,0 @@
1
- require "zillabyte/cli/base"
2
- require 'readline'
3
- # REPL console for zillabyte commands
4
- #
5
- class Zillabyte::Command::Repl < Zillabyte::Command::Base
6
-
7
- # repl
8
- #
9
- # start a console session for zillabyte
10
- # --quiet # HIDDEN
11
- # --history HISTORY# HIDDEN hack to allow history for readline
12
- def index
13
- if !options[:quiet]
14
- v = `zillabyte version`
15
- display "\n#{v}Type q,exit or Ctrl+D to quit\n\n"
16
- end
17
- server = `echo $ZILLABYTE_API_HOST` || ""
18
- prompt = ""
19
- if server && server.chomp.length > 0
20
- prompt = "#{server.chomp} "
21
- end
22
- prompt += "zillabyte $ "
23
- if options[:history]
24
- #p options[:history]
25
- history = JSON.parse(options[:history])
26
- history.last(50).each do |his|
27
- # TODO: Handle single quotes ??
28
- Readline::HISTORY << his
29
- end
30
- end
31
- # TODO: Add tab completion for basic commands, app/relation names etc.
32
- while cmd = Readline.readline(prompt, true)
33
- if cmd && cmd.length > 0
34
- if cmd.downcase == "exit" || cmd.downcase == "q"
35
- display "" # TODO Make Ctrl+D print a newline too
36
- return
37
- else
38
- exec "zillabyte #{cmd}; zillabyte repl --quiet --history '#{Readline::HISTORY.to_a.to_json}'"
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,322 +0,0 @@
1
- require "zillabyte/cli/base"
2
- require("zillabyte/cli/helpers/table_output_builder")
3
-
4
- # executes queries
5
- #
6
- class Zillabyte::Command::Query < Zillabyte::Command::Base
7
-
8
- MAX_POLL_SECONDS = 60 * 5
9
- POLL_SLEEP = 1
10
-
11
- # query:sxp EXPRESSION
12
- #
13
- # Executes SXP queries against the zillabyte corpus.
14
- #
15
- # -o, --offset OFFSET # Skips to the offset [default: 0]
16
- # -l, --limit LIMIT # Sets the result limit [default: 20]
17
- # -t, --tail TAIL # Continuously watches for new results
18
- # --meta # Show meta columns (since, confidence, source)
19
- # --output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
20
- #
21
- #Examples:
22
- #
23
- # $ zillabyte query:sxp "(uses company 'web_css')" --limit 100
24
- #
25
- def sxp
26
-
27
- opts = {}
28
- opts[:offset] = options[:offset] || 0
29
- opts[:limit] = options[:limit] || 10
30
- type = options[:output_type]
31
- show_meta = options[:meta] || false
32
- tail = options[:tail] || false
33
- expression = options[:expression] || shift_argument
34
- opts[:since] = options[:since]
35
-
36
- if expression.nil?
37
- error("no expression given", type)
38
- end
39
-
40
- seen = {}
41
-
42
- begin
43
-
44
- validate_arguments!
45
- res = api.query.sxp(expression, :post, opts)
46
-
47
- if res['job_id']
48
- job_id = res['job_id']
49
- opts[:job_id] = job_id
50
-
51
- start = Time.now.utc
52
- display "Fetching your data, please wait..." if type.nil?
53
-
54
- while(Time.now.utc < start + MAX_POLL_SECONDS) do
55
-
56
- res = api.query.sxp(expression, :get, opts)
57
- case res['status']
58
- when 'completed'
59
- if(res['return'])
60
- res = res['return']
61
- else
62
- error("something is wrong #{res}", type)
63
- end
64
- # success! continue below
65
- break
66
- when 'running'
67
- sleep(POLL_SLEEP)
68
- else
69
- error("unknown status: #{res}", type)
70
- end
71
-
72
- end
73
- else
74
- if res['error']
75
- error(res['error_message'] || res['error'], type)
76
- else
77
- error("remote server error(r256)", type)
78
- end
79
- end
80
-
81
- filtered = []
82
- headings = []
83
- if res['results'].first
84
- headings = res['results'].first.keys
85
- META_COLUMNS.each {|c| concrete_headings.delete c} if (!show_meta)
86
- rows = res['results'].each do |obj|
87
- new_row = headings.map do |heading|
88
- obj[heading]
89
- end
90
- unless seen[new_row.to_s]
91
- filtered << new_row
92
- seen[new_row.to_s] = true
93
- end
94
- end
95
- end
96
-
97
- if filtered.size > 0
98
- display TableOutputBuilder.build_table(headings, filtered)
99
- else
100
- unless tail
101
- display "no results" if type.nil?
102
- end
103
- end
104
-
105
- opts[:since] = DateTime.now
106
-
107
- end while (tail && sleep(5))
108
-
109
- end
110
- alias_command "sxp", "query:sxp"
111
-
112
-
113
-
114
-
115
- # query:sql EXPRESSION
116
- #
117
- # Executes SQL queries against the zillabyte corpus.
118
- #
119
- # -o, --offset OFFSET # Skips to the offset [default: 0]
120
- # -l, --limit LIMIT # Sets the result limit [default: 20]
121
- # -t, --tail TAIL # Continuously watches for new results
122
- # -s, --since SINCE # Grab newer records since SINCE
123
- # --no_truncation # Doesn't truncate long strings
124
- # --meta # Show meta columns (since, confidence, source)
125
- # --output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
126
- #
127
- #Examples:
128
- #
129
- # $ zillabyte query:sql "select * from company" --limit 100
130
- #
131
- def sql
132
-
133
- opts = {}
134
- opts[:offset] = options[:offset] || 0
135
- opts[:limit] = options[:limit] || 10
136
-
137
- tail = options[:tail] || false
138
- expression = options[:expression] || shift_argument
139
- opts[:since] = options[:since]
140
- show_meta = options[:meta] || false
141
- type = options[:output_type]
142
- seen = {}
143
-
144
- if expression.nil?
145
- error("no expression given", type)
146
- end
147
-
148
- begin
149
-
150
- validate_arguments!
151
- res = api.query.sql(expression, :post, opts)
152
-
153
- if res['job_id']
154
- job_id = res['job_id']
155
- opts[:job_id] = job_id
156
-
157
- start = Time.now.utc
158
-
159
- col_aliases = res['column_aliases']
160
- while(Time.now.utc < start + MAX_POLL_SECONDS) do
161
-
162
- res = api.query.sql(expression, :get, opts)
163
- case res['status']
164
- when 'completed'
165
- if(res['return'])
166
- res = res['return']
167
- else
168
- throw "something is wrong: #{res}"
169
- end
170
- # success! continue below
171
- break
172
- when 'running'
173
- sleep(POLL_SLEEP)
174
- # display ".", false
175
- else
176
- throw "unknown status: #{res}"
177
- end
178
-
179
- end
180
- else
181
- if res['error']
182
- error(res['error_message'] || res['error'], type)
183
- else
184
- error("remote server error(r256)", type)
185
- end
186
- end
187
-
188
- headings = []
189
- filtered = []
190
- if res['rows'] && res['rows'].first
191
- concrete_headings = res['rows'].first.keys
192
- META_COLUMNS.each {|c| concrete_headings.delete c} if (!show_meta)
193
- concrete_headings.each do |ch|
194
- has_alias = false
195
- col_aliases.each do |al|
196
- if(al["concrete_name"] == ch)
197
- headings << al["alias"]
198
- has_alias = true
199
- end
200
- end
201
- headings << ch if !has_alias
202
- end
203
- rows = res['rows'].each do |obj|
204
- # if obj['since']
205
- # opts[:since] = [obj['since'], opts[:since]].compact.max
206
- # end
207
-
208
- new_row = concrete_headings.map do |heading|
209
- if options[:no_truncation]
210
- obj[heading]
211
- else
212
- if obj[heading].to_s.size > 30
213
- obj[heading].to_s[0..30] + "..."
214
- else
215
- obj[heading]
216
- end
217
- end
218
- end
219
-
220
- unless seen[new_row.to_s]
221
- filtered << new_row
222
- seen[new_row.to_s] = true
223
- end
224
- end
225
- end
226
-
227
- if filtered.size > 0
228
- opts[:since] = Time.now.utc
229
- display TableOutputBuilder.build_table(headings, filtered, type)
230
-
231
- else
232
- unless tail
233
- if type == "json"
234
- display {}.to_json
235
- else
236
- display "no results"
237
- end
238
- end
239
- end
240
-
241
-
242
- end while (tail && sleep(5))
243
-
244
- end
245
- alias_command "sql", "query:sql"
246
-
247
-
248
-
249
-
250
- # query:pull QUERY FILE
251
- #
252
- # Executes a query and downloads the results to FILE.
253
- #
254
- def pull
255
-
256
- query = options[:query] || shift_argument
257
- file = options[:file] || shift_argument
258
- type = options[:output_type]
259
- error("no query given", type) if query.nil?
260
- error("no file given", type) if file.nil?
261
- file = "#{file}.gz" unless File.extname(file) == ".gz"
262
-
263
- options[:query] = query
264
-
265
- res = api.request(
266
- :expects => 200,
267
- :method => :post,
268
- :path => "/query_pull",
269
- :body => options.to_json
270
- )
271
- res = res.body
272
-
273
- handle_downloading_manifest(file, res, type)
274
-
275
- if type == "json"
276
- display "{}"
277
- else
278
- display "finished downloading results to file"
279
- end
280
-
281
- end
282
- alias_command "sql:pull", "query:pull"
283
-
284
-
285
-
286
- # query:pull:s3 QUERY S3_KEY S3_SECRET S3_BUCKET s3_FILE_KEY
287
- #
288
- # Executes a query and pulls data to S3_BUCKET/FILE_KEY/part***.gz.
289
- #
290
- # --output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN
291
- #
292
- def pull_to_s3
293
-
294
- query = options[:query] || shift_argument
295
- error("query cannot be empty", type) if query.nil?
296
-
297
- type = options[:output_type]
298
-
299
- user_s3_access_key = options[:s3_access_key] || shift_argument
300
- user_s3_secret = options[:s3_secret] || shift_argument
301
- user_s3_bucket = options[:s3_bucket] || shift_argument
302
- user_s3_file_key = options[:s3_file_key] || shift_argument
303
- error("no s3 access key provided", type) if user_s3_access_key.nil?
304
- error("no s3 secret provided", type) if user_s3_secret.nil?
305
- error("no s3 bucket provided", type) if user_s3_bucket.nil?
306
- error("no s3 file path specified", type) if user_s3_file_key.nil?
307
-
308
- s3_params = {:s3_access_key => user_s3_access_key, :s3_secret => user_s3_secret,
309
- :s3_bucket => user_s3_bucket, :s3_file_key => user_s3_file_key}
310
-
311
- res = self.api.queries.pull_to_s3(query, s3_params)
312
-
313
- if type == "json"
314
- display {}.to_json
315
- else
316
- display "downloading query results to s3://#{res["s3_bucket"]}/#{res["s3_file_key"]}/"
317
- display "if the dataset is large, this may take a while, please check your s3 account after a few minutes"
318
- end
319
- end
320
- alias_command "query:pull:s3", "query:pull_to_s3"
321
-
322
- end
@@ -1,27 +0,0 @@
1
- import zillabyte
2
-
3
- def prep(controller):
4
- return
5
-
6
- # This is the heart of your algorithm. It's processed on every
7
- # web page. This algorithm is run in parallel on possibly hundreds
8
- # of machines.
9
- def execute(controller, tup):
10
- if("hello world" in tup.values["html"]):
11
- controller.emit("has_hello_world",{"url":tup.values["url"]})
12
- return
13
-
14
- zillabyte.simple_function(\
15
- # This directive instructs zillabyte to give your function every
16
- # web page in our known universe. Your function will have access
17
- # to two fields: URL and HTML
18
- matches = "select * from web_pa", \
19
-
20
- # This directive tells Zillabyte what kind of data your function
21
- # produces. In this case, we're saying we will emit a tuple that
22
- # is one-column wide and contains the field 'URL'
23
- emits = [["has_hello_world", [{"url":"string"}]]], \
24
-
25
- prepare = prep, \
26
- execute = execute\
27
- )
@@ -1,39 +0,0 @@
1
- module Zillabyte::Queries
2
-
3
-
4
-
5
- def self.array_to_sxp_expression(exp)
6
- s = []
7
- s << "("
8
- s << exp[0]
9
- exp[1].each do |ss|
10
- s << " "
11
- s << ss
12
- end
13
- s << ")"
14
- s = s.join("")
15
- end
16
-
17
-
18
- def self.convert_clause_to_sxp(match)
19
- return nil if match.nil? or match.size == 0
20
- queue = match.clone
21
- s = array_to_sxp_expression(queue.shift)
22
- while queue.size > 0
23
- next_exp = array_to_sxp_expression(queue.shift)
24
- s = "(and #{s} #{next_exp})"
25
- end
26
- s
27
- end
28
-
29
- # def self.load
30
- # Dir[File.join(File.dirname(__FILE__), "functions", "*.rb")].each do |file|
31
- # require file
32
- # end
33
- # end
34
- end
35
-
36
-
37
- # Load all helpers...
38
- # Zillabyte::Functions.load()
39
-