-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from bmeg/feature/code-ref
[WIP] External code references
- Loading branch information
Showing
15 changed files
with
187 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
class: Playbook | ||
name: codeTest | ||
|
||
inputs: | ||
startData: | ||
embedded: | ||
- {"value": 0, "name": "alice"} | ||
- {"value": 1, "name": "bob"} | ||
- {"value": 2, "name": "charlie"} | ||
|
||
|
||
pipelines: | ||
codeTest: | ||
- from: startData | ||
- map: | ||
method: update | ||
gpython: | ||
$ref: map.py | ||
- map: | ||
method: update | ||
gpython: | | ||
def update(x): | ||
x["value"] = x["value"] + 1 | ||
return x | ||
- debug: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def filter_bob(row): | ||
return row['name'] == "bob" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
def fix(row): | ||
out = { | ||
"identifier":[{ | ||
"system": "https://redivis.com/datasets/ye2v-6skh7wdr7/tables", | ||
"value":str(int(row["person_id"])) | ||
}] | ||
} | ||
|
||
if(row["person_source_value"] is not None): | ||
out["identifier"].append({ | ||
"value": row["person_source_value"], | ||
"system": "https://redivis.com/datasets/ye2v-6skh7wdr7/tables" | ||
}) | ||
else: | ||
out["identifier"].append({"value": "None", "system": "https://redivis.com/datasets/ye2v-6skh7wdr7/tables"}) | ||
|
||
out["identifier"][1]["value"] = str(out["identifier"][1]["value"]) + "_" + "None" | ||
|
||
return out["identifier"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
class: Playbook | ||
name: codeTest | ||
|
||
inputs: | ||
startData: | ||
embedded: | ||
- {"COMPLEX_ID":"Complex_76a0f49f-272e-4ec4-bcba-723806b35a31___null__6468_","PROTEIN":"Q9Y296"} | ||
- {"COMPLEX_ID":"Complex_da6f165b-e085-4ec6-ba43-1170756b0a57___null__6967_","PROTEIN":"O08957"} | ||
- {"COMPLEX_ID":"Complex_c688ddcc-a541-4098-ab0d-25b87e5bc5cd___null__1097_","PROTEIN":"Q13347"} | ||
|
||
otherData: | ||
embedded: | ||
- {"person_id": 3589912774911670272, "person_source_value": 10009628, "name": "alice"} | ||
- {"person_id": -3210373572193940992, "person_source_value": 10011398, "name": "bob"} | ||
- {"person_id": -775517641933593344, "person_source_value": 10004235, "name": "charlie"} | ||
|
||
pipelines: | ||
filterpipeline: | ||
- from: startData | ||
- reduce: | ||
field: COMPLEX_ID | ||
method: merge | ||
init: { "proteins": [] } | ||
gpython: | ||
$ref: reduce.py | ||
|
||
- debug: {} | ||
|
||
otherpipelines: | ||
- from: otherData | ||
- filter: | ||
# The [field,match] values and the gpython file give the same result | ||
#field: name | ||
#match: bob | ||
method: filter_bob | ||
gpython: | ||
$ref: filter.py | ||
#- debug: {} | ||
- flatMap: | ||
method: fix | ||
gpython: | ||
$ref: flatMap.py | ||
|
||
- debug: {} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
def update(x): | ||
x["value"] = x["value"] + 1 | ||
return x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
def merge(x,y): | ||
x["proteins"] = [x["PROTEIN"]] + y["proteins"] | ||
return x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
def test(row): | ||
row["TEST"] = "test_string" | ||
return row |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package transform | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
type CodeBlock struct { | ||
Code string | ||
Ref string | ||
BaseDir string | ||
} | ||
|
||
func (cb *CodeBlock) UnmarshalJSON(data []byte) error { | ||
if err := json.Unmarshal(data, &cb.Code); err == nil { | ||
return nil | ||
} | ||
ref := map[string]any{} | ||
if err := json.Unmarshal(data, &ref); err == nil { | ||
if path, ok := ref["$ref"]; ok { | ||
if pathStr, ok := path.(string); ok { | ||
cb.Ref = pathStr | ||
return nil | ||
} | ||
} | ||
} | ||
return fmt.Errorf("unknown code block type") | ||
} | ||
|
||
func (cb *CodeBlock) SetBaseDir(path string) { | ||
cb.BaseDir = path | ||
} | ||
|
||
func (cb *CodeBlock) String() string { | ||
if cb.Ref != "" { | ||
path := filepath.Join(cb.BaseDir, cb.Ref) | ||
data, err := os.ReadFile(path) | ||
if err == nil { | ||
cb.Code = string(data) | ||
} | ||
} | ||
return cb.Code | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters