Skip to content

Commit

Permalink
Improve support for labeled arrays in experimental array processes (#317
Browse files Browse the repository at this point in the history
)

* Better support for labeled arrays in array processes that previously discarded them. Should help with #233.

* Update proposals/array_append.json

* Throw an error when labels exist in both arrays.
  • Loading branch information
m-mohr committed Jan 12, 2022
1 parent 5aa2da1 commit d5be1a5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Added better support for labeled arrays. Labels are not discarded in all cases anymore. Affected processes:
- `array_append`
- `array_concat`
- `array_modify`
- Moved the `text_` processes to proposals as they are lacking implementations.
- Renamed `text_merge` to `text_concat` for better alignment with `array_concat`.

Expand Down
39 changes: 20 additions & 19 deletions proposals/array_append.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "array_append",
"summary": "Append a value to an array",
"description": "Appends a value to the end of the array. Array labels get discarded from the array.",
"description": "Appends a new value to the end of the array, which may also include a new label for labeled arrays.",
"categories": [
"arrays"
],
Expand All @@ -23,6 +23,18 @@
"schema": {
"description": "Any data type is allowed."
}
},
{
"name": "label",
"description": "If the given array is a labeled array, a new label for the new value should be given. If not given or `null`, the array index as string is used as the label. If in any case the label exists, a `LabelExists` exception is thrown.",
"optional": true,
"default": null,
"schema": {
"type": [
"string",
"null"
]
}
}
],
"returns": {
Expand All @@ -34,6 +46,11 @@
}
}
},
"exceptions": {
"LabelExists": {
"message": "An array element with the specified label already exists."
}
},
"examples": [
{
"arguments": {
Expand All @@ -49,21 +66,5 @@
3
]
}
],
"process_graph": {
"append": {
"process_id": "array_concat",
"arguments": {
"array1": {
"from_parameter": "data"
},
"array2": [
{
"from_parameter": "value"
}
]
},
"result": true
}
}
}
]
}
9 changes: 7 additions & 2 deletions proposals/array_concat.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "array_concat",
"summary": "Merge two arrays",
"description": "Concatenates two arrays into a single array by appending the second array to the first array. Array labels get discarded from both arrays before merging.",
"description": "Concatenates two arrays into a single array by appending the second array to the first array.\n\nArray labels are kept only if both given arrays are labeled. Otherwise, the labels get discarded from both arrays. The process fails with an `ArrayLabelConflict` exception if a label is present in both arrays. Conflicts must be resolved beforehand.",
"categories": [
"arrays"
],
Expand Down Expand Up @@ -37,6 +37,11 @@
}
}
},
"exceptions": {
"ArrayLabelConflict": {
"message": "At least one label exists in both arrays and the conflict must be resolved before."
}
},
"examples": [
{
"description": "Concatenates two arrays containing different data type.",
Expand All @@ -58,4 +63,4 @@
]
}
]
}
}
5 changes: 4 additions & 1 deletion proposals/array_modify.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "array_modify",
"summary": "Change the content of an array (remove, insert, update)",
"description": "Modify an array by removing, inserting or updating elements. Updating can be seen as removing elements followed by inserting new elements (not necessarily the same number).\n\nAll labels get discarded and the array indices are always a sequence of numbers with the step size of 1 and starting at 0.",
"description": "Modify an array by removing, inserting or updating elements. Updating can be seen as removing elements followed by inserting new elements (not necessarily the same number).\n\nArray labels are kept only if both arrays given in `data` and `values` are labeled or one of them is empty. Otherwise, all labels get discarded and the array indices are a sequence of numbers with the step size of 1 and starting at 0. The process fails with an `ArrayLabelConflict` exception if a label is present in both arrays.",
"categories": [
"arrays"
],
Expand Down Expand Up @@ -58,6 +58,9 @@
"exceptions": {
"ArrayElementNotAvailable": {
"message": "The array can't be modified as the given index is larger than the number of elements in the array."
},
"ArrayLabelConflict": {
"message": "At least one label exists in both arrays and the conflict must be resolved before."
}
},
"examples": [
Expand Down

0 comments on commit d5be1a5

Please sign in to comment.