gooddata_datawarehouse 0.0.7 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 453c08405c8e4e9c2fc46b6b2fb1f1df22f2f4ae
4
- data.tar.gz: ce89580d666c0d660a61a72def8f6d7d28d4ab9d
3
+ metadata.gz: 4df42b6be9975a0f86aa383914db372e5ca91361
4
+ data.tar.gz: e13dd331a4a0c9dd0e817def626b70fa0959d4d5
5
5
  SHA512:
6
- metadata.gz: 5d40a9ece4f77255e2d2f750d0082bc5ca0d19bb1d99ae013d8da5331000b1c86022e3dc4c8b70b54cda7da130332a6b3b19ac4eeb280d27573d19bd8cafc1ed
7
- data.tar.gz: 69fc15c0a428e8e32db4b20f07b7fa7ef686342df98e210dc1a4540e6af85569f31cebb00a867d9fe5e15a62f3326c1d3c74db0b4a31fb6d7b4c777fc6755c4a
6
+ metadata.gz: e1bc334616cb41069cbc6cbd9aac87dd7ec48e55b3c9ae25e38cd9941ef60924d523bee6b816cecd78fde0951295571659821fe627f9a4ace273264b275c88f4
7
+ data.tar.gz: f8dffb2a551d20e4a577de3fa7780b1f69898a33889b3128e54623b16a9aabed5964ab04a76c3ab9a264933e6984f837b22a2b205af78faf8ac967197419d22a
data/README.md CHANGED
@@ -47,6 +47,8 @@ dwh = GoodData::Datawarehouse.new('you@gooddata.com', 'yourpass', 'your ADS inst
47
47
  # instance id is the identifier of your datawarehouse (ADS).
48
48
  # E.g. for datawarehouse https://secure.gooddata.com/gdc/datawarehouse/instances/d4979ac54df8afb7b5192b0086de6270
49
49
  # the instance id is d4979ac54df8afb7b5192b0086de6270
50
+ # for custom jdbc url do:
51
+ # dwh = GoodData::Datawarehouse.new('you@gooddata.com', 'yourpass', nil, 'jdbc:dss://whatever.com/something')
50
52
 
51
53
  # import a csv
52
54
  dwh.csv_to_new_table('my_table', 'path/to/my.csv')
@@ -14,9 +14,13 @@ module GoodData
14
14
  @logger = Logger.new(STDOUT)
15
15
  @username = username
16
16
  @password = password
17
- @jdbc_url = "jdbc:dss://secure.gooddata.com/gdc/dss/instances/#{instance_id}"
18
- if @username.nil? || @password.nil? || instance_id.nil?
19
- fail ArgumentError, "username, password and/or instance_id are nil. All of them are mandatory."
17
+ @jdbc_url = opts[:jdbc_url] || "jdbc:dss://secure.gooddata.com/gdc/dss/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
+
22
+ if instance_id.nil? && opts[:jdbc_url].nil?
23
+ fail ArgumentError, "you must either provide instance_id or jdbc_url option."
20
24
  end
21
25
 
22
26
  Jdbc::DSS.load_driver
@@ -1,5 +1,5 @@
1
1
  module GoodData
2
2
  class Datawarehouse
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
@@ -19,380 +19,388 @@ class Helper
19
19
  end
20
20
 
21
21
  describe GoodData::Datawarehouse do
22
- before(:each) do
23
- @dwh = Helper::create_default_connection
24
- @random = rand(10000000).to_s
25
- @random_table_name = "temp_#{@random}"
26
- @created_tables = nil
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
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
28
35
 
29
- after(:each) do
30
- @created_tables ||= [@random_table_name]
31
- @created_tables.each{|t| @dwh.drop_table(t) if t} if @created_tables
32
- end
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
33
40
 
34
- describe '#create_table' do
35
- it 'creates a table with default type' do
36
- cols = ['col1', 'col2', 'col3']
37
- @dwh.create_table(@random_table_name, cols)
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)
38
45
 
39
- # table exists
40
- expect(@dwh.table_exists?(@random_table_name)).to eq true
46
+ # table exists
47
+ expect(@dwh.table_exists?(@random_table_name)).to eq true
41
48
 
42
- # cols are the same
43
- 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}})
44
- end
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
45
52
 
46
- it "doesn't create a table when it already exists" do
47
- cols = ['col1', 'col2', 'col3']
48
- cols2 = ['col1', 'col2']
49
- @dwh.create_table(@random_table_name, cols)
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)
50
57
 
51
- expect(@dwh.table_exists?(@random_table_name)).to eq true
58
+ expect(@dwh.table_exists?(@random_table_name)).to eq true
52
59
 
53
- # try to create a table with di
54
- @dwh.create_table(@random_table_name, cols2, skip_if_exists: true)
60
+ # try to create a table with di
61
+ @dwh.create_table(@random_table_name, cols2, skip_if_exists: true)
55
62
 
56
- # table still exists
57
- expect(@dwh.table_exists?(@random_table_name)).to eq true
58
- # cols are the same
59
- 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}})
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
60
90
  end
61
91
 
62
- it 'creates a table with given types' do
63
- cols = [
64
- {
65
- column_name: 'col1',
66
- data_type: 'varchar(88)'
67
- }, {
68
- column_name: 'col2',
69
- data_type: 'int'
70
- }, {
71
- column_name: 'col3',
72
- data_type: 'boolean'
73
- }
74
- ]
75
- @dwh.create_table(@random_table_name, cols)
92
+ describe '#drop_table' do
93
+ it 'drops a table' do
94
+ cols = ['col1', 'col2', 'col3']
76
95
 
77
- # table exists
78
- expect(@dwh.table_exists?(@random_table_name)).to eq true
96
+ @dwh.create_table(@random_table_name, cols)
97
+ expect(@dwh.table_exists?(@random_table_name)).to eq true
79
98
 
80
- # cols are the same
81
- expect(Set.new(@dwh.get_columns(@random_table_name))).to eq Set.new(cols)
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
82
105
  end
83
- end
84
106
 
85
- describe '#drop_table' do
86
- it 'drops a table' do
87
- cols = ['col1', 'col2', 'col3']
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
88
112
 
89
- @dwh.create_table(@random_table_name, cols)
113
+ def check_table_exists
114
+ # table exists
90
115
  expect(@dwh.table_exists?(@random_table_name)).to eq true
116
+ end
91
117
 
92
- # it shouldn't exist after being dropped
93
- @dwh.drop_table(@random_table_name)
94
- expect(@dwh.table_exists?(@random_table_name)).to eq false
95
-
96
- @random_table_name = nil
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
97
122
  end
98
- end
99
123
 
100
- def check_cols
101
- # cols are the same as in the csv
102
- expected_cols = File.open(CSV_PATH, &:gets).strip.split(',')
103
- 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}})
104
- end
124
+ describe '#rename_table' do
125
+ it 'renames a table' do
126
+ cols = ['col1', 'col2', 'col3']
105
127
 
106
- def check_table_exists
107
- # table exists
108
- expect(@dwh.table_exists?(@random_table_name)).to eq true
109
- end
128
+ @dwh.create_table(@random_table_name, cols)
129
+ expect(@dwh.table_exists?(@random_table_name)).to eq true
110
130
 
111
- def check_row_count(files=[CSV_PATH, CSV_PATH2])
112
- expected_count = files.map {|f| Helper.line_count(f)}.reduce(:+)
113
- # there are lines from both of the csvs
114
- expect(@dwh.table_row_count(@random_table_name)).to eq expected_count
115
- end
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
116
136
 
117
- describe '#rename_table' do
118
- it 'renames a table' do
119
- cols = ['col1', 'col2', 'col3']
137
+ @created_tables = [changed_name]
138
+ end
139
+ end
120
140
 
121
- @dwh.create_table(@random_table_name, cols)
122
- expect(@dwh.table_exists?(@random_table_name)).to eq true
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)
123
144
 
124
- # the renamed table should exist, not the old name
125
- changed_name = "#{@random_table_name}_something"
126
- @dwh.rename_table(@random_table_name, changed_name)
127
- expect(@dwh.table_exists?(@random_table_name)).to eq false
128
- expect(@dwh.table_exists?(changed_name)).to eq true
145
+ # table exists
146
+ expect(@dwh.table_exists?(@random_table_name)).to eq true
129
147
 
