presto-client-legacy 0.4.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.travis.yml +13 -0
- data/ChangeLog +89 -0
- data/Gemfile +2 -0
- data/README.md +86 -0
- data/Rakefile +26 -0
- data/lib/presto/client/client.rb +74 -0
- data/lib/presto/client/errors.rb +42 -0
- data/lib/presto/client/models.rb +1521 -0
- data/lib/presto/client/query.rb +176 -0
- data/lib/presto/client/statement_client.rb +259 -0
- data/lib/presto/client/version.rb +20 -0
- data/lib/presto/client.rb +23 -0
- data/lib/presto-client-legacy.rb +1 -0
- data/modelgen/modelgen.rb +91 -0
- data/modelgen/models.rb +230 -0
- data/modelgen/presto_models.rb +228 -0
- data/presto-client-legacy.gemspec +29 -0
- data/spec/client_spec.rb +75 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/statement_client_spec.rb +183 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 61184b98b159d0449f73cc8234c9f1e47ccb6c7f
|
4
|
+
data.tar.gz: 21fe7f9ce3eec82b868bf1505ba46fa3787bb65e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3bec8f3656e5d37f61669c4877e3772bd93c3f8aa32b4a9fff6a708b1ef8ffc9e013c38ed91dbe71fe7a89ee82bf0ae1f02f1e0cc771cb4da5922458e46f2ba7
|
7
|
+
data.tar.gz: 4d52518e9ffe81b40b7167522c7222741cb90fca558e334c8df0aa1588e3ca4f305c031b26ef7fb14956eea2b9e5a4f9391d04b4a94d98bb26ca66ef6fe06fa8
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/ChangeLog
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
2016-08-09 version 0.4.17:
|
2
|
+
|
3
|
+
* Added support for :ssl option.
|
4
|
+
|
5
|
+
|
6
|
+
2016-08-03 version 0.4.16:
|
7
|
+
|
8
|
+
* Upgraded Presto model version to 0.151
|
9
|
+
|
10
|
+
|
11
|
+
2016-08-03 version 0.4.15:
|
12
|
+
|
13
|
+
* decode method of model classes validate Hash type
|
14
|
+
|
15
|
+
|
16
|
+
2016-08-02 version 0.4.14:
|
17
|
+
|
18
|
+
* Added support for resuming fetching query results by using new `Query.resume(next_uri, options)` method (@tetrakai++)
|
19
|
+
|
20
|
+
|
21
|
+
2016-08-02 version 0.4.13:
|
22
|
+
|
23
|
+
* Added support for :http_proxy option to use a HTTP proxy server
|
24
|
+
* Added support for hashed Client response using `run_with_names` (thanks to MoovWeb for allowing me to contribute)
|
25
|
+
* Upgraded Presto model version to 0.134
|
26
|
+
|
27
|
+
2015-04-01 version 0.4.5:
|
28
|
+
|
29
|
+
* Upgraded Presto model version to 0.99
|
30
|
+
|
31
|
+
|
32
|
+
2014-11-20 version 0.4.3:
|
33
|
+
|
34
|
+
* Updated gem dependency to accept faraday ~> 0.9.x as well as ~> 0.8.8
|
35
|
+
|
36
|
+
|
37
|
+
2014-10-15 version 0.4.2:
|
38
|
+
|
39
|
+
* Added support for :properties option to set session properties introduced
|
40
|
+
since Presto 0.78
|
41
|
+
|
42
|
+
|
43
|
+
2014-06-12 version 0.4.1:
|
44
|
+
|
45
|
+
* Added EquiJoinClause model class
|
46
|
+
* Added StageId#query_id and #id methods
|
47
|
+
* Added TaskId#query_id, #stage_id and #id methods
|
48
|
+
|
49
|
+
|
50
|
+
2014-06-10 version 0.4.0:
|
51
|
+
|
52
|
+
* Added Query#current_results, #advance and #query_info for advanced users
|
53
|
+
* Generate model classes from Presto source code to include complete classes
|
54
|
+
|
55
|
+
|
56
|
+
2014-05-06 version 0.3.3:
|
57
|
+
|
58
|
+
* Added :time_zone and :language options added by Presto 0.66
|
59
|
+
|
60
|
+
|
61
|
+
2014-04-01 version 0.3.2:
|
62
|
+
|
63
|
+
* Fixed a problem that client skips the last chunk if result is large
|
64
|
+
|
65
|
+
|
66
|
+
2014-01-30 version 0.3.1:
|
67
|
+
|
68
|
+
* Added http_debug option
|
69
|
+
* Disabled HTTP debug logging by default
|
70
|
+
|
71
|
+
|
72
|
+
2014-01-22 version 0.3.0:
|
73
|
+
|
74
|
+
* Added http_timeout option
|
75
|
+
* Added http_open_timeout option
|
76
|
+
* Changed Query.start API to start(query, options) to http options
|
77
|
+
|
78
|
+
|
79
|
+
2014-01-22 version 0.2.0:
|
80
|
+
|
81
|
+
* Added Query#cancel
|
82
|
+
* Added Query#close
|
83
|
+
* Added Client#run
|
84
|
+
* Changed required_ruby_version from 1.9.3 to 1.9.1
|
85
|
+
|
86
|
+
|
87
|
+
2014-01-07 version 0.1.0:
|
88
|
+
|
89
|
+
* First release
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Presto client library for Ruby which support legacy presto (before 0.151)
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/treasure-data/presto-client-ruby.svg?branch=master)](https://travis-ci.org/treasure-data/presto-client-ruby)
|
4
|
+
|
5
|
+
Presto is a distributed SQL query engine for big data:
|
6
|
+
https://github.com/facebook/presto
|
7
|
+
|
8
|
+
This is a client library for Ruby to run queries on Presto.
|
9
|
+
|
10
|
+
## Example
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
require 'presto-client'
|
14
|
+
|
15
|
+
# create a client object:
|
16
|
+
client = Presto::Client.new(
|
17
|
+
server: "localhost:8880", # required option
|
18
|
+
ssl: {verify: false},
|
19
|
+
catalog: "native",
|
20
|
+
schema: "default",
|
21
|
+
user: "frsyuki",
|
22
|
+
time_zone: "US/Pacific",
|
23
|
+
language: "English",
|
24
|
+
properties: {
|
25
|
+
"hive.force_local_scheduling": true,
|
26
|
+
"raptor.reader_stream_buffer_size": "32MB"
|
27
|
+
},
|
28
|
+
http_proxy: "proxy.example.com:8080",
|
29
|
+
http_debug: true,
|
30
|
+
)
|
31
|
+
|
32
|
+
# run a query and get results as an array of arrays:
|
33
|
+
columns, rows = client.run("select * from sys.node")
|
34
|
+
rows.each {|row|
|
35
|
+
p row # row is an array
|
36
|
+
}
|
37
|
+
|
38
|
+
# run a query and get results as an array of hashes:
|
39
|
+
results = client.run_with_names("select alpha, 1 AS beta from tablename")
|
40
|
+
results.each {|row|
|
41
|
+
p row['alpha'] # access by name
|
42
|
+
p row['beta']
|
43
|
+
p row.values[0] # access by index
|
44
|
+
p row.values[1]
|
45
|
+
}
|
46
|
+
|
47
|
+
# run a query and fetch results streamingly:
|
48
|
+
client.query("select * from sys.node") do |q|
|
49
|
+
# get columns:
|
50
|
+
q.columns.each {|column|
|
51
|
+
puts "column: #{column.name}.#{column.type}"
|
52
|
+
}
|
53
|
+
|
54
|
+
# get query results. it feeds more rows until
|
55
|
+
# query execution finishes:
|
56
|
+
q.each_row {|row|
|
57
|
+
p row # row is an array
|
58
|
+
}
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
## Options
|
63
|
+
|
64
|
+
* **server** sets address (and port) of a Presto coordinator server.
|
65
|
+
* **ssl** enables https.
|
66
|
+
* Setting `true` enables SSL and verifies server certificate using system's built-in certificates.
|
67
|
+
* Setting `{verify: false}` enables SSL but doesn't verify server certificate.
|
68
|
+
* Setting a Hash object enables SSL and verify server certificate with options:
|
69
|
+
* **ca_file**: path of a CA certification file in PEM format
|
70
|
+
* **ca_path**: path of a CA certification directory containing certifications in PEM format
|
71
|
+
* **cert_store**: a `OpenSSL::X509::Store` object used for verification
|
72
|
+
* **client_cert**: a `OpenSSL::X509::Certificate` object as client certificate
|
73
|
+
* **client_key**: a `OpenSSL::PKey::RSA` or `OpenSSL::PKey::DSA` object used for client certificate
|
74
|
+
* **catalog** sets catalog (connector) name of Presto such as `hive-cdh4`, `hive-hadoop1`, etc.
|
75
|
+
* **schema** sets default schema name of Presto. You need to use qualified name like `FROM myschema.table1` to use non-default schemas.
|
76
|
+
* **source** sets source name to connect to a Presto. This name is shown on Presto web interface.
|
77
|
+
* **user** sets user name to connect to a Presto.
|
78
|
+
* **time_zone** sets time zone of queries. Time zone affects some functions such as `format_datetime`.
|
79
|
+
* **language** sets language of queries. Language affects some functions such as `format_datetime`.
|
80
|
+
* **properties** set session properties. Session properties affect internal behavior such as `hive.force_local_scheduling: true`, `raptor.reader_stream_buffer_size: "32MB"`, etc.
|
81
|
+
* **http_proxy** sets host:port of a HTTP proxy server.
|
82
|
+
* **http_debug** enables debug message to STDOUT for each HTTP requests.
|
83
|
+
* **http_open_timeout** sets timeout in seconds to open new HTTP connection.
|
84
|
+
* **http_timeout** sets timeout in seconds to read data from a server.
|
85
|
+
|
86
|
+
See [RDoc](http://www.rubydoc.info/gems/presto-client/) for the full documentation.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/clean'
|
6
|
+
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
10
|
+
t.fail_on_error = false
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => [:spec, :build]
|
14
|
+
|
15
|
+
GEN_MODELS_VERSION = "0.134"
|
16
|
+
|
17
|
+
task :modelgen do
|
18
|
+
unless Dir.exists?("presto-#{GEN_MODELS_VERSION}")
|
19
|
+
sh "curl -L -o presto-#{GEN_MODELS_VERSION}.tar.gz https://github.com/facebook/presto/archive/#{GEN_MODELS_VERSION}.tar.gz"
|
20
|
+
sh "tar zxvf presto-#{GEN_MODELS_VERSION}.tar.gz"
|
21
|
+
end
|
22
|
+
|
23
|
+
sh "#{RbConfig.ruby} modelgen/modelgen.rb presto-#{GEN_MODELS_VERSION} modelgen/models.rb lib/presto/client/models.rb"
|
24
|
+
puts "Generated lib/presto/client/models.rb."
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#
|
2
|
+
# Presto client for Ruby
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
module PrestoLegacy::Client
|
17
|
+
|
18
|
+
require 'presto/client/models'
|
19
|
+
require 'presto/client/query'
|
20
|
+
|
21
|
+
class Client
|
22
|
+
def initialize(options)
|
23
|
+
@options = options
|
24
|
+
end
|
25
|
+
|
26
|
+
def query(query, &block)
|
27
|
+
q = Query.start(query, @options)
|
28
|
+
if block
|
29
|
+
begin
|
30
|
+
yield q
|
31
|
+
ensure
|
32
|
+
q.close
|
33
|
+
end
|
34
|
+
else
|
35
|
+
return q
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def resume_query(next_uri)
|
40
|
+
return Query.resume(next_uri, @options)
|
41
|
+
end
|
42
|
+
|
43
|
+
def run(query)
|
44
|
+
q = Query.start(query, @options)
|
45
|
+
begin
|
46
|
+
columns = q.columns
|
47
|
+
if columns.empty?
|
48
|
+
return [], []
|
49
|
+
end
|
50
|
+
return columns, q.rows
|
51
|
+
ensure
|
52
|
+
q.close
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Accepts the raw response from the Presto Client and returns an
|
57
|
+
# array of hashes where you can access the data in each row using the
|
58
|
+
# output name specified in the query with AS:
|
59
|
+
# SELECT expression AS output_name
|
60
|
+
def run_with_names(query)
|
61
|
+
columns, rows = run(query)
|
62
|
+
|
63
|
+
column_names = columns.map(&:name)
|
64
|
+
|
65
|
+
rows.map do |row|
|
66
|
+
Hash[column_names.zip(row)]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.new(*args)
|
72
|
+
Client.new(*args)
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#
|
2
|
+
# Presto client for Ruby
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
module PrestoLegacy::Client
|
17
|
+
class PrestoError < StandardError
|
18
|
+
end
|
19
|
+
|
20
|
+
class PrestoHttpError < PrestoError
|
21
|
+
def initialize(status, message)
|
22
|
+
super(message)
|
23
|
+
@status = status
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_reader :status
|
27
|
+
end
|
28
|
+
|
29
|
+
class PrestoClientError < PrestoError
|
30
|
+
end
|
31
|
+
|
32
|
+
class PrestoQueryError < PrestoError
|
33
|
+
def initialize(message, query_id, error_code, failure_info)
|
34
|
+
super(message)
|
35
|
+
@query_id = query_id
|
36
|
+
@error_code = error_code
|
37
|
+
@failure_info = failure_info
|
38
|
+
end
|
39
|
+
|
40
|
+
attr_reader :error_code, :failure_info
|
41
|
+
end
|
42
|
+
end
|