impala 0.3.1 → 0.4.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.
@@ -14,7 +14,6 @@ require 'impala/cursor'
14
14
  require 'impala/connection'
15
15
 
16
16
  module Impala
17
- KNOWN_COMMANDS = ['select', 'insert', 'show', 'describe', 'use', 'explain', 'create', 'drop', 'invalidate', 'with']
18
17
  DEFAULT_HOST = 'localhost'
19
18
  DEFAULT_PORT = 21000
20
19
  class InvalidQueryError < StandardError; end
@@ -84,10 +84,6 @@ module Impala
84
84
  raise InvalidQueryError.new("Empty query") if words.empty?
85
85
 
86
86
  command = words.first.downcase
87
- if !KNOWN_COMMANDS.include?(command)
88
- raise InvalidQueryError.new("Unrecognized command: '#{words.first}'")
89
- end
90
-
91
87
  ([command] + words[1..-1]).join(' ')
92
88
  end
93
89
 
@@ -70,6 +70,10 @@ module Impala
70
70
  !@done || !@row_buffer.empty?
71
71
  end
72
72
 
73
+ def runtime_profile
74
+ @service.GetRuntimeProfile(@handle)
75
+ end
76
+
73
77
  private
74
78
 
75
79
  def metadata
@@ -121,7 +125,7 @@ module Impala
121
125
  else
122
126
  raise ParsingError.new("Invalid value for boolean: #{value}")
123
127
  end
124
- when 'tinyint', 'int', 'bigint'
128
+ when 'tinyint', 'smallint', 'int', 'bigint'
125
129
  value.to_i
126
130
  when 'double', 'float'
127
131
  value.to_f
@@ -1,3 +1,3 @@
1
1
  module Impala
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -42,7 +42,6 @@ describe Impala::Connection do
42
42
 
43
43
  it 'should reject empty or invalid queries' do
44
44
  assert_raises(Impala::InvalidQueryError) { @connection.send(:sanitize_query, '')}
45
- assert_raises(Impala::InvalidQueryError) { @connection.send(:sanitize_query, 'HERRO herro herro')}
46
45
  end
47
46
  end
48
47
 
@@ -59,6 +59,11 @@ describe 'connected tests' do
59
59
  assert_equal([{:foo=>1.23}], ret, "the result should be a float")
60
60
  end
61
61
 
62
+ it 'can handle smallint values' do
63
+ ret = @connection.query('SELECT CAST(123 AS smallint) AS foo')
64
+ assert_equal([{:foo=>123}], ret, "the result should be an integer")
65
+ end
66
+
62
67
  it 'can handle float values' do
63
68
  ret = @connection.query('SELECT CAST(1.23 AS float) as foo')
64
69
  assert_instance_of(Float, ret.first[:foo], "the result should be a float")
@@ -77,6 +82,12 @@ describe 'connected tests' do
77
82
  it 'can successfully refresh the metadata store' do
78
83
  ret = @connection.refresh
79
84
  end
85
+
86
+ it 'can get the runtime profile from a cursor' do
87
+ cursor = @connection.execute('SELECT NOW() as foo')
88
+ ret = cursor.runtime_profile
89
+ assert_instance_of(String, ret, "the result should be a string")
90
+ end
80
91
  end
81
92
 
82
93
  describe 'with a test database' do
@@ -97,6 +108,7 @@ describe 'connected tests' do
97
108
  describe 'and a test table' do
98
109
  before do
99
110
  @table = "#{@database}.foobar"
111
+ @connection.query("DROP TABLE IF EXISTS #{@table}")
100
112
  @connection.query("CREATE TABLE #{@table} (i INT)")
101
113
  end
102
114
 
@@ -177,7 +189,11 @@ describe 'connected tests' do
177
189
  it 'can handle interspersed NULL values' do
178
190
  @connection.query("INSERT INTO #{@table} (i) SELECT NULL")
179
191
  res = @connection.query("SELECT * FROM #{@table} ORDER BY i DESC LIMIT 4")
180
- assert_equal([{:i => 1}, {:i => 1}, {:i => 1}, {:i => nil}], res)
192
+ assert_equal([{:i => nil}, {:i => 1}, {:i => 1}, {:i => 1}], res)
193
+ end
194
+
195
+ it 'can alter table add column' do
196
+ @connection.query("ALTER TABLE #{@table} ADD COLUMNS (new INT)")
181
197
  end
182
198
  end
183
199
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: impala
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-10 00:00:00.000000000 Z
12
+ date: 2014-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thrift