vertica 0.9.0.beta1 → 0.9.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vertica (0.8.1)
4
+ vertica (0.9.0.beta1)
5
5
  vertica
6
6
 
7
7
  GEM
@@ -20,4 +20,5 @@ PLATFORMS
20
20
 
21
21
  DEPENDENCIES
22
22
  jeweler
23
+ rake
23
24
  vertica!
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.0.beta1
1
+ 0.9.0.beta2
@@ -18,11 +18,11 @@ module Vertica
18
18
  [:char, nil],
19
19
  [:varchar, nil],
20
20
  [:date, lambda { |s| Date.new(*s.split("-").map{|x| x.to_i}) }],
21
- [:time, lambda { |s| Time.parse(s) }],
21
+ [:time, nil],
22
22
  [:timestamp, lambda { |s| DateTime.parse(s, true) }],
23
23
  [:timestamp_tz, lambda { |s| DateTime.parse(s, true) }],
24
24
  [:interval, nil],
25
- [:time_tz, lambda { |s| Time.parse(s) }],
25
+ [:time_tz, nil],
26
26
  [:numeric, lambda { |s| s.to_d }],
27
27
  [:bytea, nil],
28
28
  [:rle_tuple, nil]
@@ -9,6 +9,8 @@ module Vertica
9
9
 
10
10
  attr_reader :options, :notices, :transaction_status, :backend_pid, :backend_key, :notifications, :parameters
11
11
 
12
+ attr_accessor :row_style
13
+
12
14
  def self.cancel(existing_conn)
13
15
  conn = self.new(existing_conn.options.merge(:skip_startup => true))
14
16
  conn.write Messages::CancelRequest.new(existing_conn.backend_pid, existing_conn.backend_key)
@@ -21,6 +23,8 @@ module Vertica
21
23
 
22
24
  @options = options
23
25
  @notices = []
26
+
27
+ @row_style = @options[:row_style] ? @options[:row_style] : :hash
24
28
 
25
29
  unless options[:skip_startup]
26
30
  write Messages::Startup.new(@options[:user], @options[:database])
@@ -140,7 +144,7 @@ module Vertica
140
144
 
141
145
 
142
146
  def process(return_result = false)
143
- result = return_result ? Result.new : nil
147
+ result = return_result ? Result.new(row_style) : nil
144
148
  loop do
145
149
  case message = read_message
146
150
  when Messages::Authentication
@@ -11,6 +11,7 @@ module Vertica
11
11
  pos = 2
12
12
  field_count.times do |field_index|
13
13
  size = data.unpack("@#{pos}N").first
14
+ size = -1 if size == 4294967295
14
15
  @values << (size == -1 ? nil : data.unpack("@#{pos + 4}a#{size}").first)
15
16
  pos += 4 + [size, 0].max
16
17
  end
@@ -6,7 +6,10 @@ module Vertica
6
6
  attr_reader :columns
7
7
  attr_reader :rows
8
8
 
9
- def initialize
9
+ attr_accessor
10
+
11
+ def initialize(row_style = :hash)
12
+ @row_style = row_style
10
13
  @rows = []
11
14
  end
12
15
 
@@ -14,11 +17,23 @@ module Vertica
14
17
  @columns = message.fields.map { |fd| Column.new(fd) }
15
18
  end
16
19
 
17
- def format_row(row_data)
20
+ def format_row_as_hash(row_data)
18
21
  row = {}
19
- row_data.values.each_with_index do |field, idx|
22
+ row_data.values.each_with_index do |value, idx|
20
23
  col = columns[idx]
21
- row[col.name] = col.convert(field)
24
+ row[col.name] = col.convert(value)
25
+ end
26
+ row
27
+ end
28
+
29
+ def format_row(row_data)
30
+ send("format_row_as_#{@row_style}", row_data)
31
+ end
32
+
33
+ def format_row_as_array(row_data)
34
+ row = []
35
+ row_data.values.each_with_index do |value, idx|
36
+ row << columns[idx].convert(value)
22
37
  end
23
38
  row
24
39
  end
@@ -16,7 +16,7 @@ class QueryTest < Test::Unit::TestCase
16
16
  @connection.close
17
17
  end
18
18
 
19
- def test_select_query_with_results
19
+ def test_select_query_with_results_as_hash
20
20
  r = @connection.query("SELECT * FROM test_table")
21
21
  assert_equal 1, r.row_count
