kiba 2.0.0.rc1 → 3.6.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 +5 -5
- data/.github/FUNDING.yml +1 -0
- data/.travis.yml +12 -14
- data/COMM-LICENSE.md +348 -0
- data/Changes.md +32 -2
- data/ISSUE_TEMPLATE.md +7 -0
- data/LICENSE +3 -1
- data/Pro-Changes.md +82 -5
- data/README.md +12 -32
- data/Rakefile +6 -1
- data/appveyor.yml +6 -3
- data/bin/kiba +12 -2
- data/kiba.gemspec +4 -0
- data/lib/kiba.rb +8 -2
- data/lib/kiba/context.rb +4 -0
- data/lib/kiba/parser.rb +6 -22
- data/lib/kiba/runner.rb +4 -8
- data/lib/kiba/streaming_runner.rb +5 -0
- data/lib/kiba/version.rb +1 -1
- data/test/helper.rb +10 -2
- data/test/{common/runner.rb → shared_runner_tests.rb} +97 -6
- data/test/support/test_aggregate_transform.rb +19 -0
- data/test/support/test_close_yielding_transform.rb +11 -0
- data/test/support/test_destination_returning_nil.rb +12 -0
- data/test/support/test_duplicate_row_transform.rb +9 -0
- data/test/support/test_keyword_arguments_component.rb +14 -0
- data/test/support/test_mixed_arguments_component.rb +14 -0
- data/test/support/test_non_closing_transform.rb +5 -0
- data/test/test_integration.rb +3 -3
- data/test/test_parser.rb +0 -33
- data/test/test_run.rb +38 -0
- data/test/test_runner.rb +6 -1
- data/test/test_streaming_runner.rb +42 -5
- metadata +32 -23
- data/lib/kiba/cli.rb +0 -16
- data/test/fixtures/bogus.etl +0 -2
- data/test/fixtures/namespace_conflict.etl +0 -9
- data/test/fixtures/some_extension.rb +0 -4
- data/test/fixtures/valid.etl +0 -1
- data/test/test_cli.rb +0 -21
@@ -0,0 +1,19 @@
|
|
1
|
+
class AggregateTransform
|
2
|
+
def initialize(options)
|
3
|
+
@aggregate_size = options.fetch(:aggregate_size)
|
4
|
+
end
|
5
|
+
|
6
|
+
def process(row)
|
7
|
+
@buffer ||= []
|
8
|
+
@buffer << row
|
9
|
+
if @buffer.size == @aggregate_size
|
10
|
+
yield @buffer
|
11
|
+
@buffer = []
|
12
|
+
end
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def close
|
17
|
+
yield @buffer unless @buffer.empty?
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class TestDestinationReturningNil
|
2
|
+
def initialize(options = {})
|
3
|
+
on_init = options[:on_init]
|
4
|
+
# A little trick to allow outer references to this instance
|
5
|
+
on_init.call(self) if on_init
|
6
|
+
end
|
7
|
+
|
8
|
+
def write(row)
|
9
|
+
(@written_rows ||= []) << row
|
10
|
+
nil
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# a mock component to test Ruby 3 keyword argument support
|
2
|
+
class TestKeywordArgumentsComponent
|
3
|
+
def initialize(mandatory:, optional: nil, on_init: nil)
|
4
|
+
values = {
|
5
|
+
mandatory: mandatory,
|
6
|
+
optional: optional
|
7
|
+
}
|
8
|
+
on_init&.call(values)
|
9
|
+
end
|
10
|
+
|
11
|
+
def each
|
12
|
+
# no-op
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# a mock component to test Ruby 3 keyword argument support
|
2
|
+
class TestMixedArgumentsComponent
|
3
|
+
def initialize(some_value, mandatory:, optional: nil, on_init:)
|
4
|
+
@values = {}
|
5
|
+
@values[:some_value] = some_value
|
6
|
+
@values[:mandatory] = mandatory
|
7
|
+
@values[:optional] = optional
|
8
|
+
on_init&.call(@values)
|
9
|
+
end
|
10
|
+
|
11
|
+
def each
|
12
|
+
# no-op
|
13
|
+
end
|
14
|
+
end
|
data/test/test_integration.rb
CHANGED
@@ -8,10 +8,10 @@ require_relative 'support/test_source_that_reads_at_instantiation_time'
|
|
8
8
|
|
9
9
|
# End-to-end tests go here
|
10
10
|
class TestIntegration < Kiba::Test
|
11
|
-
|
12
|
-
|
11
|
+
def output_file; 'test/tmp/output.csv'; end
|
12
|
+
def input_file; 'test/tmp/input.csv'; end
|
13
13
|
|
14
|
-
|
14
|
+
def sample_csv_data
|
15
15
|
<<CSV
|
16
16
|
first_name,last_name,sex
|
17
17
|
John,Doe,M
|
data/test/test_parser.rb
CHANGED
@@ -68,39 +68,6 @@ class TestParser < Kiba::Test
|
|
68
68
|
assert_instance_of Proc, control.pre_processes[0][:block]
|
69
69
|
end
|
70
70
|
|
71
|
-
def test_source_as_string_parsing
|
72
|
-
control = Kiba.parse <<RUBY
|
73
|
-
source DummyClass, 'from', 'file'
|
74
|
-
RUBY
|
75
|
-
|
76
|
-
assert_equal 1, control.sources.size
|
77
|
-
assert_equal DummyClass, control.sources[0][:klass]
|
78
|
-
assert_equal %w(from file), control.sources[0][:args]
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_source_as_file_doing_require
|
82
|
-
IO.write 'test/tmp/etl-common.rb', <<RUBY
|
83
|
-
def common_source_declaration
|
84
|
-
source DummyClass, 'from', 'common'
|
85
|
-
end
|
86
|
-
RUBY
|
87
|
-
IO.write 'test/tmp/etl-main.rb', <<RUBY
|
88
|
-
require './test/tmp/etl-common.rb'
|
89
|
-
|
90
|
-
source DummyClass, 'from', 'main'
|
91
|
-
common_source_declaration
|
92
|
-
RUBY
|
93
|
-
control = Kiba.parse IO.read('test/tmp/etl-main.rb')
|
94
|
-
|
95
|
-
assert_equal 2, control.sources.size
|
96
|
-
|
97
|
-
assert_equal %w(from main), control.sources[0][:args]
|
98
|
-
assert_equal %w(from common), control.sources[1][:args]
|
99
|
-
|
100
|
-
ensure
|
101
|
-
remove_files('test/tmp/etl-common.rb', 'test/tmp/etl-main.rb')
|
102
|
-
end
|
103
|
-
|
104
71
|
def test_config
|
105
72
|
control = Kiba.parse do
|
106
73
|
extend Kiba::DSLExtensions::Config
|
data/test/test_run.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require 'minitest/mock'
|
3
|
+
require_relative 'support/test_enumerable_source'
|
4
|
+
require_relative 'support/test_array_destination'
|
5
|
+
|
6
|
+
class TestRun < Kiba::Test
|
7
|
+
def test_ensure_kiba_defaults_to_streaming_runner
|
8
|
+
cb = -> (job) { "Streaming runner called" }
|
9
|
+
Kiba::StreamingRunner.stub(:run, cb) do
|
10
|
+
job = Kiba::Control.new
|
11
|
+
assert_equal "Streaming runner called", Kiba.run(job)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_run_allows_block_arg
|
16
|
+
rows = []
|
17
|
+
Kiba.run do
|
18
|
+
source TestEnumerableSource, (1..10)
|
19
|
+
destination TestArrayDestination, rows
|
20
|
+
end
|
21
|
+
assert_equal (1..10).to_a, rows
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_forbids_no_arg
|
25
|
+
assert_raises ArgumentError do
|
26
|
+
Kiba.run
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_forbids_multiple_args
|
31
|
+
assert_raises ArgumentError do
|
32
|
+
job = Kiba.parse { }
|
33
|
+
Kiba.run(job) do
|
34
|
+
#
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/test/test_runner.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
require_relative 'helper'
|
2
|
-
require_relative '
|
2
|
+
require_relative 'shared_runner_tests'
|
3
3
|
|
4
4
|
class TestRunner < Kiba::Test
|
5
|
+
def kiba_run(job)
|
6
|
+
job.config[:kiba] = {runner: Kiba::Runner}
|
7
|
+
Kiba.run(job)
|
8
|
+
end
|
9
|
+
|
5
10
|
include SharedRunnerTests
|
6
11
|
end
|
@@ -2,9 +2,19 @@ require_relative 'helper'
|
|
2
2
|
require_relative 'support/test_enumerable_source'
|
3
3
|
require_relative 'support/test_array_destination'
|
4
4
|
require_relative 'support/test_yielding_transform'
|
5
|
-
require_relative '
|
5
|
+
require_relative 'support/test_duplicate_row_transform'
|
6
|
+
require_relative 'support/test_close_yielding_transform'
|
7
|
+
require_relative 'support/test_non_closing_transform'
|
8
|
+
require_relative 'shared_runner_tests'
|
9
|
+
require_relative 'support/test_keyword_arguments_component'
|
10
|
+
require_relative 'support/test_mixed_arguments_component'
|
6
11
|
|
7
12
|
class TestStreamingRunner < Kiba::Test
|
13
|
+
def kiba_run(job)
|
14
|
+
job.config[:kiba] = {runner: Kiba::StreamingRunner}
|
15
|
+
Kiba.run(job)
|
16
|
+
end
|
17
|
+
|
8
18
|
include SharedRunnerTests
|
9
19
|
|
10
20
|
def test_yielding_class_transform
|
@@ -12,12 +22,15 @@ class TestStreamingRunner < Kiba::Test
|
|
12
22
|
destination_array = []
|
13
23
|
|
14
24
|
job = Kiba.parse do
|
15
|
-
|
16
|
-
|
17
|
-
config :kiba, runner: Kiba::StreamingRunner
|
18
|
-
|
25
|
+
# provide a single row as the input
|
19
26
|
source TestEnumerableSource, [input_row]
|
27
|
+
|
28
|
+
# explode tags in one row each
|
20
29
|
transform TestYieldingTransform
|
30
|
+
|
31
|
+
# generate two rows out of each exploded tags row
|
32
|
+
transform TestDuplicateRowTranform
|
33
|
+
|
21
34
|
destination TestArrayDestination, destination_array
|
22
35
|
end
|
23
36
|
|
@@ -25,9 +38,33 @@ class TestStreamingRunner < Kiba::Test
|
|
25
38
|
|
26
39
|
assert_equal [
|
27
40
|
{item: 'one'},
|
41
|
+
{item: 'one'},
|
42
|
+
|
28
43
|
{item: 'two'},
|
44
|
+
{item: 'two'},
|
45
|
+
|
46
|
+
{item: 'three'},
|
29
47
|
{item: 'three'},
|
48
|
+
|
49
|
+
{item: 'classic-return-value'},
|
30
50
|
{item: 'classic-return-value'}
|
31
51
|
], destination_array
|
32
52
|
end
|
53
|
+
|
54
|
+
def test_transform_yielding_from_close
|
55
|
+
destination_array = []
|
56
|
+
job = Kiba.parse do
|
57
|
+
transform CloseYieldingTransform, yield_on_close: [1, 2]
|
58
|
+
destination TestArrayDestination, destination_array
|
59
|
+
end
|
60
|
+
Kiba.run(job)
|
61
|
+
assert_equal [1, 2], destination_array
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_transform_with_no_close_must_not_raise
|
65
|
+
job = Kiba.parse do
|
66
|
+
transform NonClosingTransform
|
67
|
+
end
|
68
|
+
Kiba.run(job)
|
69
|
+
end
|
33
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kiba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thibaut Barrère
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -74,10 +74,13 @@ executables:
|
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
|
+
- ".github/FUNDING.yml"
|
77
78
|
- ".gitignore"
|
78
79
|
- ".travis.yml"
|
80
|
+
- COMM-LICENSE.md
|
79
81
|
- Changes.md
|
80
82
|
- Gemfile
|
83
|
+
- ISSUE_TEMPLATE.md
|
81
84
|
- LICENSE
|
82
85
|
- Pro-Changes.md
|
83
86
|
- README.md
|
@@ -86,7 +89,6 @@ files:
|
|
86
89
|
- bin/kiba
|
87
90
|
- kiba.gemspec
|
88
91
|
- lib/kiba.rb
|
89
|
-
- lib/kiba/cli.rb
|
90
92
|
- lib/kiba/context.rb
|
91
93
|
- lib/kiba/control.rb
|
92
94
|
- lib/kiba/dsl_extensions/config.rb
|
@@ -94,31 +96,36 @@ files:
|
|
94
96
|
- lib/kiba/runner.rb
|
95
97
|
- lib/kiba/streaming_runner.rb
|
96
98
|
- lib/kiba/version.rb
|
97
|
-
- test/common/runner.rb
|
98
|
-
- test/fixtures/bogus.etl
|
99
|
-
- test/fixtures/namespace_conflict.etl
|
100
|
-
- test/fixtures/some_extension.rb
|
101
|
-
- test/fixtures/valid.etl
|
102
99
|
- test/helper.rb
|
100
|
+
- test/shared_runner_tests.rb
|
103
101
|
- test/support/shared_tests.rb
|
102
|
+
- test/support/test_aggregate_transform.rb
|
104
103
|
- test/support/test_array_destination.rb
|
104
|
+
- test/support/test_close_yielding_transform.rb
|
105
105
|
- test/support/test_csv_destination.rb
|
106
106
|
- test/support/test_csv_source.rb
|
107
|
+
- test/support/test_destination_returning_nil.rb
|
108
|
+
- test/support/test_duplicate_row_transform.rb
|
107
109
|
- test/support/test_enumerable_source.rb
|
110
|
+
- test/support/test_keyword_arguments_component.rb
|
111
|
+
- test/support/test_mixed_arguments_component.rb
|
112
|
+
- test/support/test_non_closing_transform.rb
|
108
113
|
- test/support/test_rename_field_transform.rb
|
109
114
|
- test/support/test_source_that_reads_at_instantiation_time.rb
|
110
115
|
- test/support/test_yielding_transform.rb
|
111
|
-
- test/test_cli.rb
|
112
116
|
- test/test_integration.rb
|
113
117
|
- test/test_parser.rb
|
118
|
+
- test/test_run.rb
|
114
119
|
- test/test_runner.rb
|
115
120
|
- test/test_streaming_runner.rb
|
116
121
|
- test/tmp/.gitkeep
|
117
122
|
homepage: http://thbar.github.io/kiba/
|
118
123
|
licenses:
|
119
124
|
- LGPL-3.0
|
120
|
-
metadata:
|
121
|
-
|
125
|
+
metadata:
|
126
|
+
source_code_uri: https://github.com/thbar/kiba
|
127
|
+
documentation_uri: https://github.com/thbar/kiba/wiki
|
128
|
+
post_install_message:
|
122
129
|
rdoc_options: []
|
123
130
|
require_paths:
|
124
131
|
- lib
|
@@ -129,33 +136,35 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
136
|
version: '0'
|
130
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
138
|
requirements:
|
132
|
-
- - "
|
139
|
+
- - ">="
|
133
140
|
- !ruby/object:Gem::Version
|
134
|
-
version:
|
141
|
+
version: '0'
|
135
142
|
requirements: []
|
136
|
-
|
137
|
-
|
138
|
-
signing_key:
|
143
|
+
rubygems_version: 3.2.3
|
144
|
+
signing_key:
|
139
145
|
specification_version: 4
|
140
146
|
summary: Lightweight ETL for Ruby
|
141
147
|
test_files:
|
142
|
-
- test/common/runner.rb
|
143
|
-
- test/fixtures/bogus.etl
|
144
|
-
- test/fixtures/namespace_conflict.etl
|
145
|
-
- test/fixtures/some_extension.rb
|
146
|
-
- test/fixtures/valid.etl
|
147
148
|
- test/helper.rb
|
149
|
+
- test/shared_runner_tests.rb
|
148
150
|
- test/support/shared_tests.rb
|
151
|
+
- test/support/test_aggregate_transform.rb
|
149
152
|
- test/support/test_array_destination.rb
|
153
|
+
- test/support/test_close_yielding_transform.rb
|
150
154
|
- test/support/test_csv_destination.rb
|
151
155
|
- test/support/test_csv_source.rb
|
156
|
+
- test/support/test_destination_returning_nil.rb
|
157
|
+
- test/support/test_duplicate_row_transform.rb
|
152
158
|
- test/support/test_enumerable_source.rb
|
159
|
+
- test/support/test_keyword_arguments_component.rb
|
160
|
+
- test/support/test_mixed_arguments_component.rb
|
161
|
+
- test/support/test_non_closing_transform.rb
|
153
162
|
- test/support/test_rename_field_transform.rb
|
154
163
|
- test/support/test_source_that_reads_at_instantiation_time.rb
|
155
164
|
- test/support/test_yielding_transform.rb
|
156
|
-
- test/test_cli.rb
|
157
165
|
- test/test_integration.rb
|
158
166
|
- test/test_parser.rb
|
167
|
+
- test/test_run.rb
|
159
168
|
- test/test_runner.rb
|
160
169
|
- test/test_streaming_runner.rb
|
161
170
|
- test/tmp/.gitkeep
|
data/lib/kiba/cli.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'kiba'
|
2
|
-
|
3
|
-
module Kiba
|
4
|
-
class Cli
|
5
|
-
def self.run(args)
|
6
|
-
unless args.size == 1
|
7
|
-
puts 'Syntax: kiba your-script.etl'
|
8
|
-
exit(-1)
|
9
|
-
end
|
10
|
-
filename = args[0]
|
11
|
-
script_content = IO.read(filename)
|
12
|
-
job_definition = Kiba.parse(script_content, filename)
|
13
|
-
Kiba.run(job_definition)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/test/fixtures/bogus.etl
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
fail "Context should not be visible without Kiba namespace" if defined?(Context)
|
2
|
-
fail "Control should not be visible without Kiba namespace" if defined?(Control)
|
3
|
-
fail "Parser should not be visible without Kiba namespace" if defined?(Parser)
|
4
|
-
fail "Config should not be visible without Kiba namespace" if defined?(DSLExtensions::Config)
|
5
|
-
|
6
|
-
# verify Kiba config (namespaced under Kiba::DSLExtensions::Config)
|
7
|
-
# isn't causing troubles to implementers using a top-level DSLExtensions module
|
8
|
-
require_relative 'some_extension'
|
9
|
-
extend DSLExtensions::SomeExtension
|