-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(collection): add concat #748
Changes from 3 commits
6c96711
30d0e81
139c0f9
d72fae0
e299f03
233d20b
da68466
32fcb81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,64 @@ | ||||||||
|
||||||||
|
||||||||
## Example Recipes | ||||||||
|
||||||||
In this example, we are combining two arrays of strings using the `union` and `concat` components. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit
Suggested change
|
||||||||
```yaml | ||||||||
variable: | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about documenting and providing examples with a comment here? E.g. # This pipeline combines 2 arrays of strings
# Examples:
# ["foo", "bar"], ["zot", "bat"] -> ["foo", "bar", "zot", "bat"], [] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added these 2 in corresponding components.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant documented the input/output of the pipelines, not the individual components. But it's fine. |
||||||||
texts: | ||||||||
instill-format: array:string | ||||||||
title: Text | ||||||||
texts-2: | ||||||||
instill-format: array:string | ||||||||
title: Text | ||||||||
|
||||||||
component: | ||||||||
union: | ||||||||
type: collection | ||||||||
input: | ||||||||
sets: | ||||||||
- ${variable.texts} | ||||||||
- ${variable.texts-2} | ||||||||
condition: | ||||||||
task: TASK_UNION | ||||||||
concat: | ||||||||
type: collection | ||||||||
input: | ||||||||
arrays: | ||||||||
- ${variable.texts} | ||||||||
- ${variable.texts-2} | ||||||||
condition: | ||||||||
task: TASK_CONCAT | ||||||||
|
||||||||
output: | ||||||||
union-result: | ||||||||
title: Union Result | ||||||||
value: ${union.output.set} | ||||||||
concat-result: | ||||||||
title: Concat Result | ||||||||
value: ${concat.output.array} | ||||||||
``` | ||||||||
|
||||||||
|
||||||||
In this example, we are creating an object with keys `type` and `text` from a string. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit
Suggested change
|
||||||||
```yaml | ||||||||
variable: | ||||||||
text: | ||||||||
instill-format: string | ||||||||
title: Text | ||||||||
|
||||||||
component: | ||||||||
text-object: | ||||||||
type: collection | ||||||||
input: | ||||||||
data: | ||||||||
type: text | ||||||||
text: ${variable.text} | ||||||||
condition: | ||||||||
task: TASK_ASSIGN | ||||||||
|
||||||||
output: | ||||||||
result: | ||||||||
title: Object | ||||||||
value: ${text-object.output.data} | ||||||||
``` |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -316,5 +316,62 @@ | |||||
"title": "Output", | ||||||
"type": "object" | ||||||
} | ||||||
}, | ||||||
"TASK_CONCAT": { | ||||||
"instillShortDescription": "Concat the arrays. i.e. `[1, 2] + [3, 4] = [1, 2, 3, 4]`", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
"input": { | ||||||
"description": "Input", | ||||||
"instillEditOnNodeFields": [ | ||||||
"arrays" | ||||||
], | ||||||
"instillUIOrder": 0, | ||||||
"properties": { | ||||||
"arrays": { | ||||||
"description": "Specify the arrays you want to concat.", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this should be a description, not an order
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗣️ not crucial for this PR, just opening a discussion We need to decide about the periods for the task tables. 2 options:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Now, I follow this, which @GeorgeWilliamStrong mentioned it somewhere. |
||||||
"instillAcceptFormats": [ | ||||||
"array:array:*" | ||||||
], | ||||||
"instillUIMultiline": true, | ||||||
"instillUIOrder": 0, | ||||||
"instillUpstreamTypes": [ | ||||||
"value", | ||||||
"reference", | ||||||
"template" | ||||||
], | ||||||
"items": {}, | ||||||
"required": [], | ||||||
"title": "Arrays", | ||||||
"type": "array" | ||||||
} | ||||||
}, | ||||||
"required": [ | ||||||
"arrays" | ||||||
], | ||||||
"title": "Input", | ||||||
"type": "object" | ||||||
}, | ||||||
"output": { | ||||||
"description": "Output", | ||||||
"instillEditOnNodeFields": [ | ||||||
"array" | ||||||
], | ||||||
"instillUIOrder": 0, | ||||||
"properties": { | ||||||
"array": { | ||||||
"description": "The union set.", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a typo, right?
Suggested change
|
||||||
"instillEditOnNodeFields": [], | ||||||
"instillFormat": "array:*", | ||||||
"instillUIOrder": 0, | ||||||
"required": [], | ||||||
"title": "Array", | ||||||
"type": "array" | ||||||
} | ||||||
}, | ||||||
"required": [ | ||||||
"array" | ||||||
], | ||||||
"title": "Output", | ||||||
"type": "object" | ||||||
} | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//go:generate compogen readme ./config ./README.mdx | ||
//go:generate compogen readme ./config ./README.mdx --extraContents bottom=.compogen/bottom.mdx | ||
package collection | ||
|
||
import ( | ||
|
@@ -23,6 +23,7 @@ const ( | |
taskIntersection = "TASK_INTERSECTION" | ||
taskDifference = "TASK_DIFFERENCE" | ||
taskAppend = "TASK_APPEND" | ||
taskConcat = "TASK_CONCAT" | ||
) | ||
|
||
var ( | ||
|
@@ -73,6 +74,8 @@ func (c *component) CreateExecution(x base.ComponentExecution) (base.IExecution, | |
e.execute = e.difference | ||
case taskAppend: | ||
e.execute = e.append | ||
case taskConcat: | ||
e.execute = e.concat | ||
default: | ||
return nil, errmsg.AddMessage( | ||
fmt.Errorf("not supported task: %s", x.Task), | ||
|
@@ -82,6 +85,19 @@ func (c *component) CreateExecution(x base.ComponentExecution) (base.IExecution, | |
return e, nil | ||
} | ||
|
||
func (e *execution) concat(in *structpb.Struct) (*structpb.Struct, error) { | ||
arrays := in.Fields["arrays"].GetListValue().Values | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: unit-testing this component would be great 🙏 |
||
concat := &structpb.ListValue{Values: []*structpb.Value{}} | ||
|
||
for _, a := range arrays { | ||
concat.Values = append(concat.Values, a.GetListValue().Values...) | ||
} | ||
|
||
out := &structpb.Struct{Fields: make(map[string]*structpb.Value)} | ||
out.Fields["array"] = structpb.NewListValue(concat) | ||
return out, nil | ||
} | ||
|
||
func (e *execution) union(in *structpb.Struct) (*structpb.Struct, error) { | ||
sets := in.Fields["sets"].GetListValue().Values | ||
cache := [][]string{} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in another PR, instead of adding newlines we should put that in the
compogen
template. This is a workaround and contributors (myself included) don't need to know about this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remove
-
in compogen when there is extra content