beetle_etl 1.0.1 → 2.0.0
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 +4 -4
- data/.byebug_history +8 -0
- data/.travis.yml +6 -1
- data/README.md +31 -9
- data/beetle_etl.gemspec +1 -1
- data/lib/beetle_etl.rb +7 -49
- data/lib/beetle_etl/configuration.rb +39 -0
- data/lib/beetle_etl/dsl/dsl.rb +6 -2
- data/lib/beetle_etl/dsl/transformation.rb +2 -2
- data/lib/beetle_etl/dsl/transformation_loader.rb +4 -3
- data/lib/beetle_etl/import.rb +15 -11
- data/lib/beetle_etl/naming.rb +10 -20
- data/lib/beetle_etl/reporter.rb +3 -2
- data/lib/beetle_etl/step_runner/async_step_runner.rb +6 -4
- data/lib/beetle_etl/steps/create_stage.rb +2 -2
- data/lib/beetle_etl/steps/load.rb +2 -2
- data/lib/beetle_etl/steps/map_relations.rb +2 -2
- data/lib/beetle_etl/steps/step.rb +23 -4
- data/lib/beetle_etl/steps/transform.rb +2 -2
- data/lib/beetle_etl/testing.rb +10 -5
- data/lib/beetle_etl/testing/test_wrapper.rb +4 -4
- data/lib/beetle_etl/version.rb +1 -1
- data/spec/beetle_etl_spec.rb +6 -38
- data/spec/configuration_spec.rb +66 -0
- data/spec/dsl/dsl_spec.rb +9 -3
- data/spec/dsl/transformation_loader_spec.rb +9 -8
- data/spec/dsl/transformation_spec.rb +9 -7
- data/spec/feature/feature_spec.rb +8 -8
- data/spec/reporter_spec.rb +5 -2
- data/spec/spec_helper.rb +4 -5
- data/spec/steps/assign_ids_spec.rb +7 -7
- data/spec/steps/create_stage_spec.rb +14 -12
- data/spec/steps/load_spec.rb +9 -7
- data/spec/steps/map_relations_spec.rb +14 -8
- data/spec/steps/step_spec.rb +5 -3
- data/spec/steps/table_diff_spec.rb +7 -6
- data/spec/steps/transform_spec.rb +8 -4
- data/spec/testing_spec.rb +1 -1
- metadata +9 -5
data/spec/reporter_spec.rb
CHANGED
@@ -38,7 +38,10 @@ module BeetleETL
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "loggs a summary of all step times by table name" do
|
41
|
-
|
41
|
+
config = Configuration.new.tap do |c|
|
42
|
+
c.logger = double(:logger)
|
43
|
+
end
|
44
|
+
expect(config.logger).to receive(:info).with <<-LOG.unindent
|
42
45
|
|
43
46
|
|
44
47
|
organisations
|
@@ -58,7 +61,7 @@ module BeetleETL
|
|
58
61
|
01:31:39
|
59
62
|
LOG
|
60
63
|
|
61
|
-
Reporter.new(report).log_summary
|
64
|
+
Reporter.new(config, report).log_summary
|
62
65
|
end
|
63
66
|
|
64
67
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
require "byebug"
|
1
2
|
require "codeclimate-test-reporter"
|
2
3
|
CodeClimate::TestReporter.start
|
3
4
|
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
5
|
+
require_relative "../lib/beetle_etl.rb"
|
6
|
+
require_relative "support/database_helpers.rb"
|
7
|
+
require_relative "support/file_helpers.rb"
|
7
8
|
|
8
9
|
RSpec.configure do |config|
|
9
10
|
|
@@ -13,8 +14,6 @@ RSpec.configure do |config|
|
|
13
14
|
config.backtrace_exclusion_patterns = [/rspec-core/]
|
14
15
|
|
15
16
|
config.around(:each) do |example|
|
16
|
-
BeetleETL.reset
|
17
|
-
|
18
17
|
if example.metadata[:feature]
|
19
18
|
example.run
|
20
19
|
else
|
@@ -6,16 +6,16 @@ module BeetleETL
|
|
6
6
|
let(:external_source) { 'my_source' }
|
7
7
|
let(:another_source) { 'another_source' }
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
config.external_source = external_source
|
15
|
-
config.database = test_database
|
9
|
+
let(:config) do
|
10
|
+
Configuration.new.tap do |c|
|
11
|
+
c.stage_schema = 'stage'
|
12
|
+
c.external_source = external_source
|
13
|
+
c.database = test_database
|
16
14
|
end
|
17
15
|
end
|
18
16
|
|
17
|
+
subject { AssignIds.new(config, :example_table) }
|
18
|
+
|
19
19
|
describe '#dependencies' do
|
20
20
|
it 'depends on TableDiff of the same table' do
|
21
21
|
expect(subject.dependencies).to eql(['example_table: TableDiff'].to_set)
|
@@ -3,20 +3,22 @@ require 'spec_helper'
|
|
3
3
|
module BeetleETL
|
4
4
|
describe CreateStage do
|
5
5
|
|
6
|
+
let(:config) do
|
7
|
+
Configuration.new.tap do |c|
|
8
|
+
c.database = test_database
|
9
|
+
c.external_source = "source"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
6
13
|
describe '#dependencies' do
|
7
14
|
it 'has no dependencies' do
|
8
|
-
subject = CreateStage.new(:example_table, double(:dependencies), double(:columns))
|
15
|
+
subject = CreateStage.new(config, :example_table, double(:dependencies), double(:columns))
|
9
16
|
expect(subject.dependencies).to eql(Set.new)
|
10
17
|
end
|
11
18
|
end
|
12
19
|
|
13
20
|
describe '#run' do
|
14
21
|
before do
|
15
|
-
BeetleETL.configure do |config|
|
16
|
-
config.database = test_database
|
17
|
-
config.external_source = "source"
|
18
|
-
end
|
19
|
-
|
20
22
|
test_database.execute <<-SQL
|
21
23
|
CREATE TABLE example_table (
|
22
24
|
id INTEGER,
|
@@ -42,7 +44,7 @@ module BeetleETL
|
|
42
44
|
end
|
43
45
|
|
44
46
|
let(:subject) do
|
45
|
-
CreateStage.new(:example_table, @relations, @columns)
|
47
|
+
CreateStage.new(config, :example_table, @relations, @columns)
|
46
48
|
end
|
47
49
|
|
48
50
|
it 'creates a stage table table with all payload columns' do
|
@@ -82,30 +84,30 @@ module BeetleETL
|
|
82
84
|
|
83
85
|
it 'does not add foreign key columns twice if defined as payload column' do
|
84
86
|
columns = [:some_string, :dependee_a_id]
|
85
|
-
CreateStage.new(:example_table, @relations, columns).run
|
87
|
+
CreateStage.new(config, :example_table, @relations, columns).run
|
86
88
|
end
|
87
89
|
|
88
90
|
it 'raises an error if no columns and no relations are defined' do
|
89
91
|
expect do
|
90
|
-
CreateStage.new(:example_table, {}, []).run
|
92
|
+
CreateStage.new(config, :example_table, {}, []).run
|
91
93
|
end.to raise_error(BeetleETL::NoColumnsDefinedError)
|
92
94
|
end
|
93
95
|
|
94
96
|
it 'raises an error when given columns with no definition' do
|
95
97
|
expect do
|
96
|
-
CreateStage.new(:example_table, @relations, [:undefined_column]).run
|
98
|
+
CreateStage.new(config, :example_table, @relations, [:undefined_column]).run
|
97
99
|
end.to raise_error(BeetleETL::ColumnDefinitionNotFoundError)
|
98
100
|
end
|
99
101
|
|
100
102
|
it "truncates the stage table if it already exists" do
|
101
|
-
CreateStage.new(:example_table, {}, @columns).run
|
103
|
+
CreateStage.new(config, :example_table, {}, @columns).run
|
102
104
|
|
103
105
|
insert_into(subject.stage_table_name.to_sym).values(
|
104
106
|
[ :some_string , :some_integer , :some_float ] ,
|
105
107
|
[ "hello" , 123 , 123.456 ]
|
106
108
|
)
|
107
109
|
|
108
|
-
CreateStage.new(:example_table, {}, @columns).run
|
110
|
+
CreateStage.new(config, :example_table, {}, @columns).run
|
109
111
|
|
110
112
|
expect(subject.stage_table_name).to have_values(
|
111
113
|
[:some_string, :some_integer, :some_float]
|
data/spec/steps/load_spec.rb
CHANGED
@@ -11,14 +11,16 @@ module BeetleETL
|
|
11
11
|
let(:now) { Time.now.beginning_of_day }
|
12
12
|
let(:yesterday) { 1.day.ago.beginning_of_day }
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
config.external_source = external_source
|
19
|
-
config.database = test_database
|
14
|
+
let(:config) do
|
15
|
+
Configuration.new.tap do |c|
|
16
|
+
c.external_source = external_source
|
17
|
+
c.database = test_database
|
20
18
|
end
|
19
|
+
end
|
21
20
|
|
21
|
+
subject { Load.new(config, :example_table, []) }
|
22
|
+
|
23
|
+
before do
|
22
24
|
allow(subject).to receive(:now) { now }
|
23
25
|
|
24
26
|
test_database.create_schema(:stage)
|
@@ -54,7 +56,7 @@ module BeetleETL
|
|
54
56
|
dependee_b_id: :dependee_b,
|
55
57
|
}
|
56
58
|
|
57
|
-
expect(Load.new(:depender, relations).dependencies).to eql(
|
59
|
+
expect(Load.new(config, :depender, relations).dependencies).to eql(
|
58
60
|
[
|
59
61
|
'dependee_a: Load',
|
60
62
|
'dependee_b: Load',
|
@@ -3,8 +3,19 @@ require 'spec_helper'
|
|
3
3
|
module BeetleETL
|
4
4
|
describe MapRelations do
|
5
5
|
|
6
|
-
let(:
|
7
|
-
|
6
|
+
let(:config) do
|
7
|
+
Configuration.new.tap do |c|
|
8
|
+
c.external_source = 'my_source'
|
9
|
+
c.database = test_database
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:dependee_a) do
|
14
|
+
BeetleETL::Naming.stage_table_name('my_source', :dependee_a).to_sym
|
15
|
+
end
|
16
|
+
let(:dependee_b) do
|
17
|
+
BeetleETL::Naming.stage_table_name('my_source', :dependee_b).to_sym
|
18
|
+
end
|
8
19
|
|
9
20
|
let(:relations) do
|
10
21
|
{
|
@@ -14,15 +25,10 @@ module BeetleETL
|
|
14
25
|
end
|
15
26
|
|
16
27
|
subject do
|
17
|
-
MapRelations.new(:depender, relations)
|
28
|
+
MapRelations.new(config, :depender, relations)
|
18
29
|
end
|
19
30
|
|
20
31
|
before do
|
21
|
-
BeetleETL.configure do |config|
|
22
|
-
config.external_source = 'my_source'
|
23
|
-
config.database = test_database
|
24
|
-
end
|
25
|
-
|
26
32
|
test_database.create_table(dependee_a) do
|
27
33
|
Integer :id
|
28
34
|
String :external_id, size: 255
|
data/spec/steps/step_spec.rb
CHANGED
@@ -3,7 +3,9 @@ require 'spec_helper'
|
|
3
3
|
module BeetleETL
|
4
4
|
describe Step do
|
5
5
|
|
6
|
-
|
6
|
+
let(:config) { Configuration.new }
|
7
|
+
|
8
|
+
subject { Step.new(config, :example_table) }
|
7
9
|
FooStep = Class.new(Step)
|
8
10
|
|
9
11
|
describe '.step_name' do
|
@@ -18,11 +20,11 @@ module BeetleETL
|
|
18
20
|
|
19
21
|
describe '#name' do
|
20
22
|
it 'returns the steps name' do
|
21
|
-
expect(Step.new(:example_table).name).to eql('example_table: Step')
|
23
|
+
expect(Step.new(config, :example_table).name).to eql('example_table: Step')
|
22
24
|
end
|
23
25
|
|
24
26
|
it 'returns the step name of inheriting steps' do
|
25
|
-
expect(FooStep.new(:foo_table).name).to eql('foo_table: FooStep')
|
27
|
+
expect(FooStep.new(config, :foo_table).name).to eql('foo_table: FooStep')
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
@@ -7,15 +7,16 @@ module BeetleETL
|
|
7
7
|
describe TableDiff do
|
8
8
|
|
9
9
|
let(:external_source) { 'my_source' }
|
10
|
+
let(:config) do
|
11
|
+
Configuration.new.tap do |c|
|
12
|
+
c.external_source = external_source
|
13
|
+
c.database = test_database
|
14
|
+
end
|
15
|
+
end
|
10
16
|
|
11
|
-
subject { TableDiff.new(:example_table) }
|
17
|
+
subject { TableDiff.new(config, :example_table) }
|
12
18
|
|
13
19
|
before do
|
14
|
-
BeetleETL.configure do |config|
|
15
|
-
config.external_source = external_source
|
16
|
-
config.database = test_database
|
17
|
-
end
|
18
|
-
|
19
20
|
test_database.create_table(subject.stage_table_name.to_sym) do
|
20
21
|
String :external_id, size: 255
|
21
22
|
String :transition, size: 20
|
@@ -3,10 +3,17 @@ require 'spec_helper'
|
|
3
3
|
module BeetleETL
|
4
4
|
describe Transform do
|
5
5
|
|
6
|
+
let(:database) { double(:database) }
|
7
|
+
let(:config) do
|
8
|
+
Configuration.new.tap do |c|
|
9
|
+
c.database = database
|
10
|
+
end
|
11
|
+
end
|
6
12
|
let(:query) { double(:query) }
|
13
|
+
|
7
14
|
subject do
|
8
15
|
deps = [:some_table, :some_other_table].to_set
|
9
|
-
Transform.new(:example_table, deps, query)
|
16
|
+
Transform.new(config, :example_table, deps, query)
|
10
17
|
end
|
11
18
|
|
12
19
|
describe '#dependencies' do
|
@@ -22,9 +29,6 @@ module BeetleETL
|
|
22
29
|
|
23
30
|
describe '#run' do
|
24
31
|
it 'runs a query in the database' do
|
25
|
-
database = double(:database)
|
26
|
-
BeetleETL.configure { |config| config.database = database }
|
27
|
-
|
28
32
|
expect(database).to receive(:run).with(query)
|
29
33
|
|
30
34
|
subject.run
|
data/spec/testing_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beetle_etl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luciano Maiwald
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1.
|
47
|
+
version: '1.11'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1.
|
54
|
+
version: '1.11'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,6 +116,7 @@ executables: []
|
|
116
116
|
extensions: []
|
117
117
|
extra_rdoc_files: []
|
118
118
|
files:
|
119
|
+
- ".byebug_history"
|
119
120
|
- ".gitignore"
|
120
121
|
- ".travis.yml"
|
121
122
|
- Gemfile
|
@@ -124,6 +125,7 @@ files:
|
|
124
125
|
- Rakefile
|
125
126
|
- beetle_etl.gemspec
|
126
127
|
- lib/beetle_etl.rb
|
128
|
+
- lib/beetle_etl/configuration.rb
|
127
129
|
- lib/beetle_etl/dsl/dsl.rb
|
128
130
|
- lib/beetle_etl/dsl/transformation.rb
|
129
131
|
- lib/beetle_etl/dsl/transformation_loader.rb
|
@@ -145,6 +147,7 @@ files:
|
|
145
147
|
- lib/beetle_etl/version.rb
|
146
148
|
- script/postgres
|
147
149
|
- spec/beetle_etl_spec.rb
|
150
|
+
- spec/configuration_spec.rb
|
148
151
|
- spec/dsl/dsl_spec.rb
|
149
152
|
- spec/dsl/transformation_loader_spec.rb
|
150
153
|
- spec/dsl/transformation_spec.rb
|
@@ -186,12 +189,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
189
|
version: '0'
|
187
190
|
requirements: []
|
188
191
|
rubyforge_project:
|
189
|
-
rubygems_version: 2.
|
192
|
+
rubygems_version: 2.2.5
|
190
193
|
signing_key:
|
191
194
|
specification_version: 4
|
192
195
|
summary: BeetleETL helps you with your recurring ETL imports.
|
193
196
|
test_files:
|
194
197
|
- spec/beetle_etl_spec.rb
|
198
|
+
- spec/configuration_spec.rb
|
195
199
|
- spec/dsl/dsl_spec.rb
|
196
200
|
- spec/dsl/transformation_loader_spec.rb
|
197
201
|
- spec/dsl/transformation_spec.rb
|