trino-client 1.0.2 → 2.0.1

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.
data/publish.rb DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.expand_path 'lib/trino/client/version', File.dirname(__FILE__)
3
-
4
- def run(cmd)
5
- puts cmd
6
- system cmd
7
- end
8
-
9
- run("gem build trino-client.gemspec")
10
- run("gem push trino-client-#{Trino::Client::VERSION}.gem")
11
-
12
- run("gem build trino-client-ruby/trino-client-ruby.gemspec")
13
- run("gem push trino-client-ruby/trino-client-ruby-#{Trino::Client::VERSION}.gem")
14
-
data/release.rb DELETED
@@ -1,56 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'fileutils'
4
-
5
- PREFIX = 'https://github.com/treasure-data/trino-client-ruby'
6
- RELEASE_NOTES_FILE = "ChangeLog.md"
7
-
8
- last_tag = `git describe --tags --abbrev=0`.chomp
9
- last_version = last_tag.sub("v", "")
10
- puts "last version: #{last_version}"
11
-
12
- print "next version? "
13
- next_version = STDIN.gets.chomp
14
-
15
- abort("Can't use empty version string") if next_version.empty?
16
-
17
- logs = `git log #{last_tag}..HEAD --pretty=format:'%h %s'`
18
- # Add links to GitHub issues
19
- logs = logs.gsub(/\#([0-9]+)/, "[#\\1](#{PREFIX}/issues/\\1)")
20
-
21
- new_release_notes = []
22
- new_release_notes <<= "\#\# #{next_version}\n"
23
- new_release_notes <<= logs.split(/\n/)
24
- .reject{|line| line.include?("#{last_version} release notes")}
25
- .map{|x|
26
- rev = x[0..6]
27
- "- #{x[8..-1]} [[#{rev}](#{PREFIX}/commit/#{rev})]\n"
28
- }
29
-
30
- release_notes = []
31
- notes = File.readlines(RELEASE_NOTES_FILE)
32
-
33
- release_notes <<= notes[0..1]
34
- release_notes <<= new_release_notes
35
- release_notes <<= "\n"
36
- release_notes <<= notes[2..-1]
37
-
38
- TMP_RELEASE_NOTES_FILE = "#{RELEASE_NOTES_FILE}.tmp"
39
- File.delete(TMP_RELEASE_NOTES_FILE) if File.exists?(TMP_RELEASE_NOTES_FILE)
40
- File.write("#{TMP_RELEASE_NOTES_FILE}", release_notes.join)
41
- system("cat #{TMP_RELEASE_NOTES_FILE} | vim - -c ':f #{TMP_RELEASE_NOTES_FILE}' -c ':9'")
42
-
43
- abort("The release note file is not saved. Aborted") unless File.exists?(TMP_RELEASE_NOTES_FILE)
44
-
45
- def run(cmd)
46
- puts cmd
47
- system cmd
48
- end
49
-
50
- FileUtils.cp(TMP_RELEASE_NOTES_FILE, RELEASE_NOTES_FILE)
51
- File.delete(TMP_RELEASE_NOTES_FILE)
52
-
53
- # run "git commit #{RELEASE_NOTES_FILE} -m \"Add #{next_version} release notes\""
54
- # run "git tag v#{next_version}"
55
- # run "git push"
56
- # run "git push --tags"
@@ -1,82 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Trino::Client::Client do
4
- before(:all) do
5
- WebMock.disable!
6
- @cluster = TinyPresto::Cluster.new()
7
- @container = @cluster.run
8
- @client = Trino::Client.new(server: 'localhost:8080', catalog: 'memory', user: 'test-user', schema: 'default')
9
- loop do
10
- begin
11
- @client.run('show schemas')
12
- break
13
- rescue StandardError => exception
14
- puts "Waiting for cluster ready... #{exception}"
15
- sleep(3)
16
- end
17
- end
18
- puts 'Cluster is ready'
19
- end
20
-
21
- after(:all) do
22
- @cluster.stop
23
- WebMock.enable!
24
- end
25
-
26
- it 'show schemas' do
27
- columns, rows = run_with_retry(@client, 'show schemas')
28
- expect(columns.length).to be(1)
29
- expect(rows.length).to be(2)
30
- end
31
-
32
- it 'ctas' do
33
- expected = [[1, 'a'], [2, 'b']]
34
- run_with_retry(@client, "create table ctas1 as select * from (values (1, 'a'), (2, 'b')) t(c1, c2)")
35
- columns, rows = run_with_retry(@client, 'select * from ctas1')
36
- expect(columns.map(&:name)).to match_array(%w[c1 c2])
37
- expect(rows).to eq(expected)
38
- end
39
-
40
- it 'next_uri' do
41
- @client.query('show schemas') do |q|
42
- expect(q.next_uri).to start_with('http://localhost:8080/v1/statement/')
43
- end
44
- end
45
-
46
- it 'advance' do
47
- @client.query('show schemas') do |q|
48
- expect(q.advance).to be(true)
49
- end
50
- end
51
-
52
- it 'current query result' do
53
- @client.query('show schemas') do |q|
54
- expect(q.current_results.info_uri).to start_with('http://localhost:8080/ui/query.html')
55
- end
56
- end
57
-
58
- it 'statement stats' do
59
- @client.query('show schemas') do |q|
60
- stats = q.current_results.stats
61
- # Immediate subsequent request should get queued result
62
- expect(stats.queued).to be(true)
63
- expect(stats.scheduled).to be(false)
64
- end
65
- end
66
-
67
- it 'partial cancel' do
68
- @client.query('show schemas') do |q|
69
- q.cancel
70
- expect { q.query_info }.to raise_error(Trino::Client::TrinoHttpError, /Error 410 Gone/)
71
- end
72
- end
73
-
74
- it 'row chunk' do
75
- expected_schemas = %w[default information_schema]
76
- @client.query('show schemas') do |q|
77
- q.each_row do |r|
78
- expect(expected_schemas).to include(r[0])
79
- end
80
- end
81
- end
82
- end
data/spec/client_spec.rb DELETED
@@ -1,75 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Trino::Client::Client do
4
- let(:client) { Trino::Client.new({}) }
5
-
6
- describe 'rehashes' do
7
- let(:columns) do
8
- [
9
- Models::Column.new(name: 'animal', type: 'string'),
10
- Models::Column.new(name: 'score', type: 'integer'),
11
- Models::Column.new(name: 'name', type: 'string')
12
- ]
13
- end
14
-
15
- it 'multiple rows' do
16
- rows = [
17
- ['dog', 1, 'Lassie'],
18
- ['horse', 5, 'Mr. Ed'],
19
- ['t-rex', 37, 'Doug']
20
- ]
21
- client.stub(:run).and_return([columns, rows])
22
-
23
- rehashed = client.run_with_names('fake query')
24
-
25
- rehashed.length.should == 3
26
-
27
- rehashed[0]['animal'].should == 'dog'
28
- rehashed[0]['score'].should == 1
29
- rehashed[0]['name'].should == 'Lassie'
30
-
31
- rehashed[0].values[0].should == 'dog'
32
- rehashed[0].values[1].should == 1
33
- rehashed[0].values[2].should == 'Lassie'
34
-
35
- rehashed[1]['animal'].should == 'horse'
36
- rehashed[1]['score'].should == 5
37
- rehashed[1]['name'].should == 'Mr. Ed'
38
-
39
- rehashed[1].values[0].should == 'horse'
40
- rehashed[1].values[1].should == 5
41
- rehashed[1].values[2].should == 'Mr. Ed'
42
- end
43
-
44
- it 'empty results' do
45
- rows = []
46
- client.stub(:run).and_return([columns, rows])
47
-
48
- rehashed = client.run_with_names('fake query')
49
-
50
- rehashed.length.should == 0
51
- end
52
-
53
- it 'handles too few result columns' do
54
- rows = [['wrong', 'count']]
55
- client.stub(:run).and_return([columns, rows])
56
-
57
- client.run_with_names('fake query').should == [{
58
- "animal" => "wrong",
59
- "score" => "count",
60
- "name" => nil,
61
- }]
62
- end
63
-
64
- it 'handles too many result columns' do
65
- rows = [['wrong', 'count', 'too', 'much', 'columns']]
66
- client.stub(:run).and_return([columns, rows])
67
-
68
- client.run_with_names('fake query').should == [{
69
- "animal" => "wrong",
70
- "score" => "count",
71
- "name" => 'too',
72
- }]
73
- end
74
- end
75
- end
data/spec/gzip_spec.rb DELETED
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Trino::Client::Client do
4
- before(:all) do
5
- @spec_path = File.dirname(__FILE__)
6
- WebMock.disable!
7
- @cluster = TinyPresto::Cluster.new()
8
- @container = @cluster.run
9
- @client = Trino::Client.new(server: 'localhost:8080', catalog: 'tpch', user: 'test-user', schema: 'tiny', gzip: true, http_debug: true)
10
- loop do
11
- begin
12
- # Make sure to all workers are available.
13
- @client.run('show schemas')
14
- break
15
- rescue StandardError => exception
16
- puts "Waiting for cluster ready... #{exception}"
17
- sleep(3)
18
- end
19
- end
20
- puts 'Cluster is ready'
21
- end
22
-
23
- after(:all) do
24
- @cluster.stop
25
- WebMock.enable!
26
- end
27
-
28
- it 'tpch q01 with gzip option' do
29
- $stdout = StringIO.new
30
- begin
31
- q = File.read("#{@spec_path}/tpch/q01.sql")
32
- columns, rows = run_with_retry(@client, q)
33
- expect(columns.length).to be(10)
34
- expect(rows.length).to be(4)
35
- expect($stdout.string).to include ('content-encoding: "gzip"')
36
- ensure
37
- $stdout = STDOUT
38
- end
39
- end
40
- end
data/spec/model_spec.rb DELETED
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Trino::Client::Models do
4
- describe 'rehash of BlockedReason' do
5
- h = {
6
- "operatorId" => 0,
7
- "planNodeId" => "47",
8
- "operatorType" => "ScanFilterAndProjectOperator",
9
- "addInputCalls" => 0,
10
- "addInputWall" => "0.00ns",
11
- "addInputCpu" => "0.00ns",
12
- "addInputUser" => "0.00ns",
13
- "inputDataSize" => "9.46MB",
14
- "inputPositions" => 440674,
15
- "getOutputCalls" => 734,
16
- "getOutputWall" => "7.29s",
17
- "getOutputCpu" => "0.00ns",
18
- "getOutputUser" => "0.00ns",
19
- "outputDataSize" => "36.99MB",
20
- "outputPositions" => 440674,
21
- "blockedWall" => "0.00ns",
22
- "finishCalls" => 0,
23
- "finishWall" => "0.00ns",
24
- "finishCpu" => "0.00ns",
25
- "finishUser" => "0.00ns",
26
- "memoryReservation" => "0B",
27
- "systemMemoryReservation" => "0b",
28
- "blockedReason" => "WAITING_FOR_MEMORY",
29
- "info" => {"k" => "v"}
30
- }
31
-
32
- stats = Models::OperatorStats.decode(h)
33
- stats.blocked_reason.should == :waiting_for_memory
34
- end
35
- end
data/spec/spec_helper.rb DELETED
@@ -1,42 +0,0 @@
1
- require 'bundler'
2
-
3
- begin
4
- Bundler.setup(:default, :test)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
-
11
- require 'simplecov'
12
- SimpleCov.start
13
-
14
- require 'json'
15
- require 'webmock/rspec'
16
-
17
- require 'trino-client'
18
- include Trino::Client
19
-
20
- require 'tiny-presto'
21
-
22
- MAX_RETRY_COUNT = 5
23
- RETRYABLE_ERRORS = [
24
- /No nodes available to run query/
25
- ]
26
-
27
- def run_with_retry(client, sql)
28
- i = 0
29
- while i < MAX_RETRY_COUNT
30
- begin
31
- columns, rows = @client.run(sql)
32
- return columns, rows
33
- rescue Trino::Client::TrinoQueryError => e
34
- if RETRYABLE_ERRORS.any? { |error| e.message =~ error }
35
- sleep(i)
36
- i += 1
37
- next
38
- end
39
- raise "Fail to run query: #{e}"
40
- end
41
- end
42
- end