130
- @created_tables = [changed_name]
131
- end
132
- end
148
+ # cols are the same as in the csv
149
+ check_cols
150
+ end
133
151
 
134
- describe '#csv_to_new_table' do
135
- it 'creates a new table from csv' do
136
- @dwh.csv_to_new_table(@random_table_name, CSV_PATH)
137
152
 
138
- # table exists
139
- expect(@dwh.table_exists?(@random_table_name)).to eq true
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)
140
158
 
141
- # cols are the same as in the csv
142
- check_cols
143
- end
159
+ @dwh.csv_to_new_table(@random_table_name, dir, :paralel_copy_thread_count => 2)
160
+ end
144
161
 
162
+ check_table_exists
163
+ check_cols
164
+ check_row_count
165
+ end
145
166
 
146
- it "loads all files in a directory, in paralel" do
147
- # make a tempdir and copy the csvs there
148
- Dir.mktmpdir('foo') do |dir|
149
- FileUtils.cp(CSV_PATH, dir)
150
- FileUtils.cp(CSV_PATH2, dir)
167
+ it "loads all files given in a list" do
168
+ @dwh.csv_to_new_table(@random_table_name, [CSV_PATH, CSV_PATH2])
151
169
 
152
- @dwh.csv_to_new_table(@random_table_name, dir, :paralel_copy_thread_count => 2)
170
+ check_table_exists
171
+ check_cols
172
+ check_row_count
153
173
  end
154
174
 
155
- check_table_exists
156
- check_cols
157
- check_row_count
158
- end
159
-
160
- it "loads all files given in a list" do
161
- @dwh.csv_to_new_table(@random_table_name, [CSV_PATH, CSV_PATH2])
175
+ it "loads all files given by a regexp" do
176
+ @dwh.csv_to_new_table(@random_table_name, CSV_REGEXP)
162
177
 
163
- check_table_exists
164
- check_cols
165
- check_row_count
166
- end
178
+ check_table_exists
179
+ check_cols
180
+ check_row_count
181
+ end
167
182
 
168
- it "loads all files given by a regexp" do
169
- @dwh.csv_to_new_table(@random_table_name, CSV_REGEXP)
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')
170
186
 
171
- check_table_exists
172
- check_cols
173
- check_row_count
174
- end
187
+ @dwh.csv_to_new_table(@random_table_name, CSV_PATH, :exceptions_file => exc.path, :rejections_file => rej.path)
175
188
 
176
- it 'writes exceptions and rejections to files at given path, passed strings' do
177
- rej = Tempfile.new('rejections.csv')
178
- exc = Tempfile.new('exceptions.csv')
189
+ expect(File.size(rej)).to eq 0
190
+ expect(File.size(exc)).to eq 0
191
+ end
179
192
 
180
- @dwh.csv_to_new_table(@random_table_name, CSV_PATH, :exceptions_file => exc.path, :rejections_file => rej.path)
193
+ it 'overwrites the rejections and exceptions' do
194
+ rej = Tempfile.new('rejections.csv')
195
+ exc = Tempfile.new('exceptions.csv')
181
196
 
182
- expect(File.size(rej)).to eq 0
183
- expect(File.size(exc)).to eq 0
184
- end
197
+ @dwh.csv_to_new_table(@random_table_name, WRONG_CSV_PATH, :exceptions_file => exc.path, :rejections_file => rej.path, :ignore_parse_errors => true)
185
198
 
186
- it 'overwrites the rejections and exceptions' do
187
- rej = Tempfile.new('rejections.csv')
188
- exc = Tempfile.new('exceptions.csv')
199
+ rej_size = File.size(rej)
200
+ exc_size = File.size(exc)
189
201
 
190
- @dwh.csv_to_new_table(@random_table_name, WRONG_CSV_PATH, :exceptions_file => exc.path, :rejections_file => rej.path, :ignore_parse_errors => true)
202
+ expect(rej_size).to be > 0
203
+ expect(exc_size).to be > 0
191
204
 
