tiny-presto 0.0.3 → 0.0.4
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 +4 -4
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +17 -7
- data/Gemfile +1 -1
- data/Rakefile +2 -0
- data/lib/tiny-presto/cluster.rb +3 -2
- data/lib/tiny-presto/version.rb +3 -1
- data/lib/tiny-presto.rb +63 -12
- data/spec/cluster_spec.rb +8 -8
- 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 +2 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22d98c71de7a327595dd05b6a59a8ed1ff747208995eb9ab5c02bc4ef954dade
|
4
|
+
data.tar.gz: 86b59421bc8379e130956108781965da6d51bad55bb274b907ba53ae688c0d4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47f6d98e15f9071f31c424fcb63f8521f7b99a09c796bbac4df5447da5ba494101460f56d6a242b213737b9ba57af3fdc2bc2498cb390a961bdc5a2366fe467d
|
7
|
+
data.tar.gz: a1801999ed1897d976e70d90b8728f92b428a91b08a8fd29a703d852728b2f1e4cc895b0ecaeac7dd09f650bc6ebb24f505f3de362e6f942fa48f10e96411920
|
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/Rakefile
CHANGED
data/lib/tiny-presto/cluster.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
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(tag = 'latest')
|
9
10
|
@tag = tag
|
10
11
|
@image_name = "prestosql/presto:#{@tag}"
|
11
12
|
end
|
data/lib/tiny-presto/version.rb
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,15 @@ 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(server:
|
19
|
+
@client = Presto::Client.new(server: 'localhost:8080', catalog: 'memory', user: 'tiny-user', schema: 'default')
|
19
20
|
loop do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
sleep(1)
|
26
|
-
end
|
21
|
+
@client.run('show schemas')
|
22
|
+
break
|
23
|
+
rescue StandardError => _
|
24
|
+
# Waiting for the cluster is launched
|
25
|
+
sleep(1)
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
@@ -32,6 +31,44 @@ module TinyPresto
|
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
34
|
+
def self.print_record(record)
|
35
|
+
ret = '('
|
36
|
+
record.each_with_index do |v, idx|
|
37
|
+
ret << ',' if idx != 0
|
38
|
+
ret << if v.is_a? Numeric
|
39
|
+
v.to_s
|
40
|
+
else
|
41
|
+
# Non numeric value is interpreted as string
|
42
|
+
"'#{v}'"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
ret << ')'
|
46
|
+
ret
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.prepare(table_name, table_data)
|
50
|
+
# {'c1': [1, 2, 3], 'c2': ['a', 'b', 'c']}
|
51
|
+
columns = table_data.keys
|
52
|
+
records = []
|
53
|
+
table_data.each do |_, rows|
|
54
|
+
rows.each_with_index do |r, idx|
|
55
|
+
if records[idx].nil?
|
56
|
+
records << [r]
|
57
|
+
else
|
58
|
+
records[idx] << r
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
values_clause = '(values '
|
63
|
+
records.each_with_index do |record, idx|
|
64
|
+
values_clause << ',' if idx != 0
|
65
|
+
values_clause << print_record(record)
|
66
|
+
end
|
67
|
+
values_clause << ')'
|
68
|
+
query = "CREATE TABLE #{table_name} AS SELECT * FROM #{values_clause} t(#{columns.join(',')})"
|
69
|
+
run_with_retry(query)
|
70
|
+
end
|
71
|
+
|
35
72
|
# Run the given SQL.
|
36
73
|
#
|
37
74
|
# TinyPresto.run("show schemas")
|
@@ -42,13 +79,27 @@ module TinyPresto
|
|
42
79
|
rows
|
43
80
|
end
|
44
81
|
|
82
|
+
# Run the given query with retrying in case of undeterministic error.
|
83
|
+
#
|
84
|
+
# TinyPresto.run_with_retry("show schemas")
|
85
|
+
#
|
86
|
+
def self.run_with_retry(sql, max_retry = 3)
|
87
|
+
max_retry.times do
|
88
|
+
return run(sql)
|
89
|
+
rescue Presto::Client::PrestoQueryError => e
|
90
|
+
# Cluster may be in the initialization phase.
|
91
|
+
raise unless e.message.match?(/^No nodes available to run query/)
|
92
|
+
|
93
|
+
next
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
45
97
|
# Run the given SQL and verify the result.
|
46
98
|
#
|
47
99
|
# TinyPresto.verify("show schemas", [["default"], ["information_schema"]])
|
48
100
|
# # => return true
|
49
101
|
def self.verify(sql, expected_result)
|
50
|
-
|
51
|
-
_, rows = presto.client.run(sql)
|
102
|
+
rows = run_with_retry(sql)
|
52
103
|
rows == expected_result
|
53
104
|
end
|
54
105
|
|
data/spec/cluster_spec.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
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
10
|
@client = Presto::Client.new(server: 'localhost:8080', catalog: 'memory', user: 'tiny-user', schema: 'default')
|
9
11
|
loop do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
sleep(3)
|
16
|
-
end
|
12
|
+
@client.run('show schemas')
|
13
|
+
break
|
14
|
+
rescue StandardError => exception
|
15
|
+
puts 'Waiting for cluster ready...'
|
16
|
+
sleep(3)
|
17
17
|
end
|
18
18
|
puts 'Cluster is ready'
|
19
19
|
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
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kai Sasaki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docker-api
|
@@ -110,8 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
requirements: []
|
113
|
-
|
114
|
-
rubygems_version: 2.7.6
|
113
|
+
rubygems_version: 3.0.3
|
115
114
|
signing_key:
|
116
115
|
specification_version: 4
|
117
116
|
summary: For Presto functionality testing
|