vertica 1.0.0.rc1 → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,51 +1,41 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class ColumnTest < Minitest::Test
4
-
5
- def test_initialize_from_row_description
6
- field_description = {
4
+ def setup
5
+ @field_description = {
7
6
  :name => "OUTPUT",
8
7
  :table_oid => 0,
9
8
  :attribute_number => 0,
10
9
  :data_type_oid => 6,
11
10
  :data_type_size => 8,
12
11
  :data_type_modifier => 8,
13
- :format_code => 0
12
+ :data_format => 0
14
13
  }
14
+ end
15
15
 
16
- column = Vertica::Column.new(field_description)
16
+ def test_initialize_from_row_description
17
+ column = Vertica::Column.build(@field_description)
17
18
  assert_equal 'OUTPUT', column.name
18
- assert_equal :integer, column.data_type
19
- assert_equal 8, column.data_type_modifier
19
+ assert_equal 'integer', column.data_type.name
20
+ assert_equal 8, column.data_type.modifier
21
+ assert_equal 8, column.data_type.size
20
22
  end
21
23
 
22
24
  def test_unknown_type_oid
23
- field_description = {
24
- :name => "OUTPUT",
25
- :table_oid => 0,
26
- :attribute_number => 0,
27
- :data_type_oid => 123456,
28
- :data_type_size => 8,
29
- :data_type_modifier => 8,
30
- :format_code => 0
31
- }
32
-
33
- assert_raises(Vertica::Error::UnknownTypeError) { Vertica::Column.new(field_description) }
25
+ field_description = @field_description.merge(data_type_oid: 123456)
26
+ assert_raises(Vertica::Error::UnknownTypeError) { Vertica::Column.build(field_description) }
34
27
  end
35
28
 
36
- def test_integer_converter
37
- field_description = {
38
- :name => "OUTPUT",
39
- :table_oid => 0,
40
- :attribute_number => 0,
41
- :data_type_oid => 6,
42
- :data_type_size => 8,
43
- :data_type_modifier => 8,
44
- :format_code => 0
45
- }
29
+ def test_equality
30
+ column = Vertica::Column.build(@field_description)
31
+
32
+ assert_equal column, Vertica::Column.build(@field_description)
33
+ refute_equal column, Vertica::Column.build(@field_description.merge(name: 'other'))
34
+ refute_equal column, Vertica::Column.build(@field_description.merge(data_format: 1))
35
+ end
46
36
 
47
- column = Vertica::Column.new(field_description)
48
- assert_equal :integer, column.data_type
49
- assert_equal 1234, column.convert('1234')
37
+ def test_inspect
38
+ column = Vertica::Column.build(@field_description)
39
+ assert_equal '#<Vertica::Column name="OUTPUT" data_type=#<Vertica::DataType:6 "integer">>', column.inspect
50
40
  end
51
41
  end
@@ -0,0 +1,72 @@
1
+ require 'test_helper'
2
+
3
+ class DataTypeTest < Minitest::Test
4
+ def test_equality
5
+ type = Vertica::DataType.new(oid: 6, size: 4)
6
+
7
+ assert_equal type, Vertica::DataType.new(oid: 6, size: 4)
8
+ assert_equal type, Vertica::DataType.new(oid: 6, size: 4, modifier: nil)
9
+
10
+ refute_equal type, Vertica::DataType.new(oid: 6, size: 10)
11
+ refute_equal type, Vertica::DataType.new(oid: 6, size: 4, modifier: 'unsigned')
12
+ refute_equal type, Vertica::DataType.new(oid: 6, size: 1)
13
+ refute_equal type, Vertica::DataType.new(oid: 7, size: 4)
14
+ end
15
+
16
+ def test_inspect
17
+ type = Vertica::DataType.new(oid: 6, name: "integer", size: 4)
18
+ assert_equal '#<Vertica::DataType:6 "integer">', type.inspect
19
+ end
20
+
21
+ def test_deserialize_bool
22
+ type = Vertica::DataType.build(oid: 5)
23
+
24
+ assert_nil type.deserialize(nil)
25
+ assert_equal true, type.deserialize('t')
26
+ assert_equal false, type.deserialize('f')
27
+ assert_raises(ArgumentError) { type.deserialize('foo') }
28
+ end
29
+
30
+ def test_deserialize_integer
31
+ type = Vertica::DataType.build(oid: 6)
32
+
33
+ assert_nil type.deserialize(nil)
34
+ assert_equal 0, type.deserialize('0')
35
+ assert_equal -123, type.deserialize('-123')
36
+ assert_raises(ArgumentError) { type.deserialize('foo') }
37
+ end
38
+
39
+ def test_deserialize_float
40
+ type = Vertica::DataType.build(oid: 7)
41
+
42
+ assert_nil type.deserialize(nil)
43
+ assert_equal Float::INFINITY, type.deserialize('Infinity')
44
+ assert_equal -Float::INFINITY, type.deserialize('-Infinity')
45
+ assert type.deserialize('NaN').equal?(Float::NAN)
46
+ assert_equal 1.1, type.deserialize('1.1')
47
+ assert_equal -1.1, type.deserialize('-1.1')
48
+ assert_raises(ArgumentError) { type.deserialize('foo') }
49
+ end
50
+
51
+ def test_deserialize_unicode_string
52
+ type = Vertica::DataType.build(oid: 115)
53
+
54
+ assert_nil type.deserialize(nil)
55
+ converted = type.deserialize("foo\x00".force_encoding(Encoding::BINARY))
56
+ assert_equal "foo\x00".force_encoding(Encoding::UTF_8), converted
57
+ end
58
+
59
+ def test_dersialize_binary_string
60
+ type = Vertica::DataType.build(oid: 17)
61
+
62
+ assert_nil type.deserialize(nil)
63
+ converted = type.deserialize("\\231\\237".force_encoding(Encoding::BINARY))
64
+ assert_equal "\x99\x9F".force_encoding(Encoding::BINARY), converted
65
+ end
66
+
67
+ def test_deserialize_bigdecimal
68
+ type = Vertica::DataType.build(oid: 16)
69
+ assert_nil type.deserialize(nil)
70
+ assert_equal BigDecimal('1.1'), type.deserialize('1.1')
71
+ end
72
+ end
@@ -4,8 +4,8 @@ class ResultTest < Minitest::Test
4
4
  def setup
5
5
  @result = Vertica::Result.build(
6
6
  row_description: [
7
- Vertica::Column.new(name: 'a', data_type_oid: 6),
8
- Vertica::Column.new(name: 'b', data_type_oid: 6),
7
+ Vertica::Column.build(name: 'a', data_type_oid: 6),
8
+ Vertica::Column.build(name: 'b', data_type_oid: 6),
9
9
  ],
10
10
  rows: [
11
11
  [1, 2],
@@ -4,8 +4,8 @@ class RowDescriptionTest < Minitest::Test
4
4
  def setup
5
5
  @message = Vertica::Protocol::RowDescription.new("\x00\x02id\x00\x00\np8\x00\x01\x00\x00\x00\x06\x00\b\xFF\xFF\xFF\xFF\x00\x00name\x00\x00\np8\x00\x02\x00\x00\x00\t\xFF\xFF\x00\x00\x00h\x00\x00")
6
6
 
7
- @column1 = Vertica::Column.new(@message.fields[0])
8
- @column2 = Vertica::Column.new(@message.fields[1])
7
+ @column1 = Vertica::Column.build(@message.fields[0])
8
+ @column2 = Vertica::Column.build(@message.fields[1])
9
9
 
10
10
  @row_description = Vertica::RowDescription.build([@column1, @column2])
11
11
  end
@@ -53,4 +53,33 @@ class RowDescriptionTest < Minitest::Test
53
53
  hash = { 'id' => @column1, 'name' => @column2}
54
54
  assert_equal hash, @row_description.to_h
55
55
  end
56
+
57
+ def test_to_h_with_duplicate_column_name_raises
58
+ row_description = Vertica::RowDescription.build([@column1, @column1])
59
+ assert_raises(Vertica::Error::DuplicateColumnName) { row_description.to_h }
60
+ end
61
+
62
+ def test_eql?
63
+ rd1 = Vertica::RowDescription.build([@column1, @column2])
64
+ rd1_copy = Vertica::RowDescription.build([@column1, @column2])
65
+ rd2 = Vertica::RowDescription.build([@column1])
66
+
67
+ assert_equal rd1, rd1_copy
68
+ refute_equal rd1, rd2
69
+
70
+ refute_equal rd1, nil
71
+ refute_equal rd1, Vertica::RowDescription
72
+ refute_equal rd1, rd2.build_row([1])
73
+ end
74
+
75
+ def test_inspect
76
+ assert_equal "#<Vertica::RowDescription[id, name]>", @row_description.inspect
77
+ end
78
+
79
+ def test_build_row
80
+ row1 = @row_description.build_row([1, 'name'])
81
+ row2 = @row_description.build_row(id: 1, name: 'name')
82
+
83
+ assert_equal row1, row2
84
+ end
56
85
  end
@@ -4,8 +4,8 @@ class RowTest < Minitest::Test
4
4
  def setup
5
5
  @message = Vertica::Protocol::RowDescription.new("\x00\x02id\x00\x00\np8\x00\x01\x00\x00\x00\x06\x00\b\xFF\xFF\xFF\xFF\x00\x00name\x00\x00\np8\x00\x02\x00\x00\x00\t\xFF\xFF\x00\x00\x00h\x00\x00")
6
6
 
7
- @column1 = Vertica::Column.new(@message.fields[0])
8
- @column2 = Vertica::Column.new(@message.fields[1])
7
+ @column1 = Vertica::Column.build(@message.fields[0])
8
+ @column2 = Vertica::Column.build(@message.fields[1])
9
9
 
10
10
  @row_description = Vertica::RowDescription.build([@column1, @column2])
11
11
  end
@@ -28,4 +28,28 @@ class RowTest < Minitest::Test
28
28
  hash = { 'id' => 123, 'name' => 'test' }
29
29
  assert_equal hash, row.to_h
30
30
  end
31
+
32
+ def test_to_h_with_duplicate_column_name_raises
33
+ row_description = Vertica::RowDescription.build([@column1, @column1])
34
+ row = Vertica::Row.new(row_description, [123, 456])
35
+
36
+ assert_raises(Vertica::Error::DuplicateColumnName) { row.to_h }
37
+ end
38
+
39
+ def test_eql?
40
+ rd1 = Vertica::RowDescription.build([@column1, @column2])
41
+ rd2 = Vertica::RowDescription.build([@column1, @column1])
42
+
43
+ row = Vertica::Row.new(rd1, [123, 'test'])
44
+
45
+ assert_equal row, Vertica::Row.new(rd1, [123, 'test'])
46
+ refute_equal rd1, Vertica::Row.new(rd1, [124, 'test'])
47
+ refute_equal rd1, Vertica::Row.new(rd2, [123, 'test'])
48
+ refute_equal rd1, nil
49
+ end
50
+
51
+ def test_inspect
52
+ row = Vertica::Row.new(@row_description, [123, 'test'])
53
+ assert_equal "#<Vertica::Row[123, \"test\"]>", row.inspect
54
+ end
31
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vertica
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc1
4
+ version: 1.0.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Smick
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-07-05 00:00:00.000000000 Z
13
+ date: 2016-07-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -80,6 +80,7 @@ extra_rdoc_files:
80
80
  files:
81
81
  - .gitignore
82
82
  - .travis.yml
83
+ - .yardopts
83
84
  - Gemfile
84
85
  - LICENSE
85
86
  - README.md
@@ -87,6 +88,7 @@ files:
87
88
  - lib/vertica.rb
88
89
  - lib/vertica/column.rb
89
90
  - lib/vertica/connection.rb
91
+ - lib/vertica/data_type.rb
90
92
  - lib/vertica/error.rb
91
93
  - lib/vertica/protocol/backend/authentication.rb
92
94
  - lib/vertica/protocol/backend/backend_key_data.rb
@@ -131,11 +133,12 @@ files:
131
133
  - test/connection.yml.example
132
134
  - test/functional/functional_connection_test.rb
133
135
  - test/functional/functional_query_test.rb
134
- - test/functional/functional_value_conversion_test.rb
136
+ - test/functional/functional_type_deserialization_test.rb
135
137
  - test/resources/test_ruby_vertica_table.csv
136
138
  - test/test_helper.rb
137
139
  - test/unit/backend_message_test.rb
138
140
  - test/unit/column_test.rb
141
+ - test/unit/data_type_test.rb
139
142
  - test/unit/frontend_message_test.rb
140
143
  - test/unit/quoting_test.rb
141
144
  - test/unit/result_test.rb
@@ -172,11 +175,12 @@ test_files:
172
175
  - test/connection.yml.example
173
176
  - test/functional/functional_connection_test.rb
174
177
  - test/functional/functional_query_test.rb
175
- - test/functional/functional_value_conversion_test.rb
178
+ - test/functional/functional_type_deserialization_test.rb
176
179
  - test/resources/test_ruby_vertica_table.csv
177
180
  - test/test_helper.rb
178
181
  - test/unit/backend_message_test.rb
179
182
  - test/unit/column_test.rb
183
+ - test/unit/data_type_test.rb
180
184
  - test/unit/frontend_message_test.rb
181
185
  - test/unit/quoting_test.rb
182
186
  - test/unit/result_test.rb
@@ -1,117 +0,0 @@
1
- # encoding : UTF-8
2
- require 'test_helper'
3
-
4
- class FunctionalValueConversionTest < Minitest::Test
5
-
6
- def setup
7
- @connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
8
-
9
- @connection.query <<-SQL
10
- CREATE TABLE IF NOT EXISTS conversions_table (
11
- "int_field" int,
12
- "string_field" varchar(100),
13
- "date_field" date,
14
- "timestamp_field" timestamp,
15
- "timestamptz_field" timestamptz,
16
- "time_field" time,
17
- "interval_field" interval,
18
- "boolean_field" boolean,
19
- "float_field" float,
20
- "float_zero" float,
21
- "binary_field" varbinary,
22
- "long_varchar_field" long varchar
23
- )
24
- SQL
25
- end
26
-
27
-
28
- def teardown
29
- @connection.query("DROP TABLE IF EXISTS conversions_table CASCADE;")
30
- @connection.close
31
- end
32
-
33
- def test_value_conversions
34
- @connection.query <<-SQL
35
- INSERT INTO conversions_table VALUES (
36
- 123,
37
- 'hello world',
38
- '2010-01-01',
39
- '2010-01-01 12:00:00.123456',
40
- '2010-01-01 12:00:00 +0930',
41
- '12:00:00',
42
- INTERVAL '1 DAY',
43
- TRUE,
44
- 1.0,
45
- 0.0,
46
- HEX_TO_BINARY('d09fd180d0b8d0b2d0b5d1822c2068656c6c6f21'),
47
- 'hello world'
48
- )
49
- SQL
50
-
51
- result = @connection.query <<-SQL
52
- SELECT *,
53
- float_field / float_zero as infinity,
54
- float_field / float_zero - float_field / float_zero as nan
55
- FROM conversions_table LIMIT 1
56
- SQL
57
-
58
- assert_equal result.rows.length, 1
59
- assert_equal [
60
- 123,
61
- 'hello world',
62
- Date.parse('2010-01-01'),
63
- Time.new(2010, 1, 1, 12, 0, BigDecimal.new("0.123456")),
64
- Time.new(2010, 1, 1, 12, 0, 0, '+09:30'),
65
- "12:00:00",
66
- "1",
67
- true,
68
- 1.0,
69
- 0.0,
70
- ['d09fd180d0b8d0b2d0b5d1822c2068656c6c6f21'].pack('H*'),
71
- 'hello world',
72
- Float::INFINITY,
73
- Float::NAN
74
- ], result[0].to_a
75
- end
76
-
77
- def test_nil_conversions
78
- @connection.query "INSERT INTO conversions_table VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)"
79
- result = @connection.query "SELECT * FROM conversions_table LIMIT 1"
80
- assert_equal result.rows.length, 1
81
- assert_equal [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], result[0].to_a
82
- end
83
-
84
- def test_string_decoding
85
- assert_equal 'åßç∂ë', @connection.query("SELECT 'åßç∂ë'").the_value
86
- assert_equal Encoding::UTF_8, @connection.query("SELECT 'åßç∂ë'").the_value.encoding
87
- end
88
-
89
- def test_binary_decoding
90
- assert_equal ['d09fd180d0b8d0b2d0b5d1822c2068656c6c6f21'].pack('H*'), @connection.query("SELECT HEX_TO_BINARY('d09fd180d0b8d0b2d0b5d1822c2068656c6c6f21')").the_value
91
- assert_equal Encoding::BINARY, @connection.query("SELECT HEX_TO_BINARY('d09fd180d0b8d0b2d0b5d1822c2068656c6c6f21')").the_value.encoding
92
- end
93
-
94
- def test_timestamp_decoding_with_utc_timezone_connection
95
- @connection.query("SET TIMEZONE TO 'UTC'")
96
-
97
- assert_equal Time.new(2013, 1, 2, 14, 15, 16), @connection.query("SELECT '2013-01-02 14:15:16'::timestamp").the_value
98
- assert_equal Time.new(2013, 1, 2, 19, 15, 16), @connection.query("SELECT '2013-01-02 14:15:16 America/Toronto'::timestamp").the_value
99
- assert_equal Time.new(2013, 1, 2, 4, 45, 16), @connection.query("SELECT '2013-01-02 14:15:16 +9:30'::timestamp").the_value
100
-
101
- assert_equal Time.new(2013, 1, 2, 14, 15, 16, '+00:00'), @connection.query("SELECT '2013-01-02 14:15:16'::timestamptz").the_value
102
- assert_equal Time.new(2013, 1, 2, 19, 15, 16, '+00:00'), @connection.query("SELECT '2013-01-02 14:15:16 America/Toronto'::timestamptz").the_value
103
- assert_equal Time.new(2013, 1, 2, 4, 45, 16, '+00:00'), @connection.query("SELECT '2013-01-02 14:15:16 +09:30'::timestamptz").the_value
104
- end
105
-
106
- def test_timestamp_decoding_with_toronto_timezone_connection
107
- @connection.query("SET TIMEZONE TO 'America/Toronto'")
108
-
109
- assert_equal Time.new(2013, 1, 2, 14, 15, 16), @connection.query("SELECT '2013-01-02 14:15:16'::timestamp").the_value
110
- assert_equal Time.new(2013, 1, 2, 14, 15, 16), @connection.query("SELECT '2013-01-02 14:15:16 America/Toronto'::timestamp").the_value
111
- assert_equal Time.new(2013, 1, 1, 23, 45, 16), @connection.query("SELECT '2013-01-02 14:15:16 +9:30'::timestamp").the_value
112
-
113
- assert_equal Time.new(2013, 1, 2, 14, 15, 16, '-05:00'), @connection.query("SELECT '2013-01-02 14:15:16'::timestamptz").the_value
114
- assert_equal Time.new(2013, 1, 2, 14, 15, 16, '-05:00'), @connection.query("SELECT '2013-01-02 14:15:16 America/Toronto'::timestamptz").the_value
115
- assert_equal Time.new(2013, 1, 1, 23, 45, 16, '-05:00'), @connection.query("SELECT '2013-01-02 14:15:16 +09:30'::timestamptz").the_value
116
- end
117
- end