192
- rej_size = File.size(rej)
193
- exc_size = File.size(exc)
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)
194
207
 
195
- expect(rej_size).to be > 0
196
- expect(exc_size).to be > 0
208
+ expect(File.size(rej)).to eq rej_size
209
+ expect(File.size(exc)).to be exc_size
210
+ end
197
211
 
198
- # load it again and see if it was overwritten - has the same size
199
- @dwh.load_data_from_csv(@random_table_name, WRONG_CSV_PATH, :exceptions_file => exc.path, :rejections_file => rej.path, :ignore_parse_errors => true)
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')
200
215
 
201
- expect(File.size(rej)).to eq rej_size
202
- expect(File.size(exc)).to be exc_size
203
- end
216
+ @dwh.csv_to_new_table(@random_table_name, CSV_PATH, :exceptions_file => exc, :rejections_file => rej)
204
217
 
205
- it 'writes exceptions and rejections to files at given path, passed files' do
206
- rej = Tempfile.new('rejections.csv')
207
- exc = Tempfile.new('exceptions.csv')
218
+ expect(File.size(rej)).to eq 0
219
+ expect(File.size(exc)).to eq 0
220
+ end
208
221
 
209
- @dwh.csv_to_new_table(@random_table_name, CSV_PATH, :exceptions_file => exc, :rejections_file => rej)
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')
210
225
 
211
- expect(File.size(rej)).to eq 0
212
- expect(File.size(exc)).to eq 0
213
- end
226
+ @dwh.csv_to_new_table(@random_table_name, WRONG_CSV_PATH, :exceptions_file => exc.path, :rejections_file => rej.path, :ignore_parse_errors => true)
214
227
 
215
- it "writes exceptions and rejections to files at given absolute path, when it's wrong there's something" do
216
- rej = Tempfile.new('rejections.csv')
217
- exc = Tempfile.new('exceptions.csv')
228
+ expect(File.size(rej)).to be > 0
229
+ expect(File.size(exc)).to be > 0
230
+ end
218
231
 
219
- @dwh.csv_to_new_table(@random_table_name, WRONG_CSV_PATH, :exceptions_file => exc.path, :rejections_file => rej.path, :ignore_parse_errors => true)
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')
220
235
 
221
- expect(File.size(rej)).to be > 0
222
- expect(File.size(exc)).to be > 0
223
- end
236
+ if File.dirname(rej) != File.dirname(exc)
237
+ raise "two directories for tempfiles!"
238
+ end
224
239
 
225
- it "writes exceptions and rejections to files at given relative path, when it's wrong there's something" do
226
- rej = Tempfile.new('rejections.csv')
227
- exc = Tempfile.new('exceptions.csv')
240
+ csv_path = File.expand_path(WRONG_CSV_PATH)
228
241
 
229
- if File.dirname(rej) != File.dirname(exc)
230
- raise "two directories for tempfiles!"
231
- end
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
232
245
 
233
- csv_path = File.expand_path(WRONG_CSV_PATH)
234
246
 
235
- Dir.chdir(File.dirname(rej)) do
236
- @dwh.csv_to_new_table(@random_table_name, csv_path, :exceptions_file => File.basename(exc), :rejections_file => File.basename(rej), :ignore_parse_errors => true)
247
+ expect(File.size(rej)).to be > 0
248
+ expect(File.size(exc)).to be > 0
237
249
  end
238
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)
239
253
 
240
- expect(File.size(rej)).to be > 0
241
- expect(File.size(exc)).to be > 0
242
- end
243
-
244
- it "loads fine when ignoring errors and not passing files" do
245
- @dwh.csv_to_new_table(@random_table_name, CSV_PATH, :ignore_parse_errors => true)
246
-
247
- # table exists
248
- expect(@dwh.table_exists?(@random_table_name)).to eq true
254
+ # table exists
255
+ expect(@dwh.table_exists?(@random_table_name)).to eq true
249
256
 
250
- # cols are the same as in the csv
251
- expected_cols = File.open(CSV_PATH, &:gets).strip.split(',')
252
- 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}})
253
- end
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
254
261
 
255
- it "works with non-existing rejection/exception files" do
256
- t = Tempfile.new('haha')
257
- d = File.dirname(t)
262
+ it "works with non-existing rejection/exception files" do
263
+ t = Tempfile.new('haha')
264
+ d = File.dirname(t)
258
265
 
259
- rej = File.join(d, @random_table_name + '_rej')
260
- exc = File.join(d, @random_table_name + '_exc')
266
+ rej = File.join(d, @random_table_name + '_rej')
267
+ exc = File.join(d, @random_table_name + '_exc')
261
268
 
262
- expect(File.exists?(rej)).to be false
263
- expect(File.exists?(exc)).to be false
269
+ expect(File.exists?(rej)).to be false
270
+ expect(File.exists?(exc)).to be false
264
271
 
265
- @dwh.csv_to_new_table(@random_table_name, WRONG_CSV_PATH, :exceptions_file => exc, :rejections_file => rej, :ignore_parse_errors => true)
272
+ @dwh.csv_to_new_table(@random_table_name, WRONG_CSV_PATH, :exceptions_file => exc, :rejections_file => rej, :ignore_parse_errors => true)
266
273
 
267
- expect(File.size(rej)).to be > 0
268
- expect(File.size(exc)).to be > 0
269
- end
274
+ expect(File.size(rej)).to be > 0
275
+ expect(File.size(exc)).to be > 0
276
+ end
270
277
 
271
- it "fails if one of the files is wrong" do
272
- expect{@dwh.csv_to_new_table(@random_table_name, [CSV_PATH, WRONG_CSV_PATH])}.to raise_error(ArgumentError)
273
- end
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
274
281
 
275
- it "creates exceptions / rejections for each file when wanted" do
276
- rej = Tempfile.new('rejections.csv')
277
- exc = Tempfile.new('exceptions.csv')
282
+ it "creates exceptions / rejections for each file when wanted" do
283
+ rej = Tempfile.new('rejections.csv')
284
+ exc = Tempfile.new('exceptions.csv')
278
285
 
279
- @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)
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)
280
287
 
281
- expect(File.size("#{rej.path}-#{File.basename(WRONG_CSV_PATH)}")).to be > 0
282
- expect(File.size("#{exc.path}-#{File.basename(WRONG_CSV_PATH)}")).to be > 0
283
- end
284
- it "creates empty1, etc. columns for empty header columns" do
285
- @dwh.csv_to_new_table(@random_table_name, EMPTY_HEADER_CSV_PATH)
286
- # it should have cols empty1,2
287
- expect(@dwh.get_columns(@random_table_name).map {|c| c[:column_name]}).to include('empty1', 'empty2')
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
288
296
  end
289
- end
290
297
 
291
- describe '#export_table' do
292
- it 'exports a created table' do
293
- @dwh.csv_to_new_table(@random_table_name, CSV_PATH)
298
+ describe '#export_table' do
299
+ it 'exports a created table' do
300
+ @dwh.csv_to_new_table(@random_table_name, CSV_PATH)
294
301
 
295
- # table exists
296
- expect(@dwh.table_exists?(@random_table_name)).to eq true
302
+ # table exists
303
+ expect(@dwh.table_exists?(@random_table_name)).to eq true
297
304
 
298
- # export it
299
- f = Tempfile.new('bike.csv')
300
- @dwh.export_table(@random_table_name, f)
305
+ # export it
306
+ f = Tempfile.new('bike.csv')
307
+ @dwh.export_table(@random_table_name, f)
301
308
 
302
- # should be the same except for order of the lines
303
- imported = Set.new(CSV.read(CSV_PATH))
304
- exported = Set.new(CSV.read(f))
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))
305
312
 
306
- expect(exported).to eq imported
313
+ expect(exported).to eq imported
314
+ end
307
315
  end
308
- end
309
316
 
310
- describe '#load_data_from_csv' do
311
- it 'loads data from csv to existing table' do
312
- # create the table
313
- @dwh.create_table_from_csv_header(@random_table_name, CSV_PATH)
314
- expect(@dwh.table_exists?(@random_table_name)).to eq true
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
315
322
 
316
- expected_cols = File.open(CSV_PATH, &:gets).strip.split(',')
317
- 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}})
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}})
318
325
 
319
- # load the data there
320
- @dwh.load_data_from_csv(@random_table_name, CSV_PATH)
326
+ # load the data there
327
+ @dwh.load_data_from_csv(@random_table_name, CSV_PATH)
321
328
 
322
- # export it
323
- f = Tempfile.new('bike.csv')
324
- @dwh.export_table(@random_table_name, f)
329
+ # export it
330
+ f = Tempfile.new('bike.csv')
331
+ @dwh.export_table(@random_table_name, f)
325
332
 
326
- # should be the same except for order of the lines
327
- imported = Set.new(CSV.read(CSV_PATH))
328
- exported = Set.new(CSV.read(f))
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))
329
336
 
330
- expect(exported).to eq imported
331
- end
337
+ expect(exported).to eq imported
338
+ end
332
339
 
333
- it "can load multiple files" do
334
- # create the table
335
- @dwh.create_table_from_csv_header(@random_table_name, CSV_PATH)
336
- check_table_exists
337
- check_cols
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
338
345
 
339
- # load the data there
340
- @dwh.load_data_from_csv(@random_table_name, [CSV_PATH, CSV_PATH2])
346
+ # load the data there
347
+ @dwh.load_data_from_csv(@random_table_name, [CSV_PATH, CSV_PATH2])
341
348
 
342
- check_row_count
343
- end
349
+ check_row_count
350
+ end
344
351
 
345
- it 'fails for a wrong csv' do
346
- # create the table
347
- @dwh.create_table_from_csv_header(@random_table_name, WRONG_CSV_PATH)
348
- expect(@dwh.table_exists?(@random_table_name)).to eq true
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
349
356
 
350
- # load the data there - expect fail
351
- expect{@dwh.load_data_from_csv(@random_table_name, WRONG_CSV_PATH)}.to raise_error(ArgumentError)
352
- end
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
353
360
 
354
- it 'truncates the data that is already there' do
355
- @dwh.create_table_from_csv_header(@random_table_name, CSV_PATH)
356
- check_table_exists
357
- check_cols
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
358
365
 
359
- # load the data there
360
- @dwh.load_data_from_csv(@random_table_name, CSV_PATH)
361
- check_row_count([CSV_PATH])
366
+ # load the data there
367
+ @dwh.load_data_from_csv(@random_table_name, CSV_PATH)
368
+ check_row_count([CSV_PATH])
362
369
 
363
- # load the data there again, count should stay
364
- @dwh.load_data_from_csv(@random_table_name, CSV_PATH2)
365
- check_row_count([CSV_PATH2])
366
- end
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
367
374
 
368
- it "keeps the data that is there if append option passed" do
369
- @dwh.create_table_from_csv_header(@random_table_name, CSV_PATH)
370
- check_table_exists
371
- check_cols
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
372
379
 
373
- # load the data there
374
- @dwh.load_data_from_csv(@random_table_name, CSV_PATH)
375
- check_row_count([CSV_PATH])
380
+ # load the data there
381
+ @dwh.load_data_from_csv(@random_table_name, CSV_PATH)
382
+ check_row_count([CSV_PATH])
376
383
 
377
- # append the data
378
- @dwh.load_data_from_csv(@random_table_name, CSV_PATH2, :append => true)
379
- check_row_count([CSV_PATH, CSV_PATH2])
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
380
388
  end
381
- end
382
389
 
383
- describe "#truncate_table" do
384
- it "truncates the given table" do
385
- @dwh.csv_to_new_table(@random_table_name, CSV_PATH)
386
- @dwh.truncate_table(@random_table_name)
387
- expect(@dwh.table_row_count(@random_table_name)).to eq 0
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
388
396
  end
389
- end
390
397
 
391
- describe '#get_columns' do
392
- it 'gives you the right list of columns' do
393
- expected_cols = File.open(CSV_PATH, &:gets).strip.split(',')
394
- @dwh.create_table_from_csv_header(@random_table_name, CSV_PATH)
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
395
404
  end
396
- # TODO more tests
397
405
  end
398
406
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gooddata_datawarehouse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petr Cvengros
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-09 00:00:00.000000000 Z
11
+ date: 2015-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement