raka 0.3.10 → 0.3.13
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/README.md +54 -6
- data/VERSION +1 -1
- data/lib/raka/compile.rb +1 -0
- data/lib/raka/lang/psql/impl.rb +7 -6
- data/lib/raka/token.rb +6 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7433868304f673611a2ce9b5e847a8a78cd6bbd0be86fe18d576090acf7009f
|
4
|
+
data.tar.gz: ebe65786208dfd8bf1e35ea83a6ad625279018aa3a73df14599392bbaa91d684
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8498aa76cd3a4ec7277fb0d7e7618c030c70cab306258bec7b5806c0da249108943e56f2b78bf41eb9fddc54d0f0aada4cfb21e59abca81db5dc8fc7495f18c
|
7
|
+
data.tar.gz: 7eef06176d02da633b5fc2138d675ec66809f479a84e155800f25d6797ed0aa463a58d76a77d1540d1d6b9eb8c6abfed39d60f78881344634cbd37610fdae579
|
data/README.md
CHANGED
@@ -338,7 +338,7 @@ In the host protocol and the block versions of other protocols, a raka task (the
|
|
338
338
|
| scope | scope for current task, i.e. the common directory for output, input and dependencies |
|
339
339
|
| target_scope | the inline scope defined in target |
|
340
340
|
| target_scope_captures | captured values by inline scope defined in target |
|
341
|
-
| rule_scopes | the
|
341
|
+
| rule_scopes | the scope components bounded by the rule scopes |
|
342
342
|
|
343
343
|
```ruby
|
344
344
|
require 'raka'
|
@@ -469,13 +469,61 @@ The `input_types` involves the strategy to find inputs. All possible input types
|
|
469
469
|
|
470
470
|
### Scope
|
471
471
|
|
472
|
-
Scopes
|
472
|
+
Scopes represent the context of a running task and its components, which are generally folders physically. Users can define scope constraints with rules to help users create rules more precisely. and can happen in several places.
|
473
473
|
|
474
|
-
|
474
|
+
Scope constraints:
|
475
475
|
|
476
|
-
**Rule scope** is the scope to restrict possible task scope
|
476
|
+
**Rule scope** is the scope to restrict possible task scope. Rule scopes can be layered, each layer with several options, like:
|
477
477
|
|
478
|
-
|
478
|
+
```ruby
|
479
|
+
dsl.scope :de, :fr
|
480
|
+
dsl.scope :food, :med
|
481
|
+
...rules
|
482
|
+
end
|
483
|
+
end
|
484
|
+
```
|
485
|
+
|
486
|
+
**Target scope** is the scope to restrict a single target. It can be used in the left-hand part of a rule, or as dependencies in the right-hand. For example:
|
487
|
+
|
488
|
+
```ruby
|
489
|
+
# The constraint "de" only apply to food.csv and fruit__food.csv, not classifier.csv
|
490
|
+
csv('de').food.fruit = [csv.classifier] | action
|
491
|
+
```
|
492
|
+
|
493
|
+
When resolved, scope constraints are verified and scopes are extracted and parsed, including the following concepts:
|
494
|
+
|
495
|
+
**Scope**(**Task scope**) is the common scope of the task, every target is resolved under the scope.
|
496
|
+
|
497
|
+
**Rule bounded scopes** (abbr. rule scopes) are the parts of scope bounded by the **Rule scope** constraints.
|
498
|
+
|
499
|
+
**Target bounded scope** (abbr. target scope) is the part of scope bounded by the **Target scope** constraints.
|
500
|
+
|
501
|
+
**Output scope** is the scope of output, while **Dep scope** is the scope of dependencies.
|
502
|
+
|
503
|
+
The following example illustrates the relationships of the above concepts.
|
504
|
+
|
505
|
+
Rule definition:
|
506
|
+
|
507
|
+
```ruby
|
508
|
+
dsl.scope :de, :fr,
|
509
|
+
dsl.scope :food, :med
|
510
|
+
csv('percent_(\d+)').data.cheap = [csv('base').price] | ...
|
511
|
+
end
|
512
|
+
end
|
513
|
+
```
|
514
|
+
|
515
|
+
When running `raka out/de/food/percent_50/cheap__data.csv`, the extracted scopes are as follows:
|
516
|
+
|
517
|
+

|
518
|
+
|
519
|
+
The auto variables are:
|
520
|
+
|
521
|
+
|var|value|var|value|
|
522
|
+
|---|-----|---|-----|
|
523
|
+
|$(scope)|out/de/food|$(output_scope)|out/de/food/percent_50|
|
524
|
+
|$(rule_scope0)|food|$(rule_scope1)|de|
|
525
|
+
|$(target_scope)|percent_50|$(target_scope0)|50|
|
526
|
+
|$(dep1_scope)|out/de/food/base|||
|
479
527
|
|
480
528
|
## Rakefile Template
|
481
529
|
|
@@ -483,4 +531,4 @@ Scopes define constraints which help users create rules more precisely. A scope
|
|
483
531
|
|
484
532
|
## Compare to other tools
|
485
533
|
|
486
|
-
Raka borrows some ideas from Drake but not much (currently mainly the name "protocol"). Briefly we have different visions and maybe different suitable
|
534
|
+
Raka borrows some ideas from Drake but not much (currently mainly the name "protocol"). Briefly, we have different visions and maybe different suitable scenarios.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.13
|
data/lib/raka/compile.rb
CHANGED
data/lib/raka/lang/psql/impl.rb
CHANGED
@@ -17,9 +17,9 @@ end
|
|
17
17
|
# postgresql protocol using psql, requires HOST, PORT, USER, DB
|
18
18
|
class Psql
|
19
19
|
# Sometimes we want to use the psql command with bash directly
|
20
|
-
def sh_cmd(
|
20
|
+
def sh_cmd(schema)
|
21
21
|
c = @conn
|
22
|
-
env_vars = "PGOPTIONS='-c search_path=#{
|
22
|
+
env_vars = "PGOPTIONS='-c search_path=#{schema.empty? ? '' : schema + ','}public' "
|
23
23
|
"PGPASSWORD=#{c.password} #{env_vars} psql -h #{c.host} -p #{c.port} -U #{c.user} -d #{c.db} -v ON_ERROR_STOP=1"
|
24
24
|
end
|
25
25
|
|
@@ -35,10 +35,10 @@ class Psql
|
|
35
35
|
raise 'argument conn required' if @conn.nil?
|
36
36
|
|
37
37
|
if @create.to_s == 'table'
|
38
|
-
'DROP TABLE IF EXISTS :_name_;' \
|
38
|
+
'DROP TABLE IF EXISTS :_schema_.:_name_;' \
|
39
39
|
'CREATE TABLE :_name_ AS (' + code + ');'
|
40
40
|
elsif @create.to_s == 'mview'
|
41
|
-
'DROP MATERIALIZED VIEW IF EXISTS :_name_;' \
|
41
|
+
'DROP MATERIALIZED VIEW IF EXISTS :_schema_.:_name_;' \
|
42
42
|
'CREATE MATERIALIZED VIEW :_name_ AS (' + code + ');'
|
43
43
|
else
|
44
44
|
code
|
@@ -47,10 +47,11 @@ class Psql
|
|
47
47
|
|
48
48
|
def run_script(env, fname, task)
|
49
49
|
param_str = (@params || {}).map { |k, v| "-v #{k}=\"#{v}\"" }.join(' ')
|
50
|
+
schema = task.rule_scopes.join('__')
|
50
51
|
|
51
52
|
bash env, %(
|
52
|
-
#{sh_cmd(
|
53
|
-
-f #{fname} | tee #{fname}.log
|
53
|
+
#{sh_cmd(schema)} #{param_str} -v _name_=#{task.output_stem} \
|
54
|
+
-v _schema_=#{schema} -f #{fname} | tee #{fname}.log
|
54
55
|
mv #{fname}.log #{task.name}
|
55
56
|
)
|
56
57
|
end
|
data/lib/raka/token.rb
CHANGED
@@ -58,7 +58,7 @@ class Token
|
|
58
58
|
res = Hash[info.names.zip(info.captures)]
|
59
59
|
unless info[:scope].nil?
|
60
60
|
rule_scopes = Regexp.new(_scope_pattern_).match(info[:scope]).captures
|
61
|
-
res[:rule_scopes] = rule_scopes[
|
61
|
+
res[:rule_scopes] = rule_scopes[2..-1].reverse
|
62
62
|
end
|
63
63
|
if !@inline_scope.nil? && !info[:target_scope].nil?
|
64
64
|
segs = Regexp.new(@inline_scope).match(info[:target_scope]).captures
|
@@ -130,8 +130,12 @@ class Token
|
|
130
130
|
[auto_input]
|
131
131
|
end
|
132
132
|
|
133
|
+
def _rule_scope_pattern_
|
134
|
+
(@context.scopes.map { |layer| "(#{layer.join('|')})" }).join('/') + ')'
|
135
|
+
end
|
136
|
+
|
133
137
|
def _scope_pattern_
|
134
|
-
'((?:(\S+)/)?' +
|
138
|
+
'((?:(\S+)/)?' + _rule_scope_pattern_
|
135
139
|
end
|
136
140
|
|
137
141
|
def _pattern_
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yarray
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|