nexia-sequel-vertica 0.2.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b5e872968a5395400e5af3cb43624b5bb449baad
4
+ data.tar.gz: 0456c06d3b644c55ef5a5f25cee332df42c13f50
5
+ SHA512:
6
+ metadata.gz: 039af7ecb0fd587dc47010631d8c0bc8697cf0c64db3c1aa4f108b493f011ea0f5f4f32936f33516797d193c173309a9cf30abe1b5e8a86ea7f646562bc92821
7
+ data.tar.gz: 974da5305b4dac6a5975643198d1da336df67cf1ca54e77bbf4d6a5754121577344e8815da4b0c0505c3bbe508580ed91bf60cea4d287d7d33861c0850974e26
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ spec/spec_config.rb
19
+ .rbenv-version
20
+ vendor/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format doc
data/.travis.yml ADDED
@@ -0,0 +1,19 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.1
6
+
7
+ before_install:
8
+ - sudo wget -nv https://s3.amazonaws.com/circle-support-bucket/vertica_7.0.1-0_amd64.deb
9
+ - sudo dpkg -i vertica_7.0.1-0_amd64.deb
10
+ - sudo /opt/vertica/sbin/install_vertica --failure-threshold HALT --accept-eula --dba-user-password dbadmin --license CE -s localhost
11
+ - sudo -u dbadmin /opt/vertica/bin/adminTools -t create_db --database ci -s localhost -p dbadmin
12
+ # - sudo -u dbadmin openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /home/dbadmin/ci/v_ci_node0001_catalog/server.key -out /home/dbadmin/ci/v_ci_node0001_catalog/server.crt -batch
13
+ # - sudo -u dbadmin chmod 600 /home/dbadmin/ci/v_ci_node0001_catalog/server.key /home/dbadmin/ci/v_ci_node0001_catalog/server.crt
14
+ # - sudo -u dbadmin /opt/vertica/bin/adminTools -t stop_db --database ci -p dbadmin
15
+ # - sudo -u dbadmin sh -c 'echo "EnableSSL = 1" > /home/dbadmin/ci/v_ci_node0001_catalog/vertica.conf'
16
+ # - sudo -u dbadmin /opt/vertica/bin/adminTools -t start_db --database ci -p dbadmin
17
+
18
+ before_script:
19
+ - cp ./spec/spec_config.example.rb ./spec/spec_config.rb
data/CHANGELOG ADDED
@@ -0,0 +1,11 @@
1
+ 0.2.1
2
+
3
+ * Update sequel version
4
+
5
+ 0.2.0
6
+
7
+ * ???
8
+
9
+ 0.1.0
10
+
11
+ * Supports Vertica 6.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sequel-vertica.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # Sequel-vertica [![Build Status](https://travis-ci.org/camilo/sequel-vertica.svg?branch=travis)](https://travis-ci.org/camilo/sequel-vertica)
2
+
3
+ A third party adapter to use Vertica through sequel, most of the actual work is
4
+ done by sequel and the vertica gem.
5
+
6
+ ## Usage
7
+
8
+ The usage is straight forward as any other Sequel adapter, just make sure to
9
+ require sequel and the sequel-vertica gem.
10
+
11
+ ```ruby
12
+ require 'sequel'
13
+ require 'sequel-vertica'
14
+
15
+ $DB = Sequel.connect('vertica://user:pw@host/database_name')
16
+ ```
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc 'Default: run specs.'
7
+ task :default => :spec
8
+
9
+ desc "Run specs"
10
+ RSpec::Core::RakeTask.new #do |t|
11
+ #t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
12
+ # Put spec opts in a file named .rspec in root
13
+ #end
@@ -0,0 +1,4 @@
1
+ require 'sequel-vertica/version'
2
+ require 'sequel/adapters/vertica'
3
+
4
+ Sequel::Database::ADAPTERS << 'vertica'
@@ -0,0 +1,5 @@
1
+ module Sequel
2
+ module Vertica
3
+ VERSION = "0.2.1"
4
+ end
5
+ end
@@ -0,0 +1,156 @@
1
+ require 'vertica'
2
+
3
+ module Sequel
4
+ extension :core_extensions
5
+ module Vertica
6
+
7
+ class CreateTableGenerator < Sequel::Schema::CreateTableGenerator
8
+ def primary_key(name, *args)
9
+ super
10
+
11
+ if @primary_key[:auto_increment]
12
+ @primary_key.delete(:auto_increment)
13
+ @primary_key[:type] = Vertica::Database::AUTO_INCREMENT
14
+ end
15
+
16
+ @primary_key
17
+ end
18
+ end
19
+
20
+ class Database < Sequel::Database
21
+
22
+ ::Vertica::Connection.send(:alias_method, :execute, :query)
23
+
24
+ PK_NAME = 'C_PRIMARY'
25
+ AUTO_INCREMENT = 'AUTO_INCREMENT'
26
+ set_adapter_scheme :vertica
27
+
28
+ def connect(server)
29
+ opts = server_opts(server)
30
+ ::Vertica::Connection.new(
31
+ :host => opts[:host],
32
+ :user => opts[:user],
33
+ :password => opts[:password],
34
+ :port => opts[:port],
35
+ :schema => opts[:schema],
36
+ :database => opts[:database],
37
+ :read_timeout => opts[:read_timeout].nil? ? nil : opts[:read_timeout].to_i,
38
+ :ssl => opts[:ssl]
39
+ )
40
+ end
41
+
42
+ def execute(sql, opts = {}, &block)
43
+ res = nil
44
+ synchronize(opts[:server]) do |conn|
45
+ res = log_yield(sql) { conn.query(sql) }
46
+ res.each(&block)
47
+ end
48
+ res
49
+ rescue ::Vertica::Error => e
50
+ raise_error(e)
51
+ end
52
+
53
+ def execute_insert(sql, opts = {}, &block)
54
+ result = execute(sql, opts, &block)
55
+ result.first[:OUTPUT]
56
+ end
57
+
58
+ alias_method :execute_dui, :execute
59
+
60
+ def supports_create_table_if_not_exists?
61
+ true
62
+ end
63
+
64
+ def supports_drop_table_if_exists?
65
+ true
66
+ end
67
+
68
+ def supports_transaction_isolation_levels?
69
+ true
70
+ end
71
+
72
+ def identifier_input_method_default
73
+ nil
74
+ end
75
+
76
+ def identifier_output_method_default
77
+ nil
78
+ end
79
+
80
+ def locks
81
+ dataset.from(:v_monitor__locks)
82
+ end
83
+
84
+ def auto_increment_sql
85
+ AUTO_INCREMENT
86
+ end
87
+
88
+ def create_table_generator_class
89
+ Vertica::CreateTableGenerator
90
+ end
91
+
92
+ def tables(options = {})
93
+ schema = options[:schema]
94
+ filter = {}
95
+ filter[:table_schema] = schema.to_s if schema
96
+
97
+ dataset.select(:table_name).
98
+ from(:v_catalog__tables).
99
+ filter(filter).
100
+ to_a.
101
+ map { |h| h[:table_name].to_sym }
102
+ end
103
+
104
+ def schema_parse_table(table_name, options = {})
105
+ schema = options[:schema]
106
+
107
+ selector = [:column_name, :constraint_name, :is_nullable.as(:allow_null),
108
+ (:column_default).as(:default), (:data_type).as(:db_type)]
109
+ filter = { :columns__table_name => table_name }
110
+ filter[:columns__table_schema] = schema.to_s if schema
111
+
112
+ dataset = metadata_dataset.
113
+ select(*selector).
114
+ filter(filter).
115
+ from(:v_catalog__columns).
116
+ left_outer_join(:v_catalog__table_constraints, :table_id => :table_id)
117
+
118
+ dataset.map do |row|
119
+ row[:default] = nil if blank_object?(row[:default])
120
+ row[:type] = schema_column_type(row[:db_type])
121
+ row[:primary_key] = row.delete(:constraint_name) == PK_NAME
122
+ [row.delete(:column_name).to_sym, row]
123
+ end
124
+ end
125
+ end
126
+
127
+ class Dataset < Sequel::Dataset
128
+ Database::DatasetClass = self
129
+ EXPLAIN = 'EXPLAIN '
130
+ EXPLAIN_LOCAL = 'EXPLAIN LOCAL '
131
+ QUERY_PLAN = 'QUERY PLAN'
132
+
133
+ def columns
134
+ return @columns if @columns
135
+ ds = unfiltered.unordered.clone(:distinct => nil, :limit => 0, :offset => nil)
136
+ res = @db.execute(ds.select_sql)
137
+ @columns = res.columns.map { |c| c.name }
138
+ @columns
139
+ end
140
+
141
+ def fetch_rows(sql)
142
+ execute(sql) do |row|
143
+ yield row
144
+ end
145
+ end
146
+
147
+ def explain(opts={})
148
+ execute((opts[:local] ? EXPLAIN_LOCAL : EXPLAIN) + select_sql).map { |k, v| k == QUERY_PLAN }.join("\$")
149
+ end
150
+
151
+ def supports_regexp?
152
+ true
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/sequel-vertica/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "nexia-sequel-vertica"
6
+ gem.version = Sequel::Vertica::VERSION
7
+
8
+ gem.authors = ["Camilo Lopez"]
9
+ gem.email = ["camilo@camilolopez.com"]
10
+ gem.description = %q{Sequel adapter for the Vertica database}
11
+ gem.summary = %q{Sequel adapter for the Vertica database largely based on the PostgreSQL adapter}
12
+ gem.homepage = "https://github.com/camilo/sequel-vertica"
13
+ gem.license = "MIT"
14
+
15
+ gem.requirements = "Vertica version 6.0 or higher"
16
+ gem.required_ruby_version = '>= 1.9.3'
17
+
18
+ gem.add_runtime_dependency "sequel", "~> 4.14"
19
+ gem.add_runtime_dependency "vertica", "~> 0.11"
20
+
21
+ gem.add_development_dependency "rake", "~> 10.3"
22
+ gem.add_development_dependency "rspec" , "~> 3.1"
23
+
24
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ gem.files = `git ls-files`.split("\n")
26
+ gem.test_files = `git ls-files -- {spec}/*`.split("\n")
27
+
28
+ gem.require_paths = ["lib"]
29
+ end
@@ -0,0 +1,317 @@
1
+ require 'spec_helper'
2
+
3
+ unless defined?(VERTICA_DB)
4
+ VERTICA_URL = 'vertica://vertica:vertica@localhost:5432/reality_spec' unless defined? VERTICA_URL
5
+ VERTICA_DB = Sequel.connect(ENV['SEQUEL_VERTICA_SPEC_DB']||VERTICA_URL)
6
+ end
7
+ INTEGRATION_DB = VERTICA_DB unless defined?(INTEGRATION_DB)
8
+
9
+ def VERTICA_DB.sqls
10
+ (@sqls ||= [])
11
+ end
12
+
13
+
14
+ VERTICA_DB.create_table! :test do
15
+ varchar :name
16
+ integer :value
17
+ end
18
+ VERTICA_DB.create_table! :test2 do
19
+ varchar :name
20
+ integer :value
21
+ end
22
+ VERTICA_DB.create_table! :test3 do
23
+ integer :value
24
+ timestamp :time
25
+ end
26
+ VERTICA_DB.create_table! :test4 do
27
+ varchar :name, :size => 20
28
+ bytea :value
29
+ end
30
+
31
+ describe "A vertica sequel connection" do
32
+ specify "should set a read timeout" do
33
+ conn = Sequel.connect("#{ENV['SEQUEL_VERTICA_SPEC_DB']||VERTICA_URL}?read_timeout=1000")
34
+ conn.synchronize do |raw_conn|
35
+ expect(raw_conn.options[:read_timeout]).to eq(1000)
36
+ end
37
+ end
38
+ end
39
+
40
+ describe "A Vertica database" do
41
+
42
+ before do
43
+ @db = VERTICA_DB
44
+ end
45
+
46
+ specify "should correctly parse the schema" do
47
+ expect(@db.schema(:test3, :reload=>true)).to eq([
48
+ [:value, {:type=>:integer, :allow_null=>true, :default=>nil, :ruby_default=>nil, :db_type=>"int", :primary_key=>false}],
49
+ [:time, {:type=>:datetime, :allow_null=>true, :default=>nil, :ruby_default=>nil, :db_type=>"timestamp", :primary_key=>false}]
50
+ ])
51
+ expect(@db.schema(:test4, :reload=>true)).to eq([
52
+ [:name, {:allow_null=>true, :default=>nil, :db_type=>"varchar(20)", :type=>:string, :primary_key=>false, :ruby_default=>nil, :max_length=>20}],
53
+ [:value, {:allow_null=>true, :default=>nil, :db_type=>"varbinary(80)", :type=>:blob, :primary_key=>false, :ruby_default=>nil}]
54
+ ])
55
+ end
56
+
57
+ specify "should create an auto incrementing primary key" do
58
+ @db.create_table! :auto_inc_test do
59
+ primary_key :id
60
+ integer :value
61
+ end
62
+ expect(@db[<<-SQL].first[:COUNT]).to eq(1)
63
+ SELECT COUNT(1) FROM v_catalog.sequences WHERE identity_table_name='auto_inc_test'
64
+ SQL
65
+ end
66
+
67
+ end
68
+
69
+ describe "A vertica dataset" do
70
+ before do
71
+ @d = VERTICA_DB[:test]
72
+ @d.delete if @d.count > 0 # Vertica will throw an error if the table has just been created and does not have a super projection yet.
73
+ end
74
+
75
+ specify "should quote columns and tables using double quotes if quoting identifiers" do
76
+ expect(@d.select(:name).sql).to eq( \
77
+ 'SELECT "name" FROM "test"'
78
+ )
79
+
80
+ expect(@d.select(Sequel.lit('COUNT(*)')).sql).to eq( \
81
+ 'SELECT COUNT(*) FROM "test"'
82
+ )
83
+
84
+ expect(@d.select(:max.sql_function(:value)).sql).to eq( \
85
+ 'SELECT max("value") FROM "test"'
86
+ )
87
+
88
+ expect(@d.select(:NOW.sql_function).sql).to eq( \
89
+ 'SELECT NOW() FROM "test"'
90
+ )
91
+
92
+ expect(@d.select(:max.sql_function(:items__value)).sql).to eq( \
93
+ 'SELECT max("items"."value") FROM "test"'
94
+ )
95
+
96
+ expect(@d.order(:name.desc).sql).to eq( \
97
+ 'SELECT * FROM "test" ORDER BY "name" DESC'
98
+ )
99
+
100
+ expect(@d.select(Sequel.lit('test.name AS item_name')).sql).to eq( \
101
+ 'SELECT test.name AS item_name FROM "test"'
102
+ )
103
+
104
+ expect(@d.select(Sequel.lit('"name"')).sql).to eq( \
105
+ 'SELECT "name" FROM "test"'
106
+ )
107
+
108
+ expect(@d.select(Sequel.lit('max(test."name") AS "max_name"')).sql).to eq( \
109
+ 'SELECT max(test."name") AS "max_name" FROM "test"'
110
+ )
111
+
112
+ expect(@d.insert_sql(:x => :y)).to match( \
113
+ /\AINSERT INTO "test" \("x"\) VALUES \("y"\)( RETURNING NULL)?\z/
114
+ )
115
+
116
+ end
117
+
118
+ specify "should quote fields correctly when reversing the order if quoting identifiers" do
119
+ expect(@d.reverse_order(:name).sql).to eq( \
120
+ 'SELECT * FROM "test" ORDER BY "name" DESC'
121
+ )
122
+
123
+ expect(@d.reverse_order(:name.desc).sql).to eq( \
124
+ 'SELECT * FROM "test" ORDER BY "name" ASC'
125
+ )
126
+
127
+ expect(@d.reverse_order(:name, :test.desc).sql).to eq( \
128
+ 'SELECT * FROM "test" ORDER BY "name" DESC, "test" ASC'
129
+ )
130
+
131
+ expect(@d.reverse_order(:name.desc, :test).sql).to eq( \
132
+ 'SELECT * FROM "test" ORDER BY "name" ASC, "test" DESC'
133
+ )
134
+ end
135
+
136
+ specify "should support regexps" do
137
+ @d << {:name => 'abc', :value => 1}
138
+ @d << {:name => 'bcd', :value => 2}
139
+
140
+ expect(@d.filter(:name => /bc/).count).to eq(2)
141
+ expect(@d.filter(:name => /^bc/).count).to eq(1)
142
+ end
143
+
144
+ specify "#columns should return the correct column names" do
145
+ expect(@d.columns!).to eq([:name, :value])
146
+ expect(@d.select(:name).columns!).to eq([:name])
147
+ end
148
+ end
149
+
150
+
151
+ describe "A Vertica dataset with a timestamp field" do
152
+ before do
153
+ @db = VERTICA_DB
154
+ @d = @db[:test3]
155
+ @d.delete if @d.count > 0 # Vertica will throw an error if the table has just been created and does not have a super projection yet.
156
+ end
157
+ after do
158
+ @db.convert_infinite_timestamps = false if @db.adapter_scheme == :postgres
159
+ end
160
+
161
+ cspecify "should store milliseconds in time fields for Time objects", :do, :swift do
162
+ t = Time.now
163
+ @d << {:value=>1, :time=>t}
164
+ t2 = @d[:value =>1][:time]
165
+ expect(@d.literal(t2)).to eq(@d.literal(t))
166
+ expect(t2.strftime('%Y-%m-%d %H:%M:%S')).to eq(t.strftime('%Y-%m-%d %H:%M:%S'))
167
+ expect(t2.is_a?(Time) ? t2.usec : t2.strftime('%N').to_i/1000).to eq(t.usec)
168
+ end
169
+
170
+ cspecify "should store milliseconds in time fields for DateTime objects", :do, :swift do
171
+ t = DateTime.now
172
+ @d << {:value=>1, :time=>t}
173
+ t2 = @d[:value =>1][:time]
174
+ expect(@d.literal(t2)).to eq(@d.literal(t))
175
+ expect(t2.strftime('%Y-%m-%d %H:%M:%S')).to eq(t.strftime('%Y-%m-%d %H:%M:%S'))
176
+ expect(t2.is_a?(Time) ? t2.usec : t2.strftime('%N').to_i/1000).to eq(t.strftime('%N').to_i/1000)
177
+ end
178
+
179
+ describe "Verticas's EXPLAIN and EXPLAIN LOCAL" do
180
+ specify "should not raise errors" do
181
+ @d = VERTICA_DB[:test3]
182
+ expect{@d.explain}.not_to raise_error
183
+ expect{@d.explain(:local => true)}.not_to raise_error
184
+ end
185
+ end
186
+
187
+ end
188
+
189
+
190
+ describe "A Vertica database" do
191
+ before do
192
+ @db = VERTICA_DB
193
+ end
194
+
195
+ specify "should support ALTER TABLE DROP COLUMN" do
196
+ @db.create_table!(:test3) { varchar :name; integer :value }
197
+ expect(@db[:test3].columns).to eq([:name, :value])
198
+ @db.drop_column :test3, :value
199
+ expect(@db[:test3].columns).to eq([:name])
200
+ end
201
+
202
+ specify "It does not support ALTER TABLE ALTER COLUMN TYPE" do
203
+ @db.create_table!(:test4) { varchar :name; integer :value }
204
+ expect{ @db.set_column_type :test4, :value, :float }.to raise_error(Sequel::DatabaseError,
205
+ /Syntax error at or near "TYPE"/)
206
+ end
207
+
208
+ specify "should support rename column operations" do
209
+ @db.create_table!(:test5) { varchar :name; integer :value }
210
+ @db[:test5] << {:name => 'mmm', :value => 111}
211
+ @db.rename_column :test5, :value, :val
212
+ expect(@db[:test5].columns).to eq([:name, :val])
213
+ expect(@db[:test5].first[:val]).to eq(111)
214
+ end
215
+
216
+ specify "should support add column operations" do
217
+ @db.create_table!(:test2) { varchar :name; integer :value }
218
+ expect(@db[:test2].columns).to eq([:name, :value])
219
+
220
+ @db.add_column :test2, :xyz, :varchar, :default => '000'
221
+ expect(@db[:test2].columns).to eq([:name, :value, :xyz])
222
+ @db[:test2] << {:name => 'mmm', :value => 111}
223
+ expect(@db[:test2].first[:xyz]).to eq('000')
224
+ end
225
+
226
+ specify "#locks should be a dataset returning database locks " do
227
+ expect(@db.locks).to be_a_kind_of(Sequel::Dataset)
228
+ expect(@db.locks.all).to be_a_kind_of(Array)
229
+ end
230
+ end
231
+
232
+ describe "Vertica::Dataset#insert" do
233
+ before do
234
+ @db = VERTICA_DB
235
+ @db.create_table!(:test5){ :xid; Integer :value}
236
+ @db.sqls.clear
237
+ @ds = @db[:test5]
238
+ end
239
+
240
+ after do
241
+ @db.drop_table?(:test5)
242
+ end
243
+
244
+ specify "should work with static SQL" do
245
+ expect(@ds.with_sql('INSERT INTO test5 (value) VALUES (10)').insert).to eq(1)
246
+ expect(@db['INSERT INTO test5 (value) VALUES (20)'].insert).to eq(1)
247
+ expect(@ds.all).to include({:value=>10}, {:value=>20})
248
+ end
249
+
250
+ specify "should insert correctly if using a column array and a value array" do
251
+ expect(@ds.insert([:value], [10])).to eq(1)
252
+ expect(@ds.all).to eq([{:value=>10}])
253
+ end
254
+ end
255
+
256
+ describe "Vertica::Database schema qualified tables" do
257
+ before do
258
+ VERTICA_DB << "CREATE SCHEMA schema_test"
259
+ VERTICA_DB.instance_variable_set(:@primary_keys, {})
260
+ VERTICA_DB.instance_variable_set(:@primary_key_sequences, {})
261
+ end
262
+
263
+ after do
264
+ VERTICA_DB << "DROP SCHEMA schema_test CASCADE"
265
+ end
266
+
267
+ specify "should be able to create, drop, select and insert into tables in a given schema" do
268
+ VERTICA_DB.create_table(:schema_test__table_in_schema_test){integer :i}
269
+ expect(VERTICA_DB[:schema_test__table_in_schema_test].first).to eq(nil)
270
+ expect(VERTICA_DB[:schema_test__table_in_schema_test].insert(:i=>1)).to eq(1)
271
+ expect(VERTICA_DB[:schema_test__table_in_schema_test].first).to eq({:i=>1})
272
+ expect(VERTICA_DB.from(Sequel.lit('schema_test.table_in_schema_test')).first).to eq({:i=>1})
273
+ VERTICA_DB.drop_table(:schema_test__table_in_schema_test)
274
+ VERTICA_DB.create_table(:table_in_schema_test.qualify(:schema_test)){integer :i}
275
+ expect(VERTICA_DB[:schema_test__table_in_schema_test].first).to eq(nil)
276
+ expect(VERTICA_DB.from(Sequel.lit('schema_test.table_in_schema_test')).first).to eq(nil)
277
+ VERTICA_DB.drop_table(:table_in_schema_test.qualify(:schema_test))
278
+ end
279
+
280
+ specify "#tables should not include tables in a default non-public schema" do
281
+ VERTICA_DB.create_table(:schema_test__table_in_schema_test){integer :i}
282
+ expect(VERTICA_DB.tables).to include(:table_in_schema_test)
283
+ expect(VERTICA_DB.tables).not_to include(:tables)
284
+ expect(VERTICA_DB.tables).not_to include(:columns)
285
+ expect(VERTICA_DB.tables).not_to include(:locks)
286
+ expect(VERTICA_DB.tables).not_to include(:domain_udt_usage)
287
+ end
288
+
289
+ specify "#tables should return tables in the schema provided by the :schema argument" do
290
+ VERTICA_DB.create_table(:schema_test__table_in_schema_test){integer :i}
291
+ expect(VERTICA_DB.tables(:schema=>:schema_test)).to eq([:table_in_schema_test])
292
+ end
293
+
294
+ specify "#schema should not include columns from tables in a default non-public schema" do
295
+ VERTICA_DB.create_table(:schema_test__domains){integer :i}
296
+ sch = VERTICA_DB.schema(:domains)
297
+ cs = sch.map{|x| x.first}
298
+ expect(cs).to include(:i)
299
+ expect(cs).not_to include(:data_type)
300
+ end
301
+
302
+ specify "#schema should only include columns from the table in the given :schema argument" do
303
+ VERTICA_DB.create_table!(:domains){integer :d}
304
+ VERTICA_DB.create_table(:schema_test__domains){integer :i}
305
+ sch = VERTICA_DB.schema(:domains, :schema=>:schema_test)
306
+ cs = sch.map{|x| x.first}
307
+ expect(cs).to include(:i)
308
+ expect(cs).not_to include(:d)
309
+ VERTICA_DB.drop_table(:domains)
310
+ end
311
+
312
+ specify "#table_exists? should see if the table is in a given schema" do
313
+ VERTICA_DB.create_table(:schema_test__schema_test){integer :i}
314
+ expect(VERTICA_DB.table_exists?(:schema_test__schema_test)).to eq(true)
315
+ end
316
+
317
+ end
@@ -0,0 +1 @@
1
+ VERTICA_URL = 'vertica://dbadmin:dbadmin@127.0.0.1:5433/ci'
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'logger'
3
+ require 'sequel'
4
+
5
+ begin
6
+ require 'spec_config'
7
+ rescue LoadError
8
+ $stderr.puts "Please create a file spec/spec_config.rb with a database connection string."
9
+ raise
10
+ end
11
+
12
+ if ENV['SEQUEL_COLUMNS_INTROSPECTION']
13
+ Sequel.extension :columns_introspection
14
+ Sequel::Dataset.introspect_all_columns
15
+ end
16
+
17
+
18
+ Sequel.cache_anonymous_models = false
19
+
20
+ class Sequel::Database
21
+ def log_duration(duration, message)
22
+ log_info(message)
23
+ end
24
+ end
25
+
26
+ (defined?(RSpec) ? RSpec::Core::ExampleGroup : Spec::Example::ExampleGroup).class_eval do
27
+ def log
28
+ begin
29
+ INTEGRATION_DB.loggers << Logger.new(STDOUT)
30
+ yield
31
+ ensure
32
+ INTEGRATION_DB.loggers.pop
33
+ end
34
+ end
35
+
36
+ def self.cspecify(message, *checked, &block)
37
+ return specify(message, &block) if ENV['SEQUEL_NO_PENDING']
38
+ pending = false
39
+ checked.each do |c|
40
+ case c
41
+ when INTEGRATION_DB.adapter_scheme
42
+ pending = c
43
+ when Proc
44
+ pending = c if c.first.call(INTEGRATION_DB)
45
+ when Array
46
+ pending = c if c.first == INTEGRATION_DB.adapter_scheme && c.last == INTEGRATION_DB.call(INTEGRATION_DB)
47
+ end
48
+ end
49
+ if pending
50
+ specify(message){pending("Not yet working on #{Array(pending).join(', ')}", &block)}
51
+ else
52
+ specify(message, &block)
53
+ end
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nexia-sequel-vertica
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Camilo Lopez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sequel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.14'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: vertica
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.11'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
69
+ description: Sequel adapter for the Vertica database
70
+ email:
71
+ - camilo@camilolopez.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CHANGELOG
80
+ - Gemfile
81
+ - README.md
82
+ - Rakefile
83
+ - lib/sequel-vertica.rb
84
+ - lib/sequel-vertica/version.rb
85
+ - lib/sequel/adapters/vertica.rb
86
+ - sequel-vertica.gemspec
87
+ - spec/adapters/vertica_spec.rb
88
+ - spec/spec_config.example.rb
89
+ - spec/spec_helper.rb
90
+ homepage: https://github.com/camilo/sequel-vertica
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 1.9.3
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements:
109
+ - Vertica version 6.0 or higher
110
+ rubyforge_project:
111
+ rubygems_version: 2.2.2
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Sequel adapter for the Vertica database largely based on the PostgreSQL adapter
115
+ test_files: []