tiny-presto 0.0.2 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e2bdd215986246b63650c85c8d78eabd47e481fa51a665e0a22264f079e24af
4
- data.tar.gz: 3e9d922298a4ff0e9ac6e1d9aaf4993cdad8cc680b5fa1985914d176d2985cdf
3
+ metadata.gz: 72dd2cba77859f25d7d3ac35b9f76243036cfa627a375d76a7b50c0f0a146aee
4
+ data.tar.gz: 61782cf0551ef563b4f71f4a77cfaf2881757a8d51ebd1da2c5f1ecc53839a91
5
5
  SHA512:
6
- metadata.gz: c99b29e972147490ac5fbe3d50b3ce870aff7dd368d77ccbdd73739c36ca7f593718e89b2fc9b56c583d6e8a5b51d90a4a9ae3630f7cf22417cb7c3dfc974390
7
- data.tar.gz: 4946f97714fab4f02b9235f5f87c2c615d097d4770fa3762115a7a3c8ce023704c182002773d6253e1b384daf81d48813720ccd0711b90a3df3f4d37f47deb3b
6
+ metadata.gz: 5203bb457596d0c13e03df2164c0225164e3abf571ef55c6b4a3b3f472adf7a769cbeb496ef3387bb09ed90a1bf3c1521cc7c54a1a14d88ffd20a7b3fc00c089
7
+ data.tar.gz: 672c494c5e5af52289d23fd18521128735b4f9c4575a40389b401e84bf37a79edf0e6859e86028fde8cea489c68afd7ca259d381aa0237faa09142a3970b919d
data/.rubocop.yml CHANGED
@@ -1 +1,4 @@
1
1
  inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.5
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2020-01-14 16:36:39 +0900 using RuboCop version 0.52.1.
3
+ # on 2020-02-12 15:52:06 +0900 using RuboCop version 0.52.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -18,15 +18,19 @@ Lint/UselessAssignment:
18
18
  Exclude:
19
19
  - 'spec/cluster_spec.rb'
20
20
 
21
+ # Offense count: 1
22
+ Metrics/AbcSize:
23
+ Max: 17
24
+
21
25
  # Offense count: 2
22
26
  # Configuration parameters: CountComments, ExcludedMethods.
23
27
  Metrics/BlockLength:
24
- Max: 32
28
+ Max: 30
25
29
 
26
- # Offense count: 1
30
+ # Offense count: 3
27
31
  # Configuration parameters: CountComments.
28
32
  Metrics/MethodLength:
29
- Max: 15
33
+ Max: 19
30
34
 
31
35
  # Offense count: 1
32
36
  # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
@@ -35,15 +39,21 @@ Naming/FileName:
35
39
  Exclude:
36
40
  - 'lib/tiny-presto.rb'
37
41
 
38
- # Offense count: 2
42
+ # Offense count: 1
43
+ # Cop supports --auto-correct.
44
+ # Configuration parameters: AutoCorrect.
45
+ Performance/HashEachMethods:
46
+ Exclude:
47
+ - 'lib/tiny-presto.rb'
48
+
49
+ # Offense count: 1
39
50
  Style/Documentation:
40
51
  Exclude:
41
52
  - 'spec/**/*'
42
53
  - 'test/**/*'
43
54
  - 'lib/tiny-presto.rb'
44
- - 'lib/tiny-presto/cluster.rb'
45
55
 
46
- # Offense count: 2
56
+ # Offense count: 5
47
57
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
48
58
  # URISchemes: http, https
49
59
  Metrics/LineLength:
data/Gemfile CHANGED
@@ -7,8 +7,8 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
7
7
  gem 'docker-api'
8
8
  gem 'presto-client'
9
9
  gem 'rake'
10
- gem 'rubocop'
11
10
  gem 'rdoc'
11
+ gem 'rubocop'
12
12
 
13
13
  group :development, :test do
14
14
  gem 'rspec'
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # tiny-presto [![Actions Status](https://github.com/Lewuathe/tiny-presto/workflows/test/badge.svg)](https://github.com/Lewuathe/tiny-presto/actions) ![Gem](https://img.shields.io/gem/v/tiny-presto) ![Gem](https://img.shields.io/gem/dt/tiny-presto)
2
2
 
3
- Tiny [Presto](https://prestosql.io/) cluster to check the compatibility of query result by using the specific Presto version.
3
+ Tiny [Trino](https://trino.io/) cluster to check the compatibility of query result by using the specific Trino version.
4
+
5
+ **NOTE: The brand name of [Presto was migrated to Trino](https://trino.io/blog/2020/12/27/announcing-trino.html). Although the internal docker image used in tiny-presto was also migrated to [Trino](https://hub.docker.com/r/trinodb/trino), we keep the package name `tiny-presto` to avoid the installation trouble.**
4
6
 
5
7
  # Install
6
8
 
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env rake
2
+ # frozen_string_literal: true
3
+
2
4
  require 'bundler/gem_tasks'
3
5
 
4
6
  require 'rake/testtask'
data/lib/tiny-presto.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'tiny-presto/version'
2
4
  require 'tiny-presto/cluster'
3
5
 
@@ -12,18 +14,25 @@ module TinyPresto
12
14
  attr_reader :cluster, :client
13
15
 
14
16
  def initialize
15
- url = 'localhost'
16
- @cluster = Cluster.new(url)
17
+ @cluster = Cluster.new
17
18
  @cluster.run
18
- @client = Presto::Client.new(server: "#{url}:8080", catalog: 'memory', user: 'tiny-user', schema: 'default')
19
+ @client = Presto::Client.new(
20
+ server: 'localhost:8080',
21
+ catalog: 'memory',
22
+ user: 'tiny-user',
23
+ schema: 'default',
24
+ # TODO: Remove after presto-client-ruby supports Trino
25
+ http_headers: {
26
+ 'X-Trino-User' => 'tiny-user',
27
+ 'X-Trino-Catalog' => 'memory',
28
+ 'X-Trino-Schema' => 'default'
29
+ })
19
30
  loop do
20
- begin
21
- @client.run('show schemas')
22
- break
23
- rescue StandardError => _
24
- # Waiting for the cluster is launched
25
- sleep(1)
26
- end
31
+ @client.run('show schemas')
32
+ break
33
+ rescue StandardError => _
34
+ # Waiting for the cluster is launched
35
+ sleep(1)
27
36
  end
28
37
  end
29
38
 
@@ -32,21 +41,78 @@ module TinyPresto
32
41
  end
33
42
  end
34
43
 
44
+ def self.print_record(record)
45
+ ret = record.map do |v|
46
+ if v.is_a? Numeric
47
+ v.to_s
48
+ else
49
+ # Non numeric value is interpreted as string
50
+ "'#{v}'"
51
+ end
52
+ end
53
+ "(#{ret.join(',')})"
54
+ end
55
+
56
+ def self.prepare(table_name, table_data)
57
+ # {'c1': [1, 2, 3], 'c2': ['a', 'b', 'c']}
58
+ columns = table_data.keys
59
+ records = []
60
+ table_data.each do |_, rows|
61
+ rows.each_with_index do |r, idx|
62
+ if records[idx].nil?
63
+ records << [r]
64
+ else
65
+ records[idx] << r
66
+ end
67
+ end
68
+ end
69
+ values_clause = []
70
+ records.each do |record|
71
+ values_clause << print_record(record)
72
+ end
73
+ query = "CREATE TABLE #{table_name} AS SELECT * FROM (values #{values_clause.join(',')}) t(#{columns.join(',')})"
74
+ run_with_retry(query)
75
+ end
76
+
35
77
  # Run the given SQL.
78
+ #
79
+ # TinyPresto.run("show schemas")
80
+ #
36
81
  def self.run(sql)
37
82
  presto = TinyPresto.instance
38
83
  _, rows = presto.client.run(sql)
39
84
  rows
40
85
  end
41
86
 
87
+ # Run the given query with retrying in case of undeterministic error.
88
+ #
89
+ # TinyPresto.run_with_retry("show schemas")
90
+ #
91
+ def self.run_with_retry(sql, max_retry = 3)
92
+ max_retry.times do
93
+ return run(sql)
94
+ rescue Presto::Client::PrestoQueryError => e
95
+ # Cluster may be in the initialization phase.
96
+ raise unless e.message.match?(/^No nodes available to run query/)
97
+
98
+ sleep(1000)
99
+ next
100
+ end
101
+ end
102
+
42
103
  # Run the given SQL and verify the result.
104
+ #
105
+ # TinyPresto.verify("show schemas", [["default"], ["information_schema"]])
106
+ # # => return true
43
107
  def self.verify(sql, expected_result)
44
- presto = TinyPresto.instance
45
- _, rows = presto.client.run(sql)
108
+ rows = run_with_retry(sql)
46
109
  rows == expected_result
47
110
  end
48
111
 
49
112
  # Make sure to stop the cluster.
113
+ #
114
+ # TinyPresto.ensure_stop
115
+ #
50
116
  def self.ensure_stop
51
117
  presto = TinyPresto.instance
52
118
  presto.stop
@@ -1,13 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'docker-api'
2
4
 
3
5
  module TinyPresto
4
6
  # Represents a Presto cluster
5
7
  #
6
8
  class Cluster
7
- def initialize(url, tag = 'latest')
8
- @url = url
9
+ def initialize(image = 'trinodb/trino', tag = 'latest')
9
10
  @tag = tag
10
- @image_name = "prestosql/presto:#{@tag}"
11
+ @image_name = "#{image}:#{@tag}"
11
12
  end
12
13
 
13
14
  # Launch Presto cluster running on Docker container
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TinyPresto
2
- VERSION = '0.0.2'.freeze
4
+ VERSION = '0.0.7'.freeze
3
5
  end
data/spec/cluster_spec.rb CHANGED
@@ -1,19 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe TinyPresto::Cluster do
4
6
  describe 'cluster' do
5
7
  before(:all) do
6
- @cluster = TinyPresto::Cluster.new('localhost')
8
+ @cluster = TinyPresto::Cluster.new
7
9
  @container = @cluster.run
8
- @client = Presto::Client.new(server: 'localhost:8080', catalog: 'memory', user: 'tiny-user', schema: 'default')
10
+ @client = Presto::Client.new(
11
+ server: 'localhost:8080',
12
+ catalog: 'memory',
13
+ user: 'tiny-user',
14
+ schema: 'default',
15
+ # TODO: Remove after presto-client-ruby supports Trino
16
+ http_headers: {
17
+ 'X-Trino-User' => 'tiny-user',
18
+ 'X-Trino-Catalog' => 'memory'
19
+ })
9
20
  loop do
10
- begin
11
- @client.run('show schemas')
12
- break
13
- rescue StandardError => exception
14
- puts 'Waiting for cluster ready...'
15
- sleep(3)
16
- end
21
+ @client.run('show schemas')
22
+ break
23
+ rescue StandardError => exception
24
+ puts "Waiting for cluster ready... #{exception}"
25
+ sleep(3)
17
26
  end
18
27
  puts 'Cluster is ready'
19
28
  end
@@ -32,8 +41,8 @@ RSpec.describe TinyPresto::Cluster do
32
41
  end
33
42
 
34
43
  it 'run CTAS query' do
35
- @client.run("create table ctas1 as select * from (values (1, 'a'), (2, 'b')) t(c1, c2)")
36
- columns, rows = @client.run('select * from ctas1')
44
+ @client.run("create table default.ctas1 as select * from (values (1, 'a'), (2, 'b')) t(c1, c2)")
45
+ columns, rows = @client.run('select * from default.ctas1')
37
46
  expect(columns.map(&:name)).to match_array(%w[c1 c2])
38
47
  end
39
48
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler'
2
4
 
3
5
  begin
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe TinyPresto do
@@ -19,4 +21,14 @@ RSpec.describe TinyPresto do
19
21
  expect(result).to eq(true)
20
22
  end
21
23
  end
24
+
25
+ describe 'prepare' do
26
+ it 'dataset correctly' do
27
+ data = { 'c1': [1, 2, 3], 'c2': %w[a b c] }
28
+ TinyPresto.prepare('new_table', data)
29
+ expected = [[1, 'a'], [2, 'b'], [3, 'c']]
30
+ rows = TinyPresto.run_with_retry('select * from new_table')
31
+ expect(rows).to eq(expected)
32
+ end
33
+ end
22
34
  end
data/spec/version_spec.rb CHANGED
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe TinyPresto do
4
6
  describe '#version' do
5
7
  it 'correct' do
6
- expect(TinyPresto::VERSION).to eq('0.0.1')
8
+ expect(TinyPresto::VERSION).to eq('0.0.5')
7
9
  end
8
10
  end
9
11
  end
data/tiny-presto.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.expand_path 'lib/tiny-presto/version', File.dirname(__FILE__)
2
4
 
3
5
  Gem::Specification.new do |gem|
@@ -9,7 +11,7 @@ Gem::Specification.new do |gem|
9
11
  gem.description = 'Wrapper for Lightweight Presto Cluster'
10
12
  gem.summary = 'For Presto functionality testing'
11
13
  gem.homepage = 'https://github.com/Lewuathe/tiny-presto'
12
- gem.license = 'Apache 2.0'
14
+ gem.license = 'Apache-2.0'
13
15
 
14
16
  gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
15
17
  gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
@@ -17,7 +19,7 @@ Gem::Specification.new do |gem|
17
19
  gem.require_paths = ['lib']
18
20
  gem.has_rdoc = false
19
21
 
20
- gem.required_ruby_version = '>= 2.5.0'
22
+ gem.required_ruby_version = '>= 2.4.0'
21
23
 
22
24
  gem.add_dependency 'docker-api', ['~> 1.34.0']
23
25
  gem.add_dependency 'faraday', ['~> 0.12']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny-presto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kai Sasaki
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-19 00:00:00.000000000 Z
11
+ date: 2021-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docker-api
@@ -93,9 +93,9 @@ files:
93
93
  - tiny-presto.gemspec
94
94
  homepage: https://github.com/Lewuathe/tiny-presto
95
95
  licenses:
96
- - Apache 2.0
96
+ - Apache-2.0
97
97
  metadata: {}
98
- post_install_message:
98
+ post_install_message:
99
99
  rdoc_options: []
100
100
  require_paths:
101
101
  - lib
@@ -103,16 +103,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
104
  - - ">="
105
105
  - !ruby/object:Gem::Version
106
- version: 2.5.0
106
+ version: 2.4.0
107
107
  required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  requirements: []
113
- rubyforge_project:
114
- rubygems_version: 2.7.6
115
- signing_key:
113
+ rubygems_version: 3.1.4
114
+ signing_key:
116
115
  specification_version: 4
117
116
  summary: For Presto functionality testing
118
117
  test_files: