rbhive 0.2.4 → 0.2.5

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.
@@ -56,6 +56,13 @@ module RBHive
56
56
  execute_safe(query)
57
57
  end
58
58
 
59
+ def explain(query)
60
+ safe do
61
+ execute_unsafe("EXPLAIN "+ query)
62
+ ExplainResult.new(client.fetchAll)
63
+ end
64
+ end
65
+
59
66
  def priority=(priority)
60
67
  set("mapred.job.priority", priority)
61
68
  end
@@ -0,0 +1,46 @@
1
+ class ExplainResult
2
+ def initialize(rows)
3
+ @rows = rows
4
+ end
5
+
6
+ def ast
7
+ by_section[:abstract_syntax_tree].first
8
+ end
9
+
10
+ def stage_count
11
+ stage_dependencies.length
12
+ end
13
+
14
+ def stage_dependencies
15
+ by_section[:stage_dependencies] || []
16
+ end
17
+
18
+ def to_tsv
19
+ @rows.join("\n")
20
+ end
21
+
22
+ def raw
23
+ @rows
24
+ end
25
+
26
+ def to_s
27
+ to_tsv
28
+ end
29
+
30
+ private
31
+
32
+ def by_section
33
+ current_section = nil
34
+ @rows.inject({}) do |sections, row|
35
+ if row.match(/^[A-Z]/)
36
+ current_section = row.chomp(':').downcase.gsub(' ', '_').to_sym
37
+ sections[current_section] = []
38
+ elsif row.length == 0
39
+ next sections
40
+ else
41
+ sections[current_section] << row.strip
42
+ end
43
+ sections
44
+ end
45
+ end
46
+ end
data/lib/rbhive.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require File.join(File.dirname(__FILE__), 'rbhive', 'connection')
2
2
  require File.join(File.dirname(__FILE__), 'rbhive', 'table_schema')
3
3
  require File.join(File.dirname(__FILE__), 'rbhive', 'result_set')
4
+ require File.join(File.dirname(__FILE__), 'rbhive', 'explain_result')
4
5
  require File.join(File.dirname(__FILE__), 'rbhive', 'schema_definition')
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbhive
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 4
10
- version: 0.2.4
9
+ - 5
10
+ version: 0.2.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Forward Internet Group
@@ -47,6 +47,7 @@ files:
47
47
  - lib/rbhive/connection.rb
48
48
  - lib/rbhive/table_schema.rb
49
49
  - lib/rbhive/result_set.rb
50
+ - lib/rbhive/explain_result.rb
50
51
  - lib/rbhive/schema_definition.rb
51
52
  - lib/thrift/facebook_service.rb
52
53
  - lib/thrift/fb303_constants.rb