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