22
22
  assert_equal 2, r.columns.length
@@ -25,9 +25,22 @@ class QueryTest < Test::Unit::TestCase
25
25
  assert_equal :varchar, r.columns[1].data_type
26
26
  assert_equal :name, r.columns[1].name
27
27
 
28
- # assert_equal [[1, 'matt']], r.rows
29
28
  assert_equal [{:id => 1, :name => "matt"}], r.rows
30
29
  end
30
+
31
+ def test_select_query_with_results_as_array
32
+ @connection.row_style = :array
33
+ r = @connection.query("SELECT * FROM test_table")
34
+ assert_equal 1, r.row_count
35
+ assert_equal 2, r.columns.length
36
+ assert_equal :in, r.columns[0].data_type
37
+ assert_equal :id, r.columns[0].name
38
+ assert_equal :varchar, r.columns[1].data_type
39
+ assert_equal :name, r.columns[1].name
40
+
41
+ assert_equal [[1, "matt"]], r.rows
42
+ end
43
+
31
44
 
32
45
  def test_select_query_with_no_results
33
46
  r = @connection.query("SELECT * FROM test_table WHERE 1 != 1")
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ class ValueConversionTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @connection = Vertica::Connection.new(TEST_CONNECTION_HASH.merge(:row_style => :array))
7
+
8
+ @connection.query <<-SQL
9
+ CREATE TABLE IF NOT EXISTS conversions_table (
10
+ "int_field" int,
11
+ "string_field" varchar(100),
12
+ "date_field" date,
13
+ "timestamp_field" timestamp,
14
+ "time_field" time,
15
+ "interval_field" interval,
16
+ "boolean_field" boolean
17
+ )
18
+ SQL
19
+ end
20
+
21
+
22
+ def teardown
23
+ @connection.query("DROP TABLE IF EXISTS conversions_table CASCADE;")
24
+ @connection.close
25
+ end
26
+
27
+ def test_value_conversions
28
+ @connection.query "INSERT INTO conversions_table VALUES (123, 'hello world', '2010-01-01', '2010-01-01 12:00:00', '12:00:00', INTERVAL '1 DAY', TRUE)"
29
+ result = @connection.query "SELECT * FROM conversions_table LIMIT 1"
30
+ assert_equal result.rows.length, 1
31
+ assert_equal [
32
+ 123,
33
+ 'hello world',
34
+ Date.parse('2010-01-01'),
35
+ DateTime.parse('2010-01-01 12:00:00'),
36
+ "12:00:00",
37
+ "1",
38
+ true], result.rows.first
39
+ end
40
+
41
+ def test_nil_conversions
42
+ @connection.query "INSERT INTO conversions_table VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL)"
43
+ result = @connection.query "SELECT * FROM conversions_table LIMIT 1"
44
+ assert_equal result.rows.length, 1
45
+ assert_equal [nil, nil, nil, nil, nil, nil, nil], result.rows.first
46
+ end
47
+ end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 9
8
8
  - 0
9
- - beta1
10
- version: 0.9.0.beta1
9
+ - beta2
10
+ version: 0.9.0.beta2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeff Smick
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-09-02 00:00:00 -04:00
19
+ date: 2011-09-09 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -71,6 +71,32 @@ dependencies:
71
71
  type: :development
72
72
  prerelease: false
73
73
  version_requirements: *id004
74
+ - !ruby/object:Gem::Dependency
75
+ name: jeweler
76
+ requirement: &id005 !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: *id005
87
+ - !ruby/object:Gem::Dependency
88
+ name: rake
89
+ requirement: &id006 !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: *id006
74
100
  description: Query Vertica with ruby
75
101
  email: sprsquish@gmail.com
76
102
  executables: []
@@ -126,6 +152,7 @@ files:
126
152
  - lib/vertica/result.rb
127
153
  - test/functional/connection_test.rb
128
154
  - test/functional/query_test.rb
155
+ - test/functional/value_conversion_test.rb
129
156
  - test/test_helper.rb
130
157
  - test/unit/backend_message_test.rb
131
158
  has_rdoc: true
@@ -165,5 +192,6 @@ summary: Pure ruby library for interacting with Vertica
165
192
  test_files:
166
193
  - test/functional/connection_test.rb
167
194
  - test/functional/query_test.rb
195
+ - test/functional/value_conversion_test.rb
168
196
  - test/test_helper.rb
169
197
  - test/unit/backend_message_test.rb