tiny-presto 0.0.2 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +17 -7
- data/Gemfile +1 -1
- data/README.md +3 -1
- data/Rakefile +2 -0
- data/lib/tiny-presto.rb +78 -12
- data/lib/tiny-presto/cluster.rb +4 -3
- data/lib/tiny-presto/version.rb +3 -1
- data/spec/cluster_spec.rb +20 -11
- data/spec/spec_helper.rb +2 -0
- data/spec/tiny_presto_spec.rb +12 -0
- data/spec/version_spec.rb +3 -1
- data/tiny-presto.gemspec +4 -2
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72dd2cba77859f25d7d3ac35b9f76243036cfa627a375d76a7b50c0f0a146aee
|
4
|
+
data.tar.gz: 61782cf0551ef563b4f71f4a77cfaf2881757a8d51ebd1da2c5f1ecc53839a91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5203bb457596d0c13e03df2164c0225164e3abf571ef55c6b4a3b3f472adf7a769cbeb496ef3387bb09ed90a1bf3c1521cc7c54a1a14d88ffd20a7b3fc00c089
|
7
|
+
data.tar.gz: 672c494c5e5af52289d23fd18521128735b4f9c4575a40389b401e84bf37a79edf0e6859e86028fde8cea489c68afd7ca259d381aa0237faa09142a3970b919d
|
data/.rubocop.yml
CHANGED
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-
|
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:
|
28
|
+
Max: 30
|
25
29
|
|
26
|
-
# Offense count:
|
30
|
+
# Offense count: 3
|
27
31
|
# Configuration parameters: CountComments.
|
28
32
|
Metrics/MethodLength:
|
29
|
-
Max:
|
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:
|
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:
|
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
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 [
|
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
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
|
-
|
16
|
-
@cluster = Cluster.new(url)
|
17
|
+
@cluster = Cluster.new
|
17
18
|
@cluster.run
|
18
|
-
@client = Presto::Client.new(
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
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
|
data/lib/tiny-presto/cluster.rb
CHANGED
@@ -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(
|
8
|
-
@url = url
|
9
|
+
def initialize(image = 'trinodb/trino', tag = 'latest')
|
9
10
|
@tag = tag
|
10
|
-
@image_name = "
|
11
|
+
@image_name = "#{image}:#{@tag}"
|
11
12
|
end
|
12
13
|
|
13
14
|
# Launch Presto cluster running on Docker container
|
data/lib/tiny-presto/version.rb
CHANGED
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
|
8
|
+
@cluster = TinyPresto::Cluster.new
|
7
9
|
@container = @cluster.run
|
8
|
-
@client = Presto::Client.new(
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
data/spec/tiny_presto_spec.rb
CHANGED
@@ -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
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
|
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.
|
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.
|
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:
|
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
|
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.
|
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
|
-
|
114
|
-
|
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:
|