trino-client 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,3 @@
1
-
2
1
  module TrinoModels
3
2
  require 'find'
4
3
  require 'stringio'
@@ -15,7 +14,7 @@ module TrinoModels
15
14
  alias_method :map?, :map
16
15
 
17
16
  def name
18
- @name ||= key.gsub(/[A-Z]/) {|f| "_#{f.downcase}" }
17
+ @name ||= key.gsub(/[A-Z]/) { |f| "_#{f.downcase}" }
19
18
  end
20
19
  end
21
20
 
@@ -23,7 +22,7 @@ module TrinoModels
23
22
  end
24
23
 
25
24
  class ModelAnalyzer
26
- def initialize(source_path, options={})
25
+ def initialize(source_path, options = {})
27
26
  @source_path = source_path
28
27
  @ignore_types = PRIMITIVE_TYPES + ARRAY_PRIMITIVE_TYPES + (options[:skip_models] || [])
29
28
  @path_mapping = options[:path_mapping] || {}
@@ -36,11 +35,11 @@ module TrinoModels
36
35
  attr_reader :skipped_models
37
36
 
38
37
  def models
39
- @models.values.sort_by {|model| model.name }
38
+ @models.values.sort_by { |model| model.name }
40
39
  end
41
40
 
42
41
  def analyze(root_models)
43
- root_models.each {|model_name|
42
+ root_models.each { |model_name|
44
43
  analyze_model(model_name)
45
44
  }
46
45
  end
@@ -54,7 +53,7 @@ module TrinoModels
54
53
  def analyze_fields(model_name, creator_block, generic: nil)
55
54
  model_name = "#{model_name}_#{generic}" if generic
56
55
  extra = @extra_fields[model_name] || []
57
- fields = creator_block.scan(PROPERTY_PATTERN).concat(extra).map do |key,nullable,type|
56
+ fields = creator_block.scan(PROPERTY_PATTERN).concat(extra).map do |key, nullable, type|
58
57
  map = false
59
58
  array = false
60
59
  nullable = !!nullable
@@ -84,10 +83,10 @@ module TrinoModels
84
83
  end
85
84
  base_type = @name_mapping[[model_name, base_type]] || base_type
86
85
  map_value_base_type = @name_mapping[[model_name, map_value_base_type]] || map_value_base_type
87
-
86
+
88
87
  if generic
89
88
  base_type = generic if base_type == 'T'
90
- map_value_base_type = generic if map_value_base_type == 'T'
89
+ map_value_base_type = generic if map_value_base_type == 'T'
91
90
  end
92
91
  if m = GENERIC_PATTERN.match(base_type)
93
92
  base_type_alias = "#{m[1]}_#{m[2]}"
@@ -103,10 +102,10 @@ module TrinoModels
103
102
  analyze_model(field.map_value_base_type, model_name) if field.map_value_base_type
104
103
  end
105
104
 
106
- return fields
105
+ fields
107
106
  end
108
107
 
109
- def analyze_model(model_name, parent_model= nil, generic: nil)
108
+ def analyze_model(model_name, parent_model = nil, generic: nil)
110
109
  return if @models[model_name] || @ignore_types.include?(model_name)
111
110
 
112
111
  if m = GENERIC_PATTERN.match(model_name)
@@ -123,7 +122,7 @@ module TrinoModels
123
122
  raise ModelAnalysisError, "Can't find JsonCreator of a model class #{model_name} of #{parent_model} at #{path}"
124
123
  end
125
124
 
126
- body = m[0]
125
+ body = m[0]
127
126
  # check inner class first
128
127
  while true
129
128
  offset = m.end(0)
@@ -146,12 +145,12 @@ module TrinoModels
146
145
 
147
146
  @source_files ||= Find.find(@source_path).to_a
148
147
  pattern = /\/#{model_name}.java$/
149
- matched = @source_files.find_all {|path| path =~ pattern && !path.include?('/test/') && !path.include?('/verifier/')}
148
+ matched = @source_files.find_all { |path| path =~ pattern && !path.include?('/test/') && !path.include?('/verifier/') }
150
149
  if matched.empty?
151
150
  raise ModelAnalysisError, "Model class #{model_name} is not found"
152
151
  end
153
152
  if matched.size == 1
154
- return matched.first
153
+ matched.first
155
154
  else
156
155
  raise ModelAnalysisError, "Model class #{model_name} of #{parent_model} found multiple match #{matched}"
157
156
  end
@@ -159,7 +158,7 @@ module TrinoModels
159
158
  end
160
159
 
161
160
  class ModelFormatter
162
- def initialize(options={})
161
+ def initialize(options = {})
163
162
  @indent = options[:indent] || ' '
164
163
  @base_indent_count = options[:base_indent_count] || 0
165
164
  @struct_class = options[:struct_class] || 'Struct'
@@ -182,7 +181,7 @@ module TrinoModels
182
181
  @model = model
183
182
 
184
183
  puts_with_indent 0, "class << #{model.name} ="
185
- puts_with_indent 2, "#{@struct_class}.new(#{model.fields.map {|f| ":#{f.name}" }.join(', ')})"
184
+ puts_with_indent 2, "#{@struct_class}.new(#{model.fields.map { |f| ":#{f.name}" }.join(', ')})"
186
185
  format_decode
187
186
  puts_with_indent 0, "end"
188
187
  line
@@ -220,7 +219,7 @@ module TrinoModels
220
219
  expr = "hash[\"#{field.key}\"]"
221
220
  else
222
221
  expr = ""
223
- expr << "hash[\"#{field.key}\"] && " #if field.nullable?
222
+ expr << "hash[\"#{field.key}\"] && " # if field.nullable?
224
223
 
225
224
  if field.map?
226
225
  key_expr = convert_expression(field.base_type, field.base_type, "k")
@@ -238,8 +237,8 @@ module TrinoModels
238
237
  end
239
238
  end
240
239
 
241
- #comment = "# #{field.base_type}#{field.array? ? '[]' : ''} #{field.key}"
242
- #puts_with_indent 3, "#{expr}, #{comment}"
240
+ # comment = "# #{field.base_type}#{field.array? ? '[]' : ''} #{field.key}"
241
+ # puts_with_indent 3, "#{expr}, #{comment}"
243
242
  puts_with_indent 3, "#{expr},"
244
243
  end
245
244
 
@@ -261,10 +260,9 @@ module TrinoModels
261
260
  key
262
261
  elsif @simple_classes.include?(base_type)
263
262
  "#{base_type}.new(#{key})"
264
- else # model class
263
+ else # model class
265
264
  "#{base_type}.decode(#{key})"
266
265
  end
267
266
  end
268
267
  end
269
268
  end
270
-
data/publish.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- require File.expand_path 'lib/trino/client/version', File.dirname(__FILE__)
2
+ require File.expand_path "lib/trino/client/version", File.dirname(__FILE__)
3
3
 
4
4
  def run(cmd)
5
5
  puts cmd
@@ -11,4 +11,3 @@ run("gem push trino-client-#{Trino::Client::VERSION}.gem")
11
11
 
12
12
  run("gem build trino-client-ruby/trino-client-ruby.gemspec")
13
13
  run("gem push trino-client-ruby/trino-client-ruby-#{Trino::Client::VERSION}.gem")
14
-
data/release.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'fileutils'
3
+ require "fileutils"
4
4
 
5
- PREFIX = 'https://github.com/treasure-data/trino-client-ruby'
5
+ PREFIX = "https://github.com/treasure-data/trino-client-ruby"
6
6
  RELEASE_NOTES_FILE = "ChangeLog.md"
7
7
 
8
8
  last_tag = `git describe --tags --abbrev=0`.chomp
@@ -19,10 +19,10 @@ logs = `git log #{last_tag}..HEAD --pretty=format:'%h %s'`
19
19
  logs = logs.gsub(/\#([0-9]+)/, "[#\\1](#{PREFIX}/issues/\\1)")
20
20
 
21
21
  new_release_notes = []
22
- new_release_notes <<= "\#\# #{next_version}\n"
23
- new_release_notes <<= logs.split(/\n/)
24
- .reject{|line| line.include?("#{last_version} release notes")}
25
- .map{|x|
22
+ new_release_notes <<= "## #{next_version}\n"
23
+ new_release_notes <<= logs.split("\n")
24
+ .reject { |line| line.include?("#{last_version} release notes") }
25
+ .map { |x|
26
26
  rev = x[0..6]
27
27
  "- #{x[8..-1]} [[#{rev}](#{PREFIX}/commit/#{rev})]\n"
28
28
  }
@@ -36,11 +36,11 @@ release_notes <<= "\n"
36
36
  release_notes <<= notes[2..-1]
37
37
 
38
38
  TMP_RELEASE_NOTES_FILE = "#{RELEASE_NOTES_FILE}.tmp"
39
- File.delete(TMP_RELEASE_NOTES_FILE) if File.exists?(TMP_RELEASE_NOTES_FILE)
40
- File.write("#{TMP_RELEASE_NOTES_FILE}", release_notes.join)
39
+ File.delete(TMP_RELEASE_NOTES_FILE) if File.exist?(TMP_RELEASE_NOTES_FILE)
40
+ File.write(TMP_RELEASE_NOTES_FILE.to_s, release_notes.join)
41
41
  system("cat #{TMP_RELEASE_NOTES_FILE} | vim - -c ':f #{TMP_RELEASE_NOTES_FILE}' -c ':9'")
42
42
 
43
- abort("The release note file is not saved. Aborted") unless File.exists?(TMP_RELEASE_NOTES_FILE)
43
+ abort("The release note file is not saved. Aborted") unless File.exist?(TMP_RELEASE_NOTES_FILE)
44
44
 
45
45
  def run(cmd)
46
46
  puts cmd
@@ -53,4 +53,4 @@ File.delete(TMP_RELEASE_NOTES_FILE)
53
53
  # run "git commit #{RELEASE_NOTES_FILE} -m \"Add #{next_version} release notes\""
54
54
  # run "git tag v#{next_version}"
55
55
  # run "git push"
56
- # run "git push --tags"
56
+ # run "git push --tags"
@@ -79,4 +79,4 @@ describe Trino::Client::Client do
79
79
  end
80
80
  end
81
81
  end
82
- end
82
+ end
data/spec/client_spec.rb CHANGED
@@ -22,23 +22,23 @@ describe Trino::Client::Client do
22
22
 
23
23
  rehashed = client.run_with_names('fake query')
24
24
 
25
- rehashed.length.should == 3
25
+ expect(rehashed.length).to eq 3
26
26
 
27
- rehashed[0]['animal'].should == 'dog'
28
- rehashed[0]['score'].should == 1
29
- rehashed[0]['name'].should == 'Lassie'
27
+ expect(rehashed[0]['animal']).to eq 'dog'
28
+ expect(rehashed[0]['score']).to eq 1
29
+ expect(rehashed[0]['name']).to eq 'Lassie'
30
30
 
31
- rehashed[0].values[0].should == 'dog'
32
- rehashed[0].values[1].should == 1
33
- rehashed[0].values[2].should == 'Lassie'
31
+ expect(rehashed[0].values[0]).to eq 'dog'
32
+ expect(rehashed[0].values[1]).to eq 1
33
+ expect(rehashed[0].values[2]).to eq 'Lassie'
34
34
 
35
- rehashed[1]['animal'].should == 'horse'
36
- rehashed[1]['score'].should == 5
37
- rehashed[1]['name'].should == 'Mr. Ed'
35
+ expect(rehashed[1]['animal']).to eq 'horse'
36
+ expect(rehashed[1]['score']).to eq 5
37
+ expect(rehashed[1]['name']).to eq 'Mr. Ed'
38
38
 
39
- rehashed[1].values[0].should == 'horse'
40
- rehashed[1].values[1].should == 5
41
- rehashed[1].values[2].should == 'Mr. Ed'
39
+ expect(rehashed[1].values[0]).to eq 'horse'
40
+ expect(rehashed[1].values[1]).to eq 5
41
+ expect(rehashed[1].values[2]).to eq 'Mr. Ed'
42
42
  end
43
43
 
44
44
  it 'empty results' do
@@ -47,14 +47,14 @@ describe Trino::Client::Client do
47
47
 
48
48
  rehashed = client.run_with_names('fake query')
49
49
 
50
- rehashed.length.should == 0
50
+ expect(rehashed.length).to eq 0
51
51
  end
52
52
 
53
53
  it 'handles too few result columns' do
54
54
  rows = [['wrong', 'count']]
55
55
  client.stub(:run).and_return([columns, rows])
56
56
 
57
- client.run_with_names('fake query').should == [{
57
+ expect(client.run_with_names('fake query')).to eq [{
58
58
  "animal" => "wrong",
59
59
  "score" => "count",
60
60
  "name" => nil,
@@ -65,7 +65,7 @@ describe Trino::Client::Client do
65
65
  rows = [['wrong', 'count', 'too', 'much', 'columns']]
66
66
  client.stub(:run).and_return([columns, rows])
67
67
 
68
- client.run_with_names('fake query').should == [{
68
+ expect(client.run_with_names('fake query')).to eq [{
69
69
  "animal" => "wrong",
70
70
  "score" => "count",
71
71
  "name" => 'too',
data/spec/gzip_spec.rb CHANGED
@@ -37,4 +37,4 @@ describe Trino::Client::Client do
37
37
  $stdout = STDOUT
38
38
  end
39
39
  end
40
- end
40
+ end
data/spec/model_spec.rb CHANGED
@@ -29,7 +29,9 @@ describe Trino::Client::Models do
29
29
  "info" => {"k" => "v"}
30
30
  }
31
31
 
32
- stats = Models::OperatorStats.decode(h)
33
- stats.blocked_reason.should == :waiting_for_memory
32
+ it 'decode blocked_reason' do
33
+ stats = Models::OperatorStats.decode(h)
34
+ expect(stats.blocked_reason).to eq :waiting_for_memory
35
+ end
34
36
  end
35
- end
37
+ end
data/spec/spec_helper.rb CHANGED
@@ -21,7 +21,8 @@ require 'tiny-presto'
21
21
 
22
22
  MAX_RETRY_COUNT = 5
23
23
  RETRYABLE_ERRORS = [
24
- /No nodes available to run query/
24
+ /No nodes available to run query/,
25
+ /failed: nodes is empty/
25
26
  ]
26
27
 
27
28
  def run_with_retry(client, sql)
@@ -32,7 +33,7 @@ def run_with_retry(client, sql)
32
33
  return columns, rows
33
34
  rescue Trino::Client::TrinoQueryError => e
34
35
  if RETRYABLE_ERRORS.any? { |error| e.message =~ error }
35
- sleep(i)
36
+ sleep(2**i)
36
37
  i += 1
37
38
  next
38
39
  end