gooddata_datawarehouse 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/gooddata_datawarehouse/datawarehouse.rb +7 -3
- data/lib/gooddata_datawarehouse/version.rb +1 -1
- data/spec/datawarehouse_spec.rb +285 -277
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4df42b6be9975a0f86aa383914db372e5ca91361
|
4
|
+
data.tar.gz: e13dd331a4a0c9dd0e817def626b70fa0959d4d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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?
|
19
|
-
fail ArgumentError, "username
|
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
|
data/spec/datawarehouse_spec.rb
CHANGED
@@ -19,380 +19,388 @@ class Helper
|
|
19
19
|
end
|
20
20
|
|
21
21
|
describe GoodData::Datawarehouse do
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
40
|
-
|
46
|
+
# table exists
|
47
|
+
expect(@dwh.table_exists?(@random_table_name)).to eq true
|
41
48
|
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
58
|
+
expect(@dwh.table_exists?(@random_table_name)).to eq true
|
52
59
|
|
53
|
-
|
54
|
-
|
60
|
+
# try to create a table with di
|
61
|
+
@dwh.create_table(@random_table_name, cols2, skip_if_exists: true)
|
55
62
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
63
|
-
|
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
|
-
|
78
|
-
|
96
|
+
@dwh.create_table(@random_table_name, cols)
|
97
|
+
expect(@dwh.table_exists?(@random_table_name)).to eq true
|
79
98
|
|
80
|
-
|
81
|
-
|
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
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
101
|
-
|
102
|
-
|
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
|
-
|
107
|
-
|
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
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
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
|
-
|
118
|
-
|
119
|
-
|
137
|
+
@created_tables = [changed_name]
|
138
|
+
end
|
139
|
+
end
|
120
140
|
|
121
|
-
|
122
|
-
|
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
|
-
|
125
|
-
|
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
|
-
|
131
|
-
|
132
|
-
|
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
|
-
|
139
|
-
|
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
|
-
|
142
|
-
|
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
|
-
|
147
|
-
|
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
|
-
|
170
|
+
check_table_exists
|
171
|
+
check_cols
|
172
|
+
check_row_count
|
153
173
|
end
|
154
174
|
|
155
|
-
|
156
|
-
|
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
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
178
|
+
check_table_exists
|
179
|
+
check_cols
|
180
|
+
check_row_count
|
181
|
+
end
|
167
182
|
|
168
|
-
|
169
|
-
|
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
|
-
|
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
|
-
|
177
|
-
|
178
|
-
|
189
|
+
expect(File.size(rej)).to eq 0
|
190
|
+
expect(File.size(exc)).to eq 0
|
191
|
+
end
|
179
192
|
|
180
|
-
|
193
|
+
it 'overwrites the rejections and exceptions' do
|
194
|
+
rej = Tempfile.new('rejections.csv')
|
195
|
+
exc = Tempfile.new('exceptions.csv')
|
181
196
|
|
182
|
-
|
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
|
-
|
187
|
-
|
188
|
-
exc = Tempfile.new('exceptions.csv')
|
199
|
+
rej_size = File.size(rej)
|
200
|
+
exc_size = File.size(exc)
|
189
201
|
|
190
|
-
|
202
|
+
expect(rej_size).to be > 0
|
203
|
+
expect(exc_size).to be > 0
|
191
204
|
|
192
|
-
|
193
|
-
|
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
|
-
|
196
|
-
|
208
|
+
expect(File.size(rej)).to eq rej_size
|
209
|
+
expect(File.size(exc)).to be exc_size
|
210
|
+
end
|
197
211
|
|
198
|
-
|
199
|
-
|
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
|
-
|
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
|
-
|
206
|
-
|
207
|
-
|
218
|
+
expect(File.size(rej)).to eq 0
|
219
|
+
expect(File.size(exc)).to eq 0
|
220
|
+
end
|
208
221
|
|
209
|
-
|
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
|
-
|
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
|
-
|
216
|
-
|
217
|
-
|
228
|
+
expect(File.size(rej)).to be > 0
|
229
|
+
expect(File.size(exc)).to be > 0
|
230
|
+
end
|
218
231
|
|
219
|
-
|
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
|
-
|
222
|
-
|
223
|
-
|
236
|
+
if File.dirname(rej) != File.dirname(exc)
|
237
|
+
raise "two directories for tempfiles!"
|
238
|
+
end
|
224
239
|
|
225
|
-
|
226
|
-
rej = Tempfile.new('rejections.csv')
|
227
|
-
exc = Tempfile.new('exceptions.csv')
|
240
|
+
csv_path = File.expand_path(WRONG_CSV_PATH)
|
228
241
|
|
229
|
-
|
230
|
-
|
231
|
-
|
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
|
-
|
236
|
-
|
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
|
-
|
241
|
-
|
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
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
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
|
-
|
256
|
-
|
257
|
-
|
262
|
+
it "works with non-existing rejection/exception files" do
|
263
|
+
t = Tempfile.new('haha')
|
264
|
+
d = File.dirname(t)
|
258
265
|
|
259
|
-
|
260
|
-
|
266
|
+
rej = File.join(d, @random_table_name + '_rej')
|
267
|
+
exc = File.join(d, @random_table_name + '_exc')
|
261
268
|
|
262
|
-
|
263
|
-
|
269
|
+
expect(File.exists?(rej)).to be false
|
270
|
+
expect(File.exists?(exc)).to be false
|
264
271
|
|
265
|
-
|
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
|
-
|
268
|
-
|
269
|
-
|
274
|
+
expect(File.size(rej)).to be > 0
|
275
|
+
expect(File.size(exc)).to be > 0
|
276
|
+
end
|
270
277
|
|
271
|
-
|
272
|
-
|
273
|
-
|
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
|
-
|
276
|
-
|
277
|
-
|
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
|
-
|
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
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
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
|
288
296
|
end
|
289
|
-
end
|
290
297
|
|
291
|
-
|
292
|
-
|
293
|
-
|
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
|
-
|
296
|
-
|
302
|
+
# table exists
|
303
|
+
expect(@dwh.table_exists?(@random_table_name)).to eq true
|
297
304
|
|
298
|
-
|
299
|
-
|
300
|
-
|
305
|
+
# export it
|
306
|
+
f = Tempfile.new('bike.csv')
|
307
|
+
@dwh.export_table(@random_table_name, f)
|
301
308
|
|
302
|
-
|
303
|
-
|
304
|
-
|
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
|
-
|
313
|
+
expect(exported).to eq imported
|
314
|
+
end
|
307
315
|
end
|
308
|
-
end
|
309
316
|
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
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
|
-
|
317
|
-
|
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
|
-
|
320
|
-
|
326
|
+
# load the data there
|
327
|
+
@dwh.load_data_from_csv(@random_table_name, CSV_PATH)
|
321
328
|
|
322
|
-
|
323
|
-
|
324
|
-
|
329
|
+
# export it
|
330
|
+
f = Tempfile.new('bike.csv')
|
331
|
+
@dwh.export_table(@random_table_name, f)
|
325
332
|
|
326
|
-
|
327
|
-
|
328
|
-
|
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
|
-
|
331
|
-
|
337
|
+
expect(exported).to eq imported
|
338
|
+
end
|
332
339
|
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
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
|
-
|
340
|
-
|
346
|
+
# load the data there
|
347
|
+
@dwh.load_data_from_csv(@random_table_name, [CSV_PATH, CSV_PATH2])
|
341
348
|
|
342
|
-
|
343
|
-
|
349
|
+
check_row_count
|
350
|
+
end
|
344
351
|
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
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
|
-
|
351
|
-
|
352
|
-
|
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
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
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
|
-
|
360
|
-
|
361
|
-
|
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
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
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
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
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
|
-
|
374
|
-
|
375
|
-
|
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
|
-
|
378
|
-
|
379
|
-
|
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
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
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
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
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.
|
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-
|
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
|