Skip to content

Commit

Permalink
Reformat Rakefile and etc
Browse files Browse the repository at this point in the history
  • Loading branch information
yuokada committed Nov 22, 2022
1 parent 009173e commit 6e08989
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 76 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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
17 changes: 8 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
#!/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
data = erb.result
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
Expand All @@ -42,4 +42,3 @@ namespace "modelgen" do
task ver => "lib/trino/client/model_versions/#{ver}.rb"
end
end

2 changes: 1 addition & 1 deletion lib/trino-client.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require 'trino/client'
require "trino/client"
6 changes: 2 additions & 4 deletions lib/trino/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 3 additions & 5 deletions modelgen/modelgen.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

if ARGV.length != 4
puts "usage: <model-version> <trino-source-dir> <template.erb> <output.rb>"
exit 1
Expand Down Expand Up @@ -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
Expand All @@ -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 = {
Expand All @@ -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)

Expand All @@ -116,4 +115,3 @@

data = erb.result
File.write(output_path, data)

38 changes: 18 additions & 20 deletions modelgen/trino_models.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

module TrinoModels
require 'find'
require 'stringio'
Expand All @@ -15,15 +14,15 @@ 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

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] || {}
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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]}"
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -146,20 +145,20 @@ 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
end
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'
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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

Expand All @@ -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

3 changes: 1 addition & 2 deletions publish.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")

16 changes: 8 additions & 8 deletions release.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
}
Expand All @@ -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
Expand All @@ -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"
# run "git push --tags"
2 changes: 1 addition & 1 deletion spec/basic_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@
end
end
end
end
end
2 changes: 1 addition & 1 deletion spec/gzip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
$stdout = STDOUT
end
end
end
end
2 changes: 1 addition & 1 deletion spec/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
stats = Models::OperatorStats.decode(h)
stats.blocked_reason.should == :waiting_for_memory
end
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 6e08989

Please sign in to comment.