presto-client 0.4.17 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,11 +48,17 @@ module Presto::Client
48
48
  @closed = false
49
49
  @exception = nil
50
50
 
51
+ if model_version = @options[:model_version]
52
+ @models = ModelVersions.const_get("V#{model_version.gsub(".", "_")}")
53
+ else
54
+ @models = Models
55
+ end
56
+
51
57
  @faraday.headers.merge!(optional_headers)
52
58
 
53
59
  if next_uri
54
60
  body = faraday_get_with_retry(next_uri)
55
- @results = Models::QueryResults.decode(MultiJson.load(body))
61
+ @results = @models::QueryResults.decode(MultiJson.load(body))
56
62
  else
57
63
  post_query_request!
58
64
  end
@@ -108,7 +114,7 @@ module Presto::Client
108
114
  end
109
115
 
110
116
  body = response.body
111
- @results = load_json(uri, body, Models::QueryResults)
117
+ @results = load_json(uri, body, @models::QueryResults)
112
118
  end
113
119
 
114
120
  private :post_query_request!
@@ -152,7 +158,7 @@ module Presto::Client
152
158
  uri = @results.next_uri
153
159
 
154
160
  body = faraday_get_with_retry(uri)
155
- @results = load_json(uri, body, Models::QueryResults)
161
+ @results = load_json(uri, body, @models::QueryResults)
156
162
 
157
163
  return true
158
164
  end
@@ -160,7 +166,7 @@ module Presto::Client
160
166
  def query_info
161
167
  uri = "/v1/query/#{@results.id}"
162
168
  body = faraday_get_with_retry(uri)
163
- load_json(uri, body, Models::QueryInfo)
169
+ load_json(uri, body, @models::QueryInfo)
164
170
  end
165
171
 
166
172
  def load_json(uri, body, body_class)
@@ -15,6 +15,6 @@
15
15
  #
16
16
  module Presto
17
17
  module Client
18
- VERSION = "0.4.17"
18
+ VERSION = "0.5.0"
19
19
  end
20
20
  end
@@ -0,0 +1,247 @@
1
+ #
2
+ # Presto client for Ruby
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ module Presto::Client::ModelVersions
17
+
18
+ ####
19
+ ## lib/presto/client/model_versions/*.rb is automatically generated using "rake modelgen:all" command.
20
+ ## You should not edit this file directly. To modify the class definitions, edit
21
+ ## modelgen/model_versions.rb file and run "rake modelgen:all".
22
+ ##
23
+
24
+ module V<%= @model_version.gsub(".", "_") %>
25
+ class Base < Struct
26
+ class << self
27
+ alias_method :new_struct, :new
28
+
29
+ def new(*args)
30
+ new_struct(*args) do
31
+ # make it immutable
32
+ undef_method :"[]="
33
+ members.each do |m|
34
+ undef_method :"#{m}="
35
+ end
36
+
37
+ # replace constructor to receive hash instead of array
38
+ alias_method :initialize_struct, :initialize
39
+
40
+ def initialize(params={})
41
+ initialize_struct(*members.map {|m| params[m] })
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ class StageId < String
49
+ def initialize(str)
50
+ super
51
+ splitted = split('.', 2)
52
+ @query_id = splitted[0]
53
+ @id = splitted[1]
54
+ end
55
+
56
+ attr_reader :query_id, :id
57
+ end
58
+
59
+ class TaskId < String
60
+ def initialize(str)
61
+ super
62
+ splitted = split('.', 3)
63
+ @stage_id = StageId.new("#{splitted[0]}.#{splitted[1]}")
64
+ @query_id = @stage_id.query_id
65
+ @id = splitted[2]
66
+ end
67
+
68
+ attr_reader :query_id, :stage_id, :id
69
+ end
70
+
71
+ class ConnectorSession < Hash
72
+ def initialize(hash)
73
+ super()
74
+ merge!(hash)
75
+ end
76
+ end
77
+
78
+ module PlanNode
79
+ def self.decode(hash)
80
+ unless hash.is_a?(Hash)
81
+ raise TypeError, "Can't convert #{hash.class} to Hash"
82
+ end
83
+ model_class = case hash["@type"]
84
+ when "output" then OutputNode
85
+ when "project" then ProjectNode
86
+ when "tablescan" then TableScanNode
87
+ when "values" then ValuesNode
88
+ when "aggregation" then AggregationNode
89
+ when "markDistinct" then MarkDistinctNode
90
+ when "filter" then FilterNode
91
+ when "window" then WindowNode
92
+ when "rowNumber" then RowNumberNode
93
+ when "topnRowNumber" then TopNRowNumberNode
94
+ when "limit" then LimitNode
95
+ when "distinctlimit" then DistinctLimitNode
96
+ when "topn" then TopNNode
97
+ when "sample" then SampleNode
98
+ when "sort" then SortNode
99
+ when "remoteSource" then RemoteSourceNode
100
+ when "join" then JoinNode
101
+ when "semijoin" then SemiJoinNode
102
+ when "indexjoin" then IndexJoinNode
103
+ when "indexsource" then IndexSourceNode
104
+ when "tablewriter" then TableWriterNode
105
+ when "delete" then DeleteNode
106
+ when "metadatadelete" then MetadataDeleteNode
107
+ when "tablecommit" then TableFinishNode
108
+ when "unnest" then UnnestNode
109
+ when "exchange" then ExchangeNode
110
+ when "union" then UnionNode
111
+ when "intersect" then IntersectNode
112
+ when "scalar" then EnforceSingleRowNode
113
+ when "groupid" then GroupIdNode
114
+ when "explainAnalyze" then ExplainAnalyzeNode
115
+ when "apply" then ApplyNode
116
+ end
117
+ if model_class
118
+ node = model_class.decode(hash)
119
+ class << node
120
+ attr_accessor :plan_node_type
121
+ end
122
+ node.plan_node_type = hash['@type']
123
+ node
124
+ end
125
+ end
126
+ end
127
+
128
+ # io.airlift.stats.Distribution.DistributionSnapshot
129
+ class << DistributionSnapshot =
130
+ Base.new(:max_error, :count, :total, :p01, :p05, :p10, :p25, :p50, :p75, :p90, :p95, :p99, :min, :max)
131
+ def decode(hash)
132
+ unless hash.is_a?(Hash)
133
+ raise TypeError, "Can't convert #{hash.class} to Hash"
134
+ end
135
+ obj = allocate
136
+ obj.send(:initialize_struct,
137
+ hash["maxError"],
138
+ hash["count"],
139
+ hash["total"],
140
+ hash["p01"],
141
+ hash["p05"],
142
+ hash["p10"],
143
+ hash["p25"],
144
+ hash["p50"],
145
+ hash["p75"],
146
+ hash["p90"],
147
+ hash["p95"],
148
+ hash["p99"],
149
+ hash["min"],
150
+ hash["max"],
151
+ )
152
+ obj
153
+ end
154
+ end
155
+
156
+ # This is a hybrid of JoinNode.EquiJoinClause and IndexJoinNode.EquiJoinClause
157
+ class << EquiJoinClause =
158
+ Base.new(:left, :right, :probe, :index)
159
+ def decode(hash)
160
+ unless hash.is_a?(Hash)
161
+ raise TypeError, "Can't convert #{hash.class} to Hash"
162
+ end
163
+ obj = allocate
164
+ obj.send(:initialize_struct,
165
+ hash["left"],
166
+ hash["right"],
167
+ hash["probe"],
168
+ hash["index"],
169
+ )
170
+ obj
171
+ end
172
+ end
173
+
174
+ class << WriterTarget =
175
+ Base.new(:type, :handle)
176
+ def decode(hash)
177
+ unless hash.is_a?(Hash)
178
+ raise TypeError, "Can't convert #{hash.class} to Hash"
179
+ end
180
+ obj = allocate
181
+ model_class = case hash["@type"]
182
+ when "CreateHandle" then OutputTableHandle
183
+ when "InsertHandle" then InsertTableHandle
184
+ when "DeleteHandle" then TableHandle
185
+ end
186
+ obj.send(:initialize_struct,
187
+ hash["@type"],
188
+ model_class.decode(hash['handle'])
189
+ )
190
+ obj
191
+ end
192
+ end
193
+
194
+ class << DeleteHandle =
195
+ Base.new(:handle)
196
+ def decode(hash)
197
+ unless hash.is_a?(Hash)
198
+ raise TypeError, "Can't convert #{hash.class} to Hash"
199
+ end
200
+ obj = allocate
201
+ obj.send(:initialize_struct,
202
+ TableHandle.decode(hash['handle'])
203
+ )
204
+ obj
205
+ end
206
+ end
207
+
208
+ # Inner classes
209
+ class << Specification =
210
+ Base.new(:partition_by, :order_by, :orderings, :frame, :pages_added)
211
+ def decode(hash)
212
+ unless hash.is_a?(Hash)
213
+ raise TypeError, "Can't convert #{hash.class} to Hash"
214
+ end
215
+ obj = allocate
216
+ obj.send(:initialize_struct,
217
+ hash["partitionBy"],
218
+ hash["orderBy"],
219
+ hash["orderings"],
220
+ hash["frame"],
221
+ )
222
+ obj
223
+ end
224
+ end
225
+
226
+ class << ArgumentBinding =
227
+ Base.new(:column, :constant)
228
+ def decode(hash)
229
+ unless hash.is_a?(Hash)
230
+ raise TypeError, "Can't convert #{hash.class} to Hash"
231
+ end
232
+ obj = allocate
233
+ obj.send(:initialize_struct,
234
+ hash["column"],
235
+ hash["constant"]
236
+ )
237
+ obj
238
+ end
239
+ end
240
+
241
+ ##
242
+ # Those model classes are automatically generated
243
+ #
244
+
245
+ <%= @contents %>
246
+ end
247
+ end
data/modelgen/modelgen.rb CHANGED
@@ -1,9 +1,10 @@
1
1
 
2
- if ARGV.length != 3
3
- puts "usage: <presto-source-dir> <template.erb> <output.rb>"
2
+ if ARGV.length != 4
3
+ puts "usage: <model-version> <presto-source-dir> <template.erb> <output.rb>"
4
+ exit 1
4
5
  end
5
6
 
6
- source_dir, template_path, output_path = *ARGV
7
+ model_version, source_dir, template_path, output_path = *ARGV
7
8
 
8
9
  require_relative 'presto_models'
9
10
 
@@ -89,7 +90,8 @@ formatter = PrestoModels::ModelFormatter.new(
89
90
  formatter.format(models)
90
91
 
91
92
  @contents = formatter.contents
93
+ @model_version = model_version
92
94
 
93
95
  data = erb.result
94
- File.open(output_path, 'w') {|f| f.write data }
96
+ File.write(output_path, data)
95
97
 
data/modelgen/models.rb CHANGED
@@ -16,232 +16,16 @@
16
16
  module Presto::Client
17
17
 
18
18
  ####
19
- ## lib/presto/client/models.rb is automatically generated using "rake modelgen" command.
19
+ ## lib/presto/client/models.rb is automatically generated using "rake modelgen:latest" command.
20
20
  ## You should not edit this file directly. To modify the class definitions, edit
21
- ## modelgen/models.rb file and run "rake modelgen".
21
+ ## modelgen/models.rb file and run "rake modelgen:latest".
22
22
  ##
23
23
 
24
- module Models
25
- class Base < Struct
26
- class << self
27
- alias_method :new_struct, :new
28
-
29
- def new(*args)
30
- new_struct(*args) do
31
- # make it immutable
32
- undef_method :"[]="
33
- members.each do |m|
34
- undef_method :"#{m}="
35
- end
36
-
37
- # replace constructor to receive hash instead of array
38
- alias_method :initialize_struct, :initialize
39
-
40
- def initialize(params={})
41
- initialize_struct(*members.map {|m| params[m] })
42
- end
43
- end
44
- end
45
- end
46
- end
47
-
48
- class StageId < String
49
- def initialize(str)
50
- super
51
- splitted = split('.', 2)
52
- @query_id = splitted[0]
53
- @id = splitted[1]
54
- end
55
-
56
- attr_reader :query_id, :id
57
- end
58
-
59
- class TaskId < String
60
- def initialize(str)
61
- super
62
- splitted = split('.', 3)
63
- @stage_id = StageId.new("#{splitted[0]}.#{splitted[1]}")
64
- @query_id = @stage_id.query_id
65
- @id = splitted[2]
66
- end
67
-
68
- attr_reader :query_id, :stage_id, :id
69
- end
70
-
71
- class ConnectorSession < Hash
72
- def initialize(hash)
73
- super()
74
- merge!(hash)
75
- end
76
- end
77
-
78
- module PlanNode
79
- def self.decode(hash)
80
- unless hash.is_a?(Hash)
81
- raise TypeError, "Can't convert #{hash.class} to Hash"
82
- end
83
- model_class = case hash["@type"]
84
- when "output" then OutputNode
85
- when "project" then ProjectNode
86
- when "tablescan" then TableScanNode
87
- when "values" then ValuesNode
88
- when "aggregation" then AggregationNode
89
- when "markDistinct" then MarkDistinctNode
90
- when "filter" then FilterNode
91
- when "window" then WindowNode
92
- when "rowNumber" then RowNumberNode
93
- when "topnRowNumber" then TopNRowNumberNode
94
- when "limit" then LimitNode
95
- when "distinctlimit" then DistinctLimitNode
96
- when "topn" then TopNNode
97
- when "sample" then SampleNode
98
- when "sort" then SortNode
99
- when "remoteSource" then RemoteSourceNode
100
- when "join" then JoinNode
101
- when "semijoin" then SemiJoinNode
102
- when "indexjoin" then IndexJoinNode
103
- when "indexsource" then IndexSourceNode
104
- when "tablewriter" then TableWriterNode
105
- when "delete" then DeleteNode
106
- when "metadatadelete" then MetadataDeleteNode
107
- when "tablecommit" then TableFinishNode
108
- when "unnest" then UnnestNode
109
- when "exchange" then ExchangeNode
110
- when "union" then UnionNode
111
- when "intersect" then IntersectNode
112
- when "scalar" then EnforceSingleRowNode
113
- when "groupid" then GroupIdNode
114
- when "explainAnalyze" then ExplainAnalyzeNode
115
- when "apply" then ApplyNode
116
- end
117
- if model_class
118
- node = model_class.decode(hash)
119
- class << node
120
- attr_accessor :plan_node_type
121
- end
122
- node.plan_node_type = hash['@type']
123
- node
124
- end
125
- end
126
- end
127
-
128
- # io.airlift.stats.Distribution.DistributionSnapshot
129
- class << DistributionSnapshot =
130
- Base.new(:max_error, :count, :total, :p01, :p05, :p10, :p25, :p50, :p75, :p90, :p95, :p99, :min, :max)
131
- def decode(hash)
132
- unless hash.is_a?(Hash)
133
- raise TypeError, "Can't convert #{hash.class} to Hash"
134
- end
135
- obj = allocate
136
- obj.send(:initialize_struct,
137
- hash["maxError"],
138
- hash["count"],
139
- hash["total"],
140
- hash["p01"],
141
- hash["p05"],
142
- hash["p10"],
143
- hash["p25"],
144
- hash["p50"],
145
- hash["p75"],
146
- hash["p90"],
147
- hash["p95"],
148
- hash["p99"],
149
- hash["min"],
150
- hash["max"],
151
- )
152
- obj
153
- end
154
- end
155
-
156
- # This is a hybrid of JoinNode.EquiJoinClause and IndexJoinNode.EquiJoinClause
157
- class << EquiJoinClause =
158
- Base.new(:left, :right, :probe, :index)
159
- def decode(hash)
160
- unless hash.is_a?(Hash)
161
- raise TypeError, "Can't convert #{hash.class} to Hash"
162
- end
163
- obj = allocate
164
- obj.send(:initialize_struct,
165
- hash["left"],
166
- hash["right"],
167
- hash["probe"],
168
- hash["index"],
169
- )
170
- obj
171
- end
172
- end
173
-
174
- class << WriterTarget =
175
- Base.new(:type, :handle)
176
- def decode(hash)
177
- unless hash.is_a?(Hash)
178
- raise TypeError, "Can't convert #{hash.class} to Hash"
179
- end
180
- obj = allocate
181
- model_class = case hash["@type"]
182
- when "CreateHandle" then OutputTableHandle
183
- when "InsertHandle" then InsertTableHandle
184
- when "DeleteHandle" then TableHandle
185
- end
186
- obj.send(:initialize_struct,
187
- hash["@type"],
188
- model_class.decode(hash['handle'])
189
- )
190
- obj
191
- end
192
- end
193
-
194
- class << DeleteHandle =
195
- Base.new(:handle)
196
- def decode(hash)
197
- unless hash.is_a?(Hash)
198
- raise TypeError, "Can't convert #{hash.class} to Hash"
199
- end
200
- obj = allocate
201
- obj.send(:initialize_struct,
202
- TableHandle.decode(hash['handle'])
203
- )
204
- obj
205
- end
206
- end
207
-
208
- # Inner classes
209
- class << Specification =
210
- Base.new(:partition_by, :order_by, :orderings, :frame, :pages_added)
211
- def decode(hash)
212
- unless hash.is_a?(Hash)
213
- raise TypeError, "Can't convert #{hash.class} to Hash"
214
- end
215
- obj = allocate
216
- obj.send(:initialize_struct,
217
- hash["partitionBy"],
218
- hash["orderBy"],
219
- hash["orderings"],
220
- hash["frame"],
221
- )
222
- obj
223
- end
224
- end
225
-
226
- class << ArgumentBinding =
227
- Base.new(:column, :constant)
228
- def decode(hash)
229
- unless hash.is_a?(Hash)
230
- raise TypeError, "Can't convert #{hash.class} to Hash"
231
- end
232
- obj = allocate
233
- obj.send(:initialize_struct,
234
- hash["column"],
235
- hash["constant"]
236
- )
237
- obj
238
- end
239
- end
24
+ module ModelVersions
25
+ end
26
+ <% @versions.each do |ver| %>
27
+ require 'presto/client/model_versions/<%= ver %>.rb'<% end %>
240
28
 
241
- ##
242
- # Those model classes are automatically generated
243
- #
29
+ Models = ModelVersions::V<%= @latest_version.gsub(".", "_") %>
244
30
 
245
- <%= @contents %>
246
- end
247
31
  end