daru-td 0.1.1 → 0.2.0

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
  SHA1:
3
- metadata.gz: 631763c13dcea8476948aa9a158a0172e9f57e0b
4
- data.tar.gz: d07e39950c7e6652960f2f24cda6542ecead9d96
3
+ metadata.gz: 670482e222c3ba743ef4f8fceb62f21c7ace7191
4
+ data.tar.gz: 7f96f38abc3543d8e83d44365227edeff4a65f3e
5
5
  SHA512:
6
- metadata.gz: 2eb0c9b47059a55518b220411e7bb91579cd5dc03155055a88b49351fb22aea2ea54c467bc211887e4dc9bc8cd969d7f89d1d3d4e5ff83baa7c2f65875f2d6df
7
- data.tar.gz: 2e70fdf28a25e4183fde5538d1321f1847d3b8b5a75789cb9839a77027c571d19911b07b63f3e97dd3bd14e66a31734fa10dbd1866a8caf1120589e4a056b546
6
+ metadata.gz: 1b62680de8c4a441d542dbc7ea22a3920d707be76a9bb750c91f0f61de67227533bb648d9e66969c711f12af4ef96fb1ac4992e7b24cdc2091f3ac6ea65bf6fe
7
+ data.tar.gz: fe7f3df1871995feeaa3885224d424ea34a2351bf2c2201655e960845fbfe65f917a62c2509ee75af40afb006f51e28ef30ad58b19c41fe2b900cfdce9dc31ff
@@ -0,0 +1,13 @@
1
+ # Changes
2
+
3
+ ## 0.2.0
4
+
5
+ - :heavy_plus_sign: `Daru::TD.read_td_job`.
6
+
7
+ ## 0.1.1
8
+
9
+ - :bug: Fix a critical NameError
10
+
11
+ ## 0.1.0
12
+
13
+ - :tada: First release
data/README.md CHANGED
@@ -39,11 +39,18 @@ df_tables = conn.tables('db_name')
39
39
 
40
40
  ```ruby
41
41
  engine = Daru::TD.create_engine('presto:sample_datasets', conn:conn)
42
- df_result = Daru::TD.read_td_query(<<-SQL, engine)
42
+ df_query_result = Daru::TD.read_td_query(<<-SQL, engine)
43
43
  select * From nasdaq limit 3
44
44
  SQL
45
45
  ```
46
46
 
47
+ ### Read the result of the existing job
48
+
49
+ ```ruby
50
+ job_id = 12345678
51
+ df_job_result = Daru::TD.read_td_job(job_id, engine)
52
+ ```
53
+
47
54
  ## Development
48
55
 
49
56
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -58,6 +58,27 @@ module Daru
58
58
  clear_progress: clear_progress)
59
59
  end
60
60
 
61
+ # Read Treasure Data query into a Daru's DataFrame.
62
+ #
63
+ # Returns a Daru::DataFrame corresponding to the result set of the query string.
64
+ #
65
+ # @param query [String]
66
+ # Query string to be executed.
67
+ # @param engine [Daru::TD::QueryEngine]
68
+ # Handler returned by create_engine.
69
+ # @param parse_dates [Array, nil]
70
+ # When an Array given, it has column names to parse as dates.
71
+ # @param distributed_join [true, false]
72
+ # (Presto only) If true, distributed join is enabled.
73
+ # If false (default), broadcast join is used.
74
+ # See https://prestodb.io/docs/current/release/release-0.77.html
75
+ # @params kwargs [Hash, nil]
76
+ # Parameters to pass to execute method.
77
+ # Available parameters:
78
+ # - result_url [String] is result output URL.
79
+ # - priority [Integer, String] is job's priority (e.g. "NORMAL", "HIGH", etc.)
80
+ # - retry_limit [Integer] is retry limit.
81
+ # @return [Daru::DataFrame]
61
82
  def self.read_td_query(query, engine, **kwargs)
62
83
  distributed_join = kwargs.delete(:distributed_join)
63
84
  parse_dates = kwargs.delete(:parse_dates)
@@ -69,6 +90,24 @@ module Daru
69
90
  result.to_dataframe(parse_dates: parse_dates)
70
91
  end
71
92
 
93
+ # Read Treasure Data job result int a Daru's DataFrame.
94
+ #
95
+ # Returns a DataFrame corresponding to the result set of the job.
96
+ # This method waits for job completion if the specified job is still running.
97
+ #
98
+ # @param job_id [Integer] Job ID.
99
+ # @param engine [Daru::TD::QueryEngine]
100
+ # Handler returned by create_engine.
101
+ # @param parse_dates [Array, nil]
102
+ # When an Array given, it has column names to parse as dates.
103
+ # @return [Daru::DataFrame]
104
+ def self.read_td_job(job_id, engine, **kwargs)
105
+ parse_dates = kwargs.delete(:parse_dates)
106
+ job = QueryEngine::JobWrapper.new(engine.connection.client.job(job_id))
107
+ result = engine.get_result(job, wait: true)
108
+ result.to_dataframe(parse_dates: parse_dates)
109
+ end
110
+
72
111
  def self.parse_query(query_string)
73
112
  CGI.parse(query_string).tap do |hash|
74
113
  hash.keys.each do |key|
@@ -119,7 +119,9 @@ module Daru
119
119
  def render_progress_html_erb(given_binding)
120
120
  template = <<-'END_ERB'
121
121
  <div style="border-style: dashed; border-width: 1px;">
122
- <%=html_text("issued at #{job.issued_at.iso8601}") %>
122
+ <% if job.issued_at %>
123
+ <%= html_text("issued at #{job.issued_at.iso8601}") %>
124
+ <% end %>
123
125
  URL: <a href="<%=job.url %>" target="_blank"><%=job.url %></a><br>
124
126
  <% if job.type == :presto %>
125
127
  <% if job.debug && job.debug['cmdout'] %>
@@ -1,5 +1,5 @@
1
1
  module Daru
2
2
  module TD
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daru-td
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenta Murata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-24 00:00:00.000000000 Z
11
+ date: 2015-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -104,6 +104,7 @@ files:
104
104
  - ".gitignore"
105
105
  - ".rspec"
106
106
  - ".travis.yml"
107
+ - CHANGES.md
107
108
  - Gemfile
108
109
  - LICENSE.txt
109
110
  - README.md