diff --git a/Gemfile b/Gemfile index e4021ce8..6676ece7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ -source 'https://rubygems.org/' +source "https://rubygems.org/" gemspec group :development, :test do - gem 'tiny-presto', "~> 0.0.8" + gem "tiny-presto", "~> 0.0.8" end diff --git a/Rakefile b/Rakefile index 3b3e0bee..cd140115 100644 --- a/Rakefile +++ b/Rakefile @@ -1,22 +1,22 @@ #!/usr/bin/env rake -require 'bundler/gem_tasks' +require "bundler/gem_tasks" -require 'rake/testtask' -require 'rake/clean' +require "rake/testtask" +require "rake/clean" -require 'rspec/core/rake_task' +require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) -task :default => [:spec, :build] +task default: [:spec, :build] GEN_MODEL_VERSIONS = %w[ 351 ] namespace "modelgen" do - task :latest => :all do - require 'erb' + task latest: :all do + require "erb" erb = ERB.new(File.read("modelgen/models.rb")) @versions = GEN_MODEL_VERSIONS @latest_version = GEN_MODEL_VERSIONS.last @@ -24,7 +24,7 @@ namespace "modelgen" do File.write("lib/trino/client/models.rb", data) end - task :all => GEN_MODEL_VERSIONS + task all: GEN_MODEL_VERSIONS GEN_MODEL_VERSIONS.each do |ver| file "build/trino-#{ver}.tar.gz" do @@ -42,4 +42,3 @@ namespace "modelgen" do task ver => "lib/trino/client/model_versions/#{ver}.rb" end end - diff --git a/lib/trino-client.rb b/lib/trino-client.rb index d668fbfb..c20fd856 100644 --- a/lib/trino-client.rb +++ b/lib/trino-client.rb @@ -1 +1 @@ -require 'trino/client' +require "trino/client" diff --git a/lib/trino/client.rb b/lib/trino/client.rb index dfcb56b6..827b9593 100644 --- a/lib/trino/client.rb +++ b/lib/trino/client.rb @@ -15,9 +15,7 @@ # module Trino module Client - - require 'trino/client/version' - require 'trino/client/client' - + require "trino/client/version" + require "trino/client/client" end end diff --git a/modelgen/modelgen.rb b/modelgen/modelgen.rb index ece2f669..ece6ff66 100644 --- a/modelgen/modelgen.rb +++ b/modelgen/modelgen.rb @@ -1,4 +1,3 @@ - if ARGV.length != 4 puts "usage: " exit 1 @@ -70,7 +69,7 @@ StatementStats StageStats ClientStageStats ClientStageStats StageStats ClientStageStats QueryResults Column ClientColumn -].each_slice(3).map { |x, y, z| [[x,y], z] }.flatten(1)] +].each_slice(3).map { |x, y, z| [[x, y], z] }.flatten(1)] path_mapping = Hash[*%w[ ClientColumn client/trino-client/src/main/java/io/trino/client/Column.java @@ -82,7 +81,7 @@ TableWriterInfo core/trino-main/src/main/java/io/trino/operator/TableWriterOperator.java TableInfo core/trino-main/src/main/java/io/trino/execution/TableInfo.java DynamicFiltersStats core/trino-main/src/main/java/io/trino/server/DynamicFilterService.java -].map.with_index { |v,i| i % 2 == 0 ? v : (source_path + "/" + v) }] +].map.with_index { |v, i| i % 2 == 0 ? v : (source_path + "/" + v) }] # model => [ [key,nullable,type], ... ] extra_fields = { @@ -107,7 +106,7 @@ primitive_types: assume_primitive, skip_types: skipped_models, simple_classes: predefined_simple_classes, - enum_types: enum_types, + enum_types: enum_types ) formatter.format(models) @@ -116,4 +115,3 @@ data = erb.result File.write(output_path, data) - diff --git a/modelgen/trino_models.rb b/modelgen/trino_models.rb index df07f0c8..5ea602d9 100644 --- a/modelgen/trino_models.rb +++ b/modelgen/trino_models.rb @@ -1,4 +1,3 @@ - module TrinoModels require 'find' require 'stringio' @@ -15,7 +14,7 @@ class Field < Struct.new(:key, :nullable, :array, :map, :type, :base_type, :map_ alias_method :map?, :map def name - @name ||= key.gsub(/[A-Z]/) {|f| "_#{f.downcase}" } + @name ||= key.gsub(/[A-Z]/) { |f| "_#{f.downcase}" } end end @@ -23,7 +22,7 @@ class ModelAnalysisError < StandardError end class ModelAnalyzer - def initialize(source_path, options={}) + def initialize(source_path, options = {}) @source_path = source_path @ignore_types = PRIMITIVE_TYPES + ARRAY_PRIMITIVE_TYPES + (options[:skip_models] || []) @path_mapping = options[:path_mapping] || {} @@ -36,11 +35,11 @@ def initialize(source_path, options={}) attr_reader :skipped_models def models - @models.values.sort_by {|model| model.name } + @models.values.sort_by { |model| model.name } end def analyze(root_models) - root_models.each {|model_name| + root_models.each { |model_name| analyze_model(model_name) } end @@ -54,7 +53,7 @@ def analyze(root_models) def analyze_fields(model_name, creator_block, generic: nil) model_name = "#{model_name}_#{generic}" if generic extra = @extra_fields[model_name] || [] - fields = creator_block.scan(PROPERTY_PATTERN).concat(extra).map do |key,nullable,type| + fields = creator_block.scan(PROPERTY_PATTERN).concat(extra).map do |key, nullable, type| map = false array = false nullable = !!nullable @@ -84,10 +83,10 @@ def analyze_fields(model_name, creator_block, generic: nil) end base_type = @name_mapping[[model_name, base_type]] || base_type map_value_base_type = @name_mapping[[model_name, map_value_base_type]] || map_value_base_type - + if generic base_type = generic if base_type == 'T' - map_value_base_type = generic if map_value_base_type == 'T' + map_value_base_type = generic if map_value_base_type == 'T' end if m = GENERIC_PATTERN.match(base_type) base_type_alias = "#{m[1]}_#{m[2]}" @@ -103,10 +102,10 @@ def analyze_fields(model_name, creator_block, generic: nil) analyze_model(field.map_value_base_type, model_name) if field.map_value_base_type end - return fields + fields end - def analyze_model(model_name, parent_model= nil, generic: nil) + def analyze_model(model_name, parent_model = nil, generic: nil) return if @models[model_name] || @ignore_types.include?(model_name) if m = GENERIC_PATTERN.match(model_name) @@ -123,7 +122,7 @@ def analyze_model(model_name, parent_model= nil, generic: nil) raise ModelAnalysisError, "Can't find JsonCreator of a model class #{model_name} of #{parent_model} at #{path}" end - body = m[0] + body = m[0] # check inner class first while true offset = m.end(0) @@ -146,12 +145,12 @@ def find_class_file(model_name, parent_model) @source_files ||= Find.find(@source_path).to_a pattern = /\/#{model_name}.java$/ - matched = @source_files.find_all {|path| path =~ pattern && !path.include?('/test/') && !path.include?('/verifier/')} + matched = @source_files.find_all { |path| path =~ pattern && !path.include?('/test/') && !path.include?('/verifier/') } if matched.empty? raise ModelAnalysisError, "Model class #{model_name} is not found" end if matched.size == 1 - return matched.first + matched.first else raise ModelAnalysisError, "Model class #{model_name} of #{parent_model} found multiple match #{matched}" end @@ -159,7 +158,7 @@ def find_class_file(model_name, parent_model) end class ModelFormatter - def initialize(options={}) + def initialize(options = {}) @indent = options[:indent] || ' ' @base_indent_count = options[:base_indent_count] || 0 @struct_class = options[:struct_class] || 'Struct' @@ -182,7 +181,7 @@ def format(models) @model = model puts_with_indent 0, "class << #{model.name} =" - puts_with_indent 2, "#{@struct_class}.new(#{model.fields.map {|f| ":#{f.name}" }.join(', ')})" + puts_with_indent 2, "#{@struct_class}.new(#{model.fields.map { |f| ":#{f.name}" }.join(', ')})" format_decode puts_with_indent 0, "end" line @@ -220,7 +219,7 @@ def format_decode expr = "hash[\"#{field.key}\"]" else expr = "" - expr << "hash[\"#{field.key}\"] && " #if field.nullable? + expr << "hash[\"#{field.key}\"] && " # if field.nullable? if field.map? key_expr = convert_expression(field.base_type, field.base_type, "k") @@ -238,8 +237,8 @@ def format_decode end end - #comment = "# #{field.base_type}#{field.array? ? '[]' : ''} #{field.key}" - #puts_with_indent 3, "#{expr}, #{comment}" + # comment = "# #{field.base_type}#{field.array? ? '[]' : ''} #{field.key}" + # puts_with_indent 3, "#{expr}, #{comment}" puts_with_indent 3, "#{expr}," end @@ -261,10 +260,9 @@ def convert_expression(type, base_type, key) key elsif @simple_classes.include?(base_type) "#{base_type}.new(#{key})" - else # model class + else # model class "#{base_type}.decode(#{key})" end end end end - diff --git a/publish.rb b/publish.rb index 7f04d928..2dee6069 100644 --- a/publish.rb +++ b/publish.rb @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -require File.expand_path 'lib/trino/client/version', File.dirname(__FILE__) +require File.expand_path "lib/trino/client/version", File.dirname(__FILE__) def run(cmd) puts cmd @@ -11,4 +11,3 @@ def run(cmd) run("gem build trino-client-ruby/trino-client-ruby.gemspec") run("gem push trino-client-ruby/trino-client-ruby-#{Trino::Client::VERSION}.gem") - diff --git a/release.rb b/release.rb index 0f74e4a6..31ec6ddc 100644 --- a/release.rb +++ b/release.rb @@ -1,8 +1,8 @@ #!/usr/bin/env ruby -require 'fileutils' +require "fileutils" -PREFIX = 'https://github.com/treasure-data/trino-client-ruby' +PREFIX = "https://github.com/treasure-data/trino-client-ruby" RELEASE_NOTES_FILE = "ChangeLog.md" last_tag = `git describe --tags --abbrev=0`.chomp @@ -21,8 +21,8 @@ new_release_notes = [] new_release_notes <<= "\#\# #{next_version}\n" new_release_notes <<= logs.split(/\n/) - .reject{|line| line.include?("#{last_version} release notes")} - .map{|x| + .reject { |line| line.include?("#{last_version} release notes") } + .map { |x| rev = x[0..6] "- #{x[8..-1]} [[#{rev}](#{PREFIX}/commit/#{rev})]\n" } @@ -36,11 +36,11 @@ release_notes <<= notes[2..-1] TMP_RELEASE_NOTES_FILE = "#{RELEASE_NOTES_FILE}.tmp" -File.delete(TMP_RELEASE_NOTES_FILE) if File.exists?(TMP_RELEASE_NOTES_FILE) -File.write("#{TMP_RELEASE_NOTES_FILE}", release_notes.join) +File.delete(TMP_RELEASE_NOTES_FILE) if File.exist?(TMP_RELEASE_NOTES_FILE) +File.write(TMP_RELEASE_NOTES_FILE.to_s, release_notes.join) system("cat #{TMP_RELEASE_NOTES_FILE} | vim - -c ':f #{TMP_RELEASE_NOTES_FILE}' -c ':9'") -abort("The release note file is not saved. Aborted") unless File.exists?(TMP_RELEASE_NOTES_FILE) +abort("The release note file is not saved. Aborted") unless File.exist?(TMP_RELEASE_NOTES_FILE) def run(cmd) puts cmd @@ -53,4 +53,4 @@ def run(cmd) # run "git commit #{RELEASE_NOTES_FILE} -m \"Add #{next_version} release notes\"" # run "git tag v#{next_version}" # run "git push" -# run "git push --tags" \ No newline at end of file +# run "git push --tags" diff --git a/spec/basic_query_spec.rb b/spec/basic_query_spec.rb index 5319e42f..04f8c170 100644 --- a/spec/basic_query_spec.rb +++ b/spec/basic_query_spec.rb @@ -79,4 +79,4 @@ end end end -end \ No newline at end of file +end diff --git a/spec/gzip_spec.rb b/spec/gzip_spec.rb index b6e7ed10..f867bb7e 100644 --- a/spec/gzip_spec.rb +++ b/spec/gzip_spec.rb @@ -37,4 +37,4 @@ $stdout = STDOUT end end -end \ No newline at end of file +end diff --git a/spec/model_spec.rb b/spec/model_spec.rb index 1cfd6073..5f6cadb6 100644 --- a/spec/model_spec.rb +++ b/spec/model_spec.rb @@ -32,4 +32,4 @@ stats = Models::OperatorStats.decode(h) stats.blocked_reason.should == :waiting_for_memory end -end \ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8f180362..0f3551ec 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -33,7 +33,7 @@ def run_with_retry(client, sql) return columns, rows rescue Trino::Client::TrinoQueryError => e if RETRYABLE_ERRORS.any? { |error| e.message =~ error } - sleep(2 ** i) + sleep(2**i) i += 1 next end diff --git a/spec/statement_client_spec.rb b/spec/statement_client_spec.rb index b5a7461f..19bd223a 100644 --- a/spec/statement_client_spec.rb +++ b/spec/statement_client_spec.rb @@ -73,7 +73,7 @@ "X-Trino-User" => options[:user], "X-Trino-Language" => options[:language], "X-Trino-Time-Zone" => options[:time_zone], - }).to_return(body: lambda{|req|if retry_p; response_json.to_json; else; retry_p=true; raise Timeout::Error.new("execution expired"); end }) + }).to_return(body: lambda { |req| if retry_p; response_json.to_json; else; retry_p = true; raise Timeout::Error.new("execution expired"); end }) sc = StatementClient.new(faraday, query, options.merge(http_open_timeout: 1)) sc.has_next?.should be_true @@ -104,7 +104,7 @@ "X-Trino-Language" => options[:language], "X-Trino-Time-Zone" => options[:time_zone], "Accept" => "application/x-msgpack,application/json" - }).to_return(body: lambda{|req|if retry_p; MessagePack.dump(response_json); else; retry_p=true; raise Timeout::Error.new("execution expired"); end }, headers: {"Content-Type" => "application/x-msgpack"}) + }).to_return(body: lambda { |req| if retry_p; MessagePack.dump(response_json); else; retry_p = true; raise Timeout::Error.new("execution expired"); end }, headers: {"Content-Type" => "application/x-msgpack"}) options.merge!(http_open_timeout: 1, enable_x_msgpack: "application/x-msgpack") sc = StatementClient.new(faraday, query, options) @@ -277,12 +277,12 @@ end it "sets X-Trino-Session from properties" do - options[:properties] = {"hello" => "world", "name"=>"value"} + options[:properties] = {"hello" => "world", "name" => "value"} stub_request(:post, "localhost/v1/statement"). with(body: query, headers: headers.merge({ - "X-Trino-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join(", ") + "X-Trino-Session" => options[:properties].map { |k, v| "#{k}=#{v}" }.join(", ") })). to_return(body: response_json.to_json) @@ -340,7 +340,7 @@ basic_auth: [options[:user], password] ).to_return(body: response_json.to_json) - options.merge!(ssl: { verify: true }, password: password) + options.merge!(ssl: {verify: true}, password: password) StatementClient.new(faraday, query, options) end @@ -449,7 +449,6 @@ end.should raise_error(NameError) end - let :nested_json do nested_stats = {createTime: Time.now} # JSON max nesting default value is 100 @@ -552,7 +551,7 @@ it "raises TrinoQueryTimeoutError if timeout during initial resuming" do stub_request(:get, "localhost/v1/next_uri"). with(headers: headers). - to_return(body: lambda{|req| raise Timeout::Error.new("execution expired")}) + to_return(body: lambda { |req| raise Timeout::Error.new("execution expired") }) lambda do StatementClient.new(faraday, query, options.merge(timeout_type => 1), "/v1/next_uri") @@ -562,7 +561,7 @@ it "raises TrinoHttpError if timeout during initial resuming and #{timeout_type} < retry_timeout" do stub_request(:get, "localhost/v1/next_uri"). with(headers: headers). - to_return(body: lambda{|req| raise Timeout::Error.new("execution expired")}) + to_return(body: lambda { |req| raise Timeout::Error.new("execution expired") }) lambda do StatementClient.new(faraday, query, options.merge(timeout_type => 2, retry_timeout: 1), "/v1/next_uri") @@ -631,7 +630,5 @@ sleep 1 client.advance # set finished end - end end - diff --git a/spec/tpch_query_spec.rb b/spec/tpch_query_spec.rb index abad9204..ea86b2e2 100644 --- a/spec/tpch_query_spec.rb +++ b/spec/tpch_query_spec.rb @@ -38,4 +38,4 @@ expect(columns.length).to be(8) expect(rows.length).to be(4) end -end \ No newline at end of file +end diff --git a/trino-client-ruby/lib/trino-client-ruby.rb b/trino-client-ruby/lib/trino-client-ruby.rb index c4db0ed4..cb1019dc 100644 --- a/trino-client-ruby/lib/trino-client-ruby.rb +++ b/trino-client-ruby/lib/trino-client-ruby.rb @@ -1 +1 @@ -require 'trino-client' +require "trino-client" diff --git a/trino-client-ruby/trino-client-ruby.gemspec b/trino-client-ruby/trino-client-ruby.gemspec index 6ccbebe4..78f239c6 100644 --- a/trino-client-ruby/trino-client-ruby.gemspec +++ b/trino-client-ruby/trino-client-ruby.gemspec @@ -1,4 +1,4 @@ -require File.expand_path '../lib/trino/client/version', File.dirname(__FILE__) +require File.expand_path "../lib/trino/client/version", File.dirname(__FILE__) Gem::Specification.new do |gem| gem.name = "trino-client-ruby" @@ -6,12 +6,12 @@ Gem::Specification.new do |gem| gem.authors = ["Sadayuki Furuhashi"] gem.email = ["sf@treasure-data.com"] - gem.description = %q{Trino client library} - gem.summary = %q{Trino client library} + gem.description = "Trino client library" + gem.summary = "Trino client library" gem.homepage = "https://github.com/treasure-data/trino-client-ruby" gem.license = "Apache-2.0" - gem.files = ['lib/trino-client-ruby.rb'] + gem.files = ["lib/trino-client-ruby.rb"] gem.require_paths = ["lib"] gem.required_ruby_version = ">= 1.9.1" diff --git a/trino-client.gemspec b/trino-client.gemspec index 8c0e81fd..4c0c660c 100644 --- a/trino-client.gemspec +++ b/trino-client.gemspec @@ -1,4 +1,4 @@ -require File.expand_path 'lib/trino/client/version', File.dirname(__FILE__) +require File.expand_path "lib/trino/client/version", File.dirname(__FILE__) Gem::Specification.new do |gem| gem.name = "trino-client" @@ -6,13 +6,13 @@ Gem::Specification.new do |gem| gem.authors = ["Sadayuki Furuhashi"] gem.email = ["sf@treasure-data.com"] - gem.description = %q{Trino client library} - gem.summary = %q{Trino client library} + gem.description = "Trino client library" + gem.summary = "Trino client library" gem.homepage = "https://github.com/treasure-data/trino-client-ruby" gem.license = "Apache-2.0" gem.files = `git ls-files`.split($\) - gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } + gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ["lib"] @@ -20,7 +20,7 @@ Gem::Specification.new do |gem| gem.add_dependency "faraday", ["~> 1.0"] gem.add_dependency "faraday_middleware", ["~> 1.0"] - gem.add_dependency "msgpack", [">= 0.7.0"] + gem.add_dependency "msgpack", [">= 0.7.0"] gem.add_development_dependency "rake", [">= 0.9.2", "< 11.0"] gem.add_development_dependency "rspec", ["~> 2.13.0"]