kiba-common 0.6.0 → 0.7.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/Changes.md +2 -0
- data/README.md +33 -0
- data/kiba-common.gemspec +1 -0
- data/lib/kiba-common/transforms/source_transform_adapter.rb +14 -0
- data/lib/kiba-common/version.rb +1 -1
- data/test/helper.rb +1 -0
- data/test/test_source_transform_adapter.rb +24 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73129b07c0c847b9a1ed5b2a88e0fe3b9449200589fea6e0b88696959c86448f
|
4
|
+
data.tar.gz: 1a73e5414c054fbb233c92c5459087153a6ad413bfa194c192d8ea54cd4ee3ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f984de5843f926e3c153c381a1e05d171275fa185c3b0b2c7d855250b75c6ed85841ad78d87cb55b9cc4d6759e7d50c585765483ef27f0c3c64f80b8a739e957
|
7
|
+
data.tar.gz: 1e05cefc61c51f474f93b8f331e3d17a1de7c2ec3683212336796e3dcbc164bc9d5bc9049a8f255c25d237a8f8e38516d02db45f343a903d2bd76ad439515330
|
data/Changes.md
CHANGED
data/README.md
CHANGED
@@ -38,6 +38,39 @@ You can pass a callable to make sure the evaluation will occur after your [pre-p
|
|
38
38
|
source Kiba::Common::Sources::Enumerable, -> { Dir["input/*.json"] }
|
39
39
|
```
|
40
40
|
|
41
|
+
### Kiba::Common::Transforms::SourceTransformAdapter
|
42
|
+
|
43
|
+
Let's say you have a source (e.g. `CSVSource`), which you would like to instantiate for each input row (e.g. a list of filenames).
|
44
|
+
|
45
|
+
Normally you'd have to bake file iteration right inside your source.
|
46
|
+
|
47
|
+
But since Kiba v2 introduction of `StreamingRunner`, it is possible for transforms to yield an arbitrary (potentially infinite) amount of rows.
|
48
|
+
|
49
|
+
Leveraging that possibility, you can use a `SourceTransformAdapter` to dynamically instantiate the source for each of your input rows.
|
50
|
+
|
51
|
+
This allows to mix-and-match components in a much more versatile & powerful way.
|
52
|
+
|
53
|
+
Requirements: Kiba v2 with `StreamingRunner` enabled.
|
54
|
+
|
55
|
+
Usage:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
source Kiba::Common::Sources::Enumerable, -> { Dir["input/*.csv"] }
|
59
|
+
|
60
|
+
transform do |r|
|
61
|
+
# build up the args that you would normally pass to your source, e.g.
|
62
|
+
# source MyCSV, filename: 'file.csv'
|
63
|
+
# but instead, using the input as a parameter
|
64
|
+
[MyCSVSource, filename: r]
|
65
|
+
end
|
66
|
+
|
67
|
+
# this will instantiate one source per input row, yielding rows
|
68
|
+
# that your source would normally yield
|
69
|
+
transform Kiba::Common::Transforms::SourceTransformAdapter
|
70
|
+
```
|
71
|
+
|
72
|
+
This can be used for a wide array of scenarios, including extracting data for N third-party accounts of a same system, with an array of API keys etc.
|
73
|
+
|
41
74
|
### Kiba::Common::Transforms::EnumerableExploder
|
42
75
|
|
43
76
|
A transform calling `each` on input rows (assuming they are e.g. arrays of sub-rows) and yielding one output row per enumerated element.
|
data/kiba-common.gemspec
CHANGED
data/lib/kiba-common/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require 'kiba-common/transforms/source_transform_adapter'
|
3
|
+
|
4
|
+
class TestSourceTransformAdapter < Minitest::Test
|
5
|
+
include Kiba::Common::Sources
|
6
|
+
include Kiba::DSLExtensions
|
7
|
+
|
8
|
+
def test_instantiation
|
9
|
+
rows = []
|
10
|
+
job = Kiba.parse do
|
11
|
+
extend Config
|
12
|
+
config :kiba, runner: Kiba::StreamingRunner
|
13
|
+
|
14
|
+
source Enumerable, [
|
15
|
+
[ Enumerable, (1..10) ],
|
16
|
+
[ Enumerable, (11..20) ]
|
17
|
+
]
|
18
|
+
transform Kiba::Common::Transforms::SourceTransformAdapter
|
19
|
+
destination TestArrayDestination, rows
|
20
|
+
end
|
21
|
+
Kiba.run(job)
|
22
|
+
assert_equal (1..20).to_a, rows
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kiba-common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thibaut Barrère
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kiba
|
@@ -72,6 +72,20 @@ dependencies:
|
|
72
72
|
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: minitest-focus
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
75
89
|
description: Commonly used helpers for Kiba ETL
|
76
90
|
email:
|
77
91
|
- thibaut.barrere@gmail.com
|
@@ -92,6 +106,7 @@ files:
|
|
92
106
|
- lib/kiba-common/dsl_extensions/show_me.rb
|
93
107
|
- lib/kiba-common/sources/enumerable.rb
|
94
108
|
- lib/kiba-common/transforms/enumerable_exploder.rb
|
109
|
+
- lib/kiba-common/transforms/source_transform_adapter.rb
|
95
110
|
- lib/kiba-common/version.rb
|
96
111
|
- test/helper.rb
|
97
112
|
- test/support/assert_called.rb
|
@@ -101,6 +116,7 @@ files:
|
|
101
116
|
- test/test_enumerable_source.rb
|
102
117
|
- test/test_logger.rb
|
103
118
|
- test/test_show_me.rb
|
119
|
+
- test/test_source_transform_adapter.rb
|
104
120
|
homepage: https://github.com/thbar/kiba-common
|
105
121
|
licenses:
|
106
122
|
- LGPL-3.0
|
@@ -134,3 +150,4 @@ test_files:
|
|
134
150
|
- test/test_enumerable_source.rb
|
135
151
|
- test/test_logger.rb
|
136
152
|
- test/test_show_me.rb
|
153
|
+
- test/test_source_transform_adapter.rb
|