gooddata_datawarehouse 0.0.9 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbb47425e959803a032aadd5eafa8b1b40c0ba1695648a49c8c3bed737be40b2
4
- data.tar.gz: c81839b299f2c9cab6a5cced6fa403e7edd9f287fa05d02aa5d23c52139dd9ae
3
+ metadata.gz: f0d852dbd45a214766536c58b9ac732d6cb7574fc3e1c9a7bddbad590da2cdd9
4
+ data.tar.gz: b1b5f7e172325dd8b8c557637fecb49c08438da69a2cf6b077a8ce76d8d55131
5
5
  SHA512:
6
- metadata.gz: 5225c46a79009619c6eaab6651d3d8f3d5f636572daa1db6ab9a27240a78e85bb77d7312957b89733da5df1a784c48fe7acb81f5ee5d2fdb1e625c43c4b3945d
7
- data.tar.gz: 9eaf09fb89d312a544f33d357505ce95b44c3f5a1068ecce6a4dbbe80e06a99b2442050678976d866f6ea4023f452cd66d0fb19bc9cb725751ab55b47ec49f76
6
+ metadata.gz: 3e1928a456fd547a04ab20718e8f53cb3f28e933a617ce5e656ba31d703172352a0c1b3c4b20f2d3b2f4529bbd74fd1fa0656f44f7f005d1e0a41425dc822215
7
+ data.tar.gz: 9f6b2f9ee5fbf39033fe0aa7894d11a0f29b4f8b1c949280c80b84ed1caef5ac6a378c05f1556e1e0460668cc71206d0edfe6e643161336ac5de5aa1211799a0
@@ -0,0 +1,25 @@
1
+ name: build
2
+ on:
3
+ push:
4
+ branches: [master]
5
+ jobs:
6
+ jruby-gem-release:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ with:
11
+ fetch-depth: 0
12
+ - uses: actions/setup-java@v2
13
+ with:
14
+ java-version: '11'
15
+ distribution: 'adopt'
16
+ - uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: 'jruby-9.4.0'
19
+ bundler-cache: true
20
+ - name: Run gem release
21
+ run: |
22
+ mkdir -p ~/.gem
23
+ echo -e "---\n:rubygems_api_key: ${{ secrets.RUBYGEMS_API_KEY }}" > ~/.gem/credentials
24
+ chmod 0600 ~/.gem/credentials
25
+ bundle exec rake gem:release
data/README.md CHANGED
@@ -50,6 +50,12 @@ dwh = GoodData::Datawarehouse.new('you@gooddata.com', 'yourpass', 'your ADS inst
50
50
  # for custom jdbc url do:
51
51
  # dwh = GoodData::Datawarehouse.new('you@gooddata.com', 'yourpass', nil, :jdbc_url => 'jdbc:dss://whatever.com/something')
52
52
 
53
+ # connect with SST (available from version 0.0.10)
54
+ # dwh = GoodData::Datawarehouse.new_instance(:instance_id => 'your ADS instance id', :sst => 'SST token')
55
+ # for custom jdbc url do:
56
+ # dwh = GoodData::Datawarehouse.new_instance(:jdbc_url => 'jdbc:dss://whatever.com/something', :sst => 'SST token')
57
+
58
+
53
59
  # import a csv
54
60
  dwh.csv_to_new_table('my_table', 'path/to/my.csv')
55
61
 
data/Rakefile CHANGED
@@ -1,8 +1,13 @@
1
- require 'coveralls/rake/task'
1
+ require 'rubygems'
2
+
3
+ require 'bundler/setup'
4
+ require 'bundler/cli'
5
+ require 'bundler/gem_tasks'
2
6
  require 'rake/testtask'
7
+ require 'coveralls/rake/task'
3
8
  require 'rspec/core/rake_task'
4
9
 
5
- Coveralls::RakeTask.new
10
+ RSpec::Core::RakeTask.new(:test)
6
11
 
7
12
  task default: %w[ci]
8
13
 
@@ -17,4 +22,20 @@ namespace :test do
17
22
  RSpec::Core::RakeTask.new(:unit) do |t|
18
23
  t.pattern = 'spec/**/*.rb'
19
24
  end
20
- end
25
+ end
26
+
27
+ namespace :gem do
28
+ desc "Release gem version #{GoodData::Datawarehouse} to rubygems"
29
+ task :release do
30
+ gem = "gooddata_datawarehouse-#{GoodData::Datawarehouse}.gem"
31
+ puts "Building #{gem} ..."
32
+ res = `gem build ./gooddata_datawarehouse.gemspec`
33
+ file = res.match('File: (.*)')[1]
34
+ next unless file
35
+
36
+ puts "Pushing #{file} ..."
37
+ system("gem push #{file}")
38
+ end
39
+ end
40
+
41
+
@@ -18,17 +18,21 @@ Gem::Specification.new do |spec|
18
18
  spec.license = "MIT"
19
19
 
20
20
  spec.files = `git ls-files -z`.split("\x0")
21
+ spec.files.reject! { |fn| fn.start_with? 'spec/', 'data', 'Dockerfile' }
22
+ spec.files.reject! { |fn| fn.end_with? '.sh' }
21
23
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
24
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
25
  spec.require_paths = ["lib"]
24
26
 
25
- spec.add_development_dependency "bundler", "~> 1.7"
26
- spec.add_development_dependency "rake", "~> 10.3"
27
+ spec.add_development_dependency "bundler", "~> 2.3"
28
+ spec.add_development_dependency 'gooddata-crypto', '~> 0.1'
29
+ spec.add_development_dependency "rake", "~> 11.1"
27
30
  spec.add_development_dependency 'rspec', '~>3.8'
28
31
  spec.add_development_dependency 'pry', '~> 0.9'
29
32
  spec.add_development_dependency 'coveralls', '~> 0.7', '>= 0.7.0'
30
33
 
31
- spec.add_dependency "sequel", "~> 4.17"
32
- spec.add_dependency "gooddata-dss-jdbc", "~> 0.2.4"
34
+ spec.add_dependency "sequel", "~> 5.60"
35
+ spec.add_dependency "gooddata-dss-jdbc", "~> 0.2.7"
33
36
  spec.add_dependency "pmap", "~> 1.0"
37
+
34
38
  end
@@ -10,14 +10,17 @@ require_relative 'sql_generator'
10
10
  module GoodData
11
11
  class Datawarehouse
12
12
  PARALEL_COPY_THREAD_COUNT = 10
13
+
14
+ def self.new_instance(opts={})
15
+ self.new(opts[:username], opts[:password], opts[:instance_id], opts)
16
+ end
17
+
13
18
  def initialize(username, password, instance_id, opts={})
14
19
  @logger = Logger.new(STDOUT)
15
20
  @username = username
16
21
  @password = password
22
+ @sst_token = opts[:sst]
17
23
  @jdbc_url = opts[:jdbc_url] || "jdbc:gdc:datawarehouse://secure.gooddata.com/gdc/datawarehouse/instances/#{instance_id}"
18
- if @username.nil? || @password.nil?
19
- fail ArgumentError, "username and/or password are nil. All of them are mandatory."
20
- end
21
24
 
22
25
  if instance_id.nil? && opts[:jdbc_url].nil?
23
26
  fail ArgumentError, "you must either provide instance_id or jdbc_url option."
@@ -192,11 +195,15 @@ module GoodData
192
195
  end
193
196
 
194
197
  def connect
195
- Sequel.connect @jdbc_url,
196
- :username => @username,
197
- :password => @password do |connection|
198
- yield(connection)
198
+ if @username.to_s.empty? || @password.to_s.empty?
199
+ @connection = Sequel.connect(@jdbc_url, :driver => Java.com.gooddata.dss.jdbc.driver.DssDriver, :jdbc_properties => {'sst' => @sst_token})
200
+ else
201
+ @connection = Sequel.connect(@jdbc_url, :username => @username, :password => @password)
199
202
  end
203
+ yield(@connection)
204
+ ensure
205
+ @connection.disconnect unless @connection.nil?
206
+ Sequel.synchronize{::Sequel::DATABASES.delete(@connection)}
200
207
  end
201
208
 
202
209
  private
@@ -1,5 +1,5 @@
1
1
  module GoodData
2
2
  class Datawarehouse
3
- VERSION = "0.0.9"
3
+ VERSION = "0.0.11"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,21 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gooddata_datawarehouse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petr Cvengros
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-07 00:00:00.000000000 Z
11
+ date: 2023-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '1.7'
18
+ version: '2.3'
19
19
  name: bundler
20
20
  prerelease: false
21
21
  type: :development
@@ -23,13 +23,27 @@ dependencies:
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
26
+ version: '2.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '10.3'
32
+ version: '0.1'
33
+ name: gooddata-crypto
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '11.1'
33
47
  name: rake
34
48
  prerelease: false
35
49
  type: :development
@@ -37,7 +51,7 @@ dependencies:
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '10.3'
54
+ version: '11.1'
41
55
  - !ruby/object:Gem::Dependency
42
56
  requirement: !ruby/object:Gem::Requirement
43
57
  requirements:
@@ -91,7 +105,7 @@ dependencies:
91
105
  requirements:
92
106
  - - "~>"
93
107
  - !ruby/object:Gem::Version
94
- version: '4.17'
108
+ version: '5.60'
95
109
  name: sequel
96
110
  prerelease: false
97
111
  type: :runtime
@@ -99,13 +113,13 @@ dependencies:
99
113
  requirements:
100
114
  - - "~>"
101
115
  - !ruby/object:Gem::Version
102
- version: '4.17'
116
+ version: '5.60'
103
117
  - !ruby/object:Gem::Dependency
104
118
  requirement: !ruby/object:Gem::Requirement
105
119
  requirements:
106
120
  - - "~>"
107
121
  - !ruby/object:Gem::Version
108
- version: 0.2.4
122
+ version: 0.2.7
109
123
  name: gooddata-dss-jdbc
110
124
  prerelease: false
111
125
  type: :runtime
@@ -113,7 +127,7 @@ dependencies:
113
127
  requirements:
114
128
  - - "~>"
115
129
  - !ruby/object:Gem::Version
116
- version: 0.2.4
130
+ version: 0.2.7
117
131
  - !ruby/object:Gem::Dependency
118
132
  requirement: !ruby/object:Gem::Requirement
119
133
  requirements:
@@ -136,6 +150,7 @@ extensions: []
136
150
  extra_rdoc_files: []
137
151
  files:
138
152
  - ".coveralls.yml"
153
+ - ".github/workflows/build.yml"
139
154
  - ".gitignore"
140
155
  - ".rspec"
141
156
  - ".travis.yml"
@@ -143,19 +158,11 @@ files:
143
158
  - LICENSE.txt
144
159
  - README.md
145
160
  - Rakefile
146
- - env_setup-example.sh
147
161
  - gooddata_datawarehouse.gemspec
148
162
  - lib/gooddata_datawarehouse.rb
149
163
  - lib/gooddata_datawarehouse/datawarehouse.rb
150
164
  - lib/gooddata_datawarehouse/sql_generator.rb
151
165
  - lib/gooddata_datawarehouse/version.rb
152
- - new-version.sh
153
- - spec/data/bike.csv
154
- - spec/data/bike2.csv
155
- - spec/data/emptyheader-bike.csv
156
- - spec/data/wrong-bike.csv
157
- - spec/datawarehouse_spec.rb
158
- - spec/spec_helper.rb
159
166
  homepage: ''
160
167
  licenses:
161
168
  - MIT
@@ -175,15 +182,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
182
  - !ruby/object:Gem::Version
176
183
  version: '0'
177
184
  requirements: []
178
- rubyforge_project:
179
- rubygems_version: 2.6.13
185
+ rubygems_version: 3.3.25
180
186
  signing_key:
181
187
  specification_version: 4
182
188
  summary: Convenient work with GoodData's Datawarehouse (ADS)
183
- test_files:
184
- - spec/data/bike.csv
185
- - spec/data/bike2.csv
186
- - spec/data/emptyheader-bike.csv
187
- - spec/data/wrong-bike.csv
188
- - spec/datawarehouse_spec.rb
189
- - spec/spec_helper.rb
189
+ test_files: []
data/env_setup-example.sh DELETED
@@ -1,5 +0,0 @@
1
- #!/bin/sh
2
-
3
- export USERNAME=""
4
- export PASSWORD=""
5
- export INSTANCE_ID=""
data/new-version.sh DELETED
@@ -1,23 +0,0 @@
1
- #!/bin/sh
2
-
3
- # get the new version
4
- VERSION=`bundle exec ruby <<-EORUBY
5
-
6
- require 'gooddata_datawarehouse'
7
- puts GoodData::Datawarehouse::VERSION
8
-
9
- EORUBY`
10
-
11
- # create tag and push it
12
- TAG="v$VERSION"
13
- git tag $TAG
14
- git push origin $TAG
15
-
16
- # build and push the gem
17
- gem build gooddata_datawarehouse.gemspec
18
- gem push "gooddata_datawarehouse-$VERSION.gem"
19
-
20
- # update the gem after a few secs
21
- echo "Sleeping.."
22
- sleep 30
23
- gem update gooddata_datawarehouse
data/spec/data/bike.csv DELETED
@@ -1,5 +0,0 @@
1
- wheel_size,manufacturer
2
- "29","Specialized"
3
- "27.5","Scott"
4
- "29","Scott"
5
- "989","989"
data/spec/data/bike2.csv DELETED
@@ -1,4 +0,0 @@
1
- wheel_size,manufacturer
2
- "29","Ibis"
3
- "27.5","Seven"
4
- "29","Moots"
@@ -1,4 +0,0 @@
1
- "","manufacturer",""
2
- "29","Ibis","1"
3
- "27.5","Seven","2"
4
- "29","Moots","3"
@@ -1,6 +0,0 @@
1
- wheel_size,manufacturer
2
- "29","Specialized"
3
- "27.5","Scott"
4
- "29","Scott"
5
- "989","989"
6
- "26","Something","Too much cols"
@@ -1,406 +0,0 @@
1
- require 'tempfile'
2
- require 'gooddata_datawarehouse/datawarehouse'
3
-
4
- CSV_PATH = 'spec/data/bike.csv'
5
- CSV_PATH2 = 'spec/data/bike2.csv'
6
- WRONG_CSV_PATH = 'spec/data/wrong-bike.csv'
7
- EMPTY_HEADER_CSV_PATH = 'spec/data/emptyheader-bike.csv'
8
- CSV_REGEXP = 'spec/data/bike*.csv'
9
-
10
- class Helper
11
- def self.create_default_connection
12
- GoodData::Datawarehouse.new(ENV['USERNAME'], ENV['PASSWORD'], ENV['INSTANCE_ID'])
13
- end
14
- def self.line_count(f)
15
- i = 0
16
- CSV.foreach(f, :headers => true) {|_| i += 1}
17
- i
18
- end
19
- end
20
-
21
- describe GoodData::Datawarehouse do
22
- describe "dwh instance creation" do
23
- it "creates an instance with custom jdbc url" do
24
- dwh = GoodData::Datawarehouse.new(ENV['USERNAME'], ENV['PASSWORD'], nil, :jdbc_url => "jdbc:dss://secure.gooddata.com/gdc/dss/instances/#{ENV['INSTANCE_ID']}")
25
- expect(dwh.table_exists?('hahahaha')).to eq false
26
- end
27
- end
28
- describe 'Table operations' do
29
- before(:each) do
30
- @dwh = Helper::create_default_connection
31
- @random = rand(10000000).to_s
32
- @random_table_name = "temp_#{@random}"
33
- @created_tables = nil
34
- end
35
-
36
- after(:each) do
37
- @created_tables ||= [@random_table_name]
38
- @created_tables.each{|t| @dwh.drop_table(t) if t} if @created_tables
39
- end
40
-
41
- describe '#create_table' do
42
- it 'creates a table with default type' do
43
- cols = ['col1', 'col2', 'col3']
44
- @dwh.create_table(@random_table_name, cols)
45
-
46
- # table exists
47
- expect(@dwh.table_exists?(@random_table_name)).to eq true
48
-
49
- # cols are the same
50
- expect(Set.new(@dwh.get_columns(@random_table_name))).to eq Set.new(cols.map {|c| {:column_name => c, :data_type => GoodData::SQLGenerator::DEFAULT_TYPE}})
51
- end
52
-
53
- it "doesn't create a table when it already exists" do
54
- cols = ['col1', 'col2', 'col3']
55
- cols2 = ['col1', 'col2']
56
- @dwh.create_table(@random_table_name, cols)
57
-
58
- expect(@dwh.table_exists?(@random_table_name)).to eq true
59
-
60
- # try to create a table with di
61
- @dwh.create_table(@random_table_name, cols2, skip_if_exists: true)
62
-
63
- # table still exists
64
- expect(@dwh.table_exists?(@random_table_name)).to eq true
65
- # cols are the same
66
- expect(Set.new(@dwh.get_columns(@random_table_name))).to eq Set.new(cols.map {|c| {:column_name => c, :data_type => GoodData::SQLGenerator::DEFAULT_TYPE}})
67
- end
68
-
69
- it 'creates a table with given types' do
70
- cols = [
71
- {
72
- column_name: 'col1',
73
- data_type: 'varchar(88)'
74
- }, {
75
- column_name: 'col2',
76
- data_type: 'int'
77
- }, {
78
- column_name: 'col3',
79
- data_type: 'boolean'
80
- }
81
- ]
82
- @dwh.create_table(@random_table_name, cols)
83
-
84
- # table exists
85
- expect(@dwh.table_exists?(@random_table_name)).to eq true
86
-
87
- # cols are the same
88
- expect(Set.new(@dwh.get_columns(@random_table_name))).to eq Set.new(cols)
89
- end
90
- end
91
-
92
- describe '#drop_table' do
93
- it 'drops a table' do
94
- cols = ['col1', 'col2', 'col3']
95
-
96
- @dwh.create_table(@random_table_name, cols)
97
- expect(@dwh.table_exists?(@random_table_name)).to eq true
98
-
99
- # it shouldn't exist after being dropped
100
- @dwh.drop_table(@random_table_name)
101
- expect(@dwh.table_exists?(@random_table_name)).to eq false
102
-
103
- @random_table_name = nil
104
- end
105
- end
106
-
107
- def check_cols
108
- # cols are the same as in the csv
109
- expected_cols = File.open(CSV_PATH, &:gets).strip.split(',')
110
- expect(Set.new(@dwh.get_columns(@random_table_name))).to eq Set.new(expected_cols.map {|c| {:column_name => c, :data_type => GoodData::SQLGenerator::DEFAULT_TYPE}})
111
- end
112
-
113
- def check_table_exists
114
- # table exists
115
- expect(@dwh.table_exists?(@random_table_name)).to eq true
116
- end
117
-
118
- def check_row_count(files=[CSV_PATH, CSV_PATH2])
119
- expected_count = files.map {|f| Helper.line_count(f)}.reduce(:+)
120
- # there are lines from both of the csvs
121
- expect(@dwh.table_row_count(@random_table_name)).to eq expected_count
122
- end
123
-
124
- describe '#rename_table' do
125
- it 'renames a table' do
126
- cols = ['col1', 'col2', 'col3']
127
-
128
- @dwh.create_table(@random_table_name, cols)
129
- expect(@dwh.table_exists?(@random_table_name)).to eq true
130
-
131
- # the renamed table should exist, not the old name
132
- changed_name = "#{@random_table_name}_something"
133
- @dwh.rename_table(@random_table_name, changed_name)
134
- expect(@dwh.table_exists?(@random_table_name)).to eq false
135
- expect(@dwh.table_exists?(changed_name)).to eq true
136
-
137
- @created_tables = [changed_name]
138
- end
139
- end
140
-
141
- describe '#csv_to_new_table' do
142
- it 'creates a new table from csv' do
143
- @dwh.csv_to_new_table(@random_table_name, CSV_PATH)
144
-
145
- # table exists
146
- expect(@dwh.table_exists?(@random_table_name)).to eq true
147
-
148
- # cols are the same as in the csv
149
- check_cols
150
- end
151
-
152
-
153
- it "loads all files in a directory, in paralel" do
154
- # make a tempdir and copy the csvs there
155
- Dir.mktmpdir('foo') do |dir|
156
- FileUtils.cp(CSV_PATH, dir)
157
- FileUtils.cp(CSV_PATH2, dir)
158
-
159
- @dwh.csv_to_new_table(@random_table_name, dir, :paralel_copy_thread_count => 2)
160
- end
161
-
162
- check_table_exists
163
- check_cols
164
- check_row_count
165
- end
166
-
167
- it "loads all files given in a list" do
168
- @dwh.csv_to_new_table(@random_table_name, [CSV_PATH, CSV_PATH2])
169
-
170
- check_table_exists
171
- check_cols
172
- check_row_count
173
- end
174
-
175
- it "loads all files given by a regexp" do
176
- @dwh.csv_to_new_table(@random_table_name, CSV_REGEXP)
177
-
178
- check_table_exists
179
- check_cols
180
- check_row_count
181
- end
182
-
183
- it 'writes exceptions and rejections to files at given path, passed strings' do
184
- rej = Tempfile.new('rejections.csv')
185
- exc = Tempfile.new('exceptions.csv')
186
-
187
- @dwh.csv_to_new_table(@random_table_name, CSV_PATH, :exceptions_file => exc.path, :rejections_file => rej.path)
188
-
189
- expect(File.size(rej)).to eq 0
190
- expect(File.size(exc)).to eq 0
191
- end
192
-
193
- it 'overwrites the rejections and exceptions' do
194
- rej = Tempfile.new('rejections.csv')
195
- exc = Tempfile.new('exceptions.csv')
196
-
197
- @dwh.csv_to_new_table(@random_table_name, WRONG_CSV_PATH, :exceptions_file => exc.path, :rejections_file => rej.path, :ignore_parse_errors => true)
198
-
199
- rej_size = File.size(rej)
200
- exc_size = File.size(exc)
201
-
202
- expect(rej_size).to be > 0
203
- expect(exc_size).to be > 0
204
-
205
- # load it again and see if it was overwritten - has the same size
206
- @dwh.load_data_from_csv(@random_table_name, WRONG_CSV_PATH, :exceptions_file => exc.path, :rejections_file => rej.path, :ignore_parse_errors => true)
207
-
208
- expect(File.size(rej)).to eq rej_size
209
- expect(File.size(exc)).to be exc_size
210
- end
211
-
212
- it 'writes exceptions and rejections to files at given path, passed files' do
213
- rej = Tempfile.new('rejections.csv')
214
- exc = Tempfile.new('exceptions.csv')
215
-
216
- @dwh.csv_to_new_table(@random_table_name, CSV_PATH, :exceptions_file => exc, :rejections_file => rej)
217
-
218
- expect(File.size(rej)).to eq 0
219
- expect(File.size(exc)).to eq 0
220
- end
221
-
222
- it "writes exceptions and rejections to files at given absolute path, when it's wrong there's something" do
223
- rej = Tempfile.new('rejections.csv')
224
- exc = Tempfile.new('exceptions.csv')
225
-
226
- @dwh.csv_to_new_table(@random_table_name, WRONG_CSV_PATH, :exceptions_file => exc.path, :rejections_file => rej.path, :ignore_parse_errors => true)
227
-
228
- expect(File.size(rej)).to be > 0
229
- expect(File.size(exc)).to be > 0
230
- end
231
-
232
- it "writes exceptions and rejections to files at given relative path, when it's wrong there's something" do
233
- rej = Tempfile.new('rejections.csv')
234
- exc = Tempfile.new('exceptions.csv')
235
-
236
- if File.dirname(rej) != File.dirname(exc)
237
- raise "two directories for tempfiles!"
238
- end
239
-
240
- csv_path = File.expand_path(WRONG_CSV_PATH)
241
-
242
- Dir.chdir(File.dirname(rej)) do
243
- @dwh.csv_to_new_table(@random_table_name, csv_path, :exceptions_file => File.basename(exc), :rejections_file => File.basename(rej), :ignore_parse_errors => true)
244
- end
245
-
246
-
247
- expect(File.size(rej)).to be > 0
248
- expect(File.size(exc)).to be > 0
249
- end
250
-
251
- it "loads fine when ignoring errors and not passing files" do
252
- @dwh.csv_to_new_table(@random_table_name, CSV_PATH, :ignore_parse_errors => true)
253
-
254
- # table exists
255
- expect(@dwh.table_exists?(@random_table_name)).to eq true
256
-
257
- # cols are the same as in the csv
258
- expected_cols = File.open(CSV_PATH, &:gets).strip.split(',')
259
- expect(Set.new(@dwh.get_columns(@random_table_name))).to eq Set.new(expected_cols.map {|c| {:column_name => c, :data_type => GoodData::SQLGenerator::DEFAULT_TYPE}})
260
- end
261
-
262
- it "works with non-existing rejection/exception files" do
263
- t = Tempfile.new('haha')
264
- d = File.dirname(t)
265
-
266
- rej = File.join(d, @random_table_name + '_rej')
267
- exc = File.join(d, @random_table_name + '_exc')
268
-
269
- expect(File.exists?(rej)).to be false
270
- expect(File.exists?(exc)).to be false
271
-
272
- @dwh.csv_to_new_table(@random_table_name, WRONG_CSV_PATH, :exceptions_file => exc, :rejections_file => rej, :ignore_parse_errors => true)
273
-
274
- expect(File.size(rej)).to be > 0
275
- expect(File.size(exc)).to be > 0
276
- end
277
-
278
- it "fails if one of the files is wrong" do
279
- expect{@dwh.csv_to_new_table(@random_table_name, [CSV_PATH, WRONG_CSV_PATH])}.to raise_error(ArgumentError)
280
- end
281
-
282
- it "creates exceptions / rejections for each file when wanted" do
283
- rej = Tempfile.new('rejections.csv')
284
- exc = Tempfile.new('exceptions.csv')
285
-
286
- @dwh.csv_to_new_table(@random_table_name, [CSV_PATH, WRONG_CSV_PATH], :exceptions_file => exc.path, :rejections_file => rej.path, :ignore_parse_errors => true)
287
-
288
- expect(File.size("#{rej.path}-#{File.basename(WRONG_CSV_PATH)}")).to be > 0
289
- expect(File.size("#{exc.path}-#{File.basename(WRONG_CSV_PATH)}")).to be > 0
290
- end
291
- it "creates empty1, etc. columns for empty header columns" do
292
- @dwh.csv_to_new_table(@random_table_name, EMPTY_HEADER_CSV_PATH)
293
- # it should have cols empty1,2
294
- expect(@dwh.get_columns(@random_table_name).map {|c| c[:column_name]}).to include('empty1', 'empty2')
295
- end
296
- end
297
-
298
- describe '#export_table' do
299
- it 'exports a created table' do
300
- @dwh.csv_to_new_table(@random_table_name, CSV_PATH)
301
-
302
- # table exists
303
- expect(@dwh.table_exists?(@random_table_name)).to eq true
304
-
305
- # export it
306
- f = Tempfile.new('bike.csv')
307
- @dwh.export_table(@random_table_name, f)
308
-
309
- # should be the same except for order of the lines
310
- imported = Set.new(CSV.read(CSV_PATH))
311
- exported = Set.new(CSV.read(f))
312
-
313
- expect(exported).to eq imported
314
- end
315
- end
316
-
317
- describe '#load_data_from_csv' do
318
- it 'loads data from csv to existing table' do
319
- # create the table
320
- @dwh.create_table_from_csv_header(@random_table_name, CSV_PATH)
321
- expect(@dwh.table_exists?(@random_table_name)).to eq true
322
-
323
- expected_cols = File.open(CSV_PATH, &:gets).strip.split(',')
324
- expect(Set.new(@dwh.get_columns(@random_table_name))).to eq Set.new(expected_cols.map {|c| {:column_name => c, :data_type => GoodData::SQLGenerator::DEFAULT_TYPE}})
325
-
326
- # load the data there
327
- @dwh.load_data_from_csv(@random_table_name, CSV_PATH)
328
-
329
- # export it
330
- f = Tempfile.new('bike.csv')
331
- @dwh.export_table(@random_table_name, f)
332
-
333
- # should be the same except for order of the lines
334
- imported = Set.new(CSV.read(CSV_PATH))
335
- exported = Set.new(CSV.read(f))
336
-
337
- expect(exported).to eq imported
338
- end
339
-
340
- it "can load multiple files" do
341
- # create the table
342
- @dwh.create_table_from_csv_header(@random_table_name, CSV_PATH)
343
- check_table_exists
344
- check_cols
345
-
346
- # load the data there
347
- @dwh.load_data_from_csv(@random_table_name, [CSV_PATH, CSV_PATH2])
348
-
349
- check_row_count
350
- end
351
-
352
- it 'fails for a wrong csv' do
353
- # create the table
354
- @dwh.create_table_from_csv_header(@random_table_name, WRONG_CSV_PATH)
355
- expect(@dwh.table_exists?(@random_table_name)).to eq true
356
-
357
- # load the data there - expect fail
358
- expect{@dwh.load_data_from_csv(@random_table_name, WRONG_CSV_PATH)}.to raise_error(ArgumentError)
359
- end
360
-
361
- it 'truncates the data that is already there' do
362
- @dwh.create_table_from_csv_header(@random_table_name, CSV_PATH)
363
- check_table_exists
364
- check_cols
365
-
366
- # load the data there
367
- @dwh.load_data_from_csv(@random_table_name, CSV_PATH)
368
- check_row_count([CSV_PATH])
369
-
370
- # load the data there again, count should stay
371
- @dwh.load_data_from_csv(@random_table_name, CSV_PATH2)
372
- check_row_count([CSV_PATH2])
373
- end
374
-
375
- it "keeps the data that is there if append option passed" do
376
- @dwh.create_table_from_csv_header(@random_table_name, CSV_PATH)
377
- check_table_exists
378
- check_cols
379
-
380
- # load the data there
381
- @dwh.load_data_from_csv(@random_table_name, CSV_PATH)
382
- check_row_count([CSV_PATH])
383
-
384
- # append the data
385
- @dwh.load_data_from_csv(@random_table_name, CSV_PATH2, :append => true)
386
- check_row_count([CSV_PATH, CSV_PATH2])
387
- end
388
- end
389
-
390
- describe "#truncate_table" do
391
- it "truncates the given table" do
392
- @dwh.csv_to_new_table(@random_table_name, CSV_PATH)
393
- @dwh.truncate_table(@random_table_name)
394
- expect(@dwh.table_row_count(@random_table_name)).to eq 0
395
- end
396
- end
397
-
398
- describe '#get_columns' do
399
- it 'gives you the right list of columns' do
400
- expected_cols = File.open(CSV_PATH, &:gets).strip.split(',')
401
- @dwh.create_table_from_csv_header(@random_table_name, CSV_PATH)
402
- end
403
- # TODO more tests
404
- end
405
- end
406
- end
data/spec/spec_helper.rb DELETED
@@ -1,8 +0,0 @@
1
- require 'coveralls'
2
- Coveralls.wear!
3
-
4
- RSpec.configure do |c|
5
- c.filter_run :focus => true
6
- c.run_all_when_everything_filtered = true
7
- end
8
-