Skip to content

Belated Expression Workflow Changes#27

Draft
mfleader wants to merge 8 commits intomainfrom
expression-fixes
Draft

Belated Expression Workflow Changes#27
mfleader wants to merge 8 commits intomainfrom
expression-fixes

Conversation

@mfleader
Copy link
Copy Markdown
Member

@mfleader mfleader commented May 3, 2024

Changes introduced with this PR

Make changes that converge the expressions example towards the other examples.


By contributing to this repository, I agree to the contribution guidelines.

@mfleader mfleader self-assigned this May 3, 2024
@mfleader mfleader requested a review from dustinblack May 3, 2024 20:19
webbnh

This comment was marked as resolved.

Copy link
Copy Markdown

@dbutenhof dbutenhof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like Webb, I'm not comfortable with the specific container label. This implies an outstanding task of making sure we formally track references like this and keep them up-to-date...

@dustinblack
Copy link
Copy Markdown
Member

dustinblack commented May 8, 2024

There are several problems with this example workflow, most of which apply to the original commit rather than this PR's changes. I've made notes inline, but as an additional point I think the README needs to be expanded. I know there is a link to the proper documentation for expressions there, but example workflows, especially the basic ones, should provide self-contained knowledge for the new user. It is completely unclear in the README how I use this feature.

steps.example.cancelled-->steps.example.crashed
steps.example.crashed-->steps.example.crashed.error
%% Mermaid end
```
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the mermaid chart of only the subworkflow. Since we are using a foreach here, it may make sense to include the charts for both the inner and outer workflows.

It's troublesome that both the parent and the subworkflow use the step name example, and I really think that should be changed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the parent workflow

@mfleader
Copy link
Copy Markdown
Member Author

mfleader commented May 8, 2024

There are several problems with this example workflow, most of which apply to the original commit rather than this PR's changes. I've made notes inline, but as an additional point I think the README needs to be expanded. I know there is a link to the proper documentation for expressions there, but example workflows, especially the basic ones, should provide self-contained knowledge for the new user. It is completely unclear in the README how I use this feature.

@jaredoconnell I could use some input on what you'd want to see in the expressions example workflow readme.

@mfleader mfleader requested a review from dustinblack May 9, 2024 17:45
@mfleader
Copy link
Copy Markdown
Member Author

mfleader commented May 9, 2024

There are several problems with this example workflow, most of which apply to the original commit rather than this PR's changes. I've made notes inline, but as an additional point I think the README needs to be expanded. I know there is a link to the proper documentation for expressions there, but example workflows, especially the basic ones, should provide self-contained knowledge for the new user. It is completely unclear in the README how I use this feature.

I pulled some of the relevant linked documentation into the workflow's README.

* update workflow with clearer examples and no sub-workflow

* addressing PR feedback

* updates from PR feedback
@dustinblack
Copy link
Copy Markdown
Member

@mfleader I heavily re-worked this myself, and those changes are merged now, so it will be a little self-serving for me to approve the PR at this point. I'd like for you to take another pass at it and make sure we've really covered the feature well now.

@mfleader mfleader dismissed dustinblack’s stale review May 20, 2024 15:22

changes were effectively approved with the merge of @dustinblack's pull request #29

@mfleader mfleader added documentation Improvements or additions to documentation enhancement New feature or request labels May 20, 2024
@mfleader mfleader requested review from dbutenhof, jaredoconnell and webbnh and removed request for dustinblack May 20, 2024 15:22
@jaredoconnell jaredoconnell marked this pull request as draft May 20, 2024 15:34
@jaredoconnell
Copy link
Copy Markdown
Contributor

We would like to keep the existing example, but we will rename it to "quoting". Then this PR will be updated as a new example.

@webbnh
Copy link
Copy Markdown

webbnh commented May 20, 2024

We would like to keep the existing example, but we will rename it to "quoting". Then this PR will be updated as a new example.

This work was completed in PR #30.

Now the branch for this PR needs to be brought up to date with main, which might be slightly challenging, as Git will probably regard the upstream change as deleting the files and the downstream change as modifying them. But, if all else fails, you can just present the downstream files as "new" files (i.e., save them aside, do the pull, and then move them back and add them). (Please do not delete and recreate the branch with the same name -- GitHub tends not to handle that well.)

Copy link
Copy Markdown

@webbnh webbnh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I ran this workflow, and the output doesn't look right:

$ ../../../arcaflow -input input.yaml -config config.yaml -context . 2>&1 | sed -E -e '/^2024/ d' -e '/%% Mermaid/,/%% Mermaid/ d'
workflow.yaml:1:16: invalid char escape
workflow.yaml:1:16: invalid char escape
workflow.yaml:1:16: invalid char literal
output_data:
    message:
        message: |-
            Hello, !expr intToString(floatToInt(intToFloat($.input.int_value) *  $.input.float_value)) + ' User'
            !
    name:
        message: Hello, Arcaflow -- "The Noble Workflow Engine"!
output_id: success

(I took the liberty of filtering out the Mermaid output and the log messages.)

I'm not sure what the three "invalid char" messages are referring to, but, interestingly, they don't stop the run from starting.

And, more interesting than that, the expression in step example2 is being passed through as a literal (including its trailing newline) instead of being evaluated (perhaps as a result of the invalid characters?).

Although, the debug output does include the line,

2024-05-21T17:23:29Z	debug	source=executor	Evaluating expression $.input.name + ' -- \"The Noble Workflow Engine\"'...

so, apparently Arca knows that it's an expression.

If I put the whole expression on the same line as the property tag, then it seems to work as expected, although it still complains about the invalid char (in fact it adds a complaint).

One other curious thing to note: the file seems to be using CR/LF pairs as the line endings. I don't know if that's a problem (or if it's some sort of local setting I've got), but, when the going gets weird, I start looking at everything....

Comment on lines -14 to +37
- name: !expr '"Here''s an apostrophe and \"embedded quotes\"."'
- name: !expr "'Here\\'s an apostrophe and \"embedded quotes\".'"
- name: !expr |-
'Here\'s an apostrophe and "embedded quotes".'
- name: !expr |-
"Here's an apostrophe and \"embedded quotes\"."
- name: !expr '`Here''s an apostrophe and "embedded quotes".`'
- name: !expr |-
`Here's an apostrophe and "embedded quotes".`
example1:
plugin:
deployment_type: image
src: quay.io/arcalot/arcaflow-plugin-template-python:0.4.0
input:
#Expression with concatenation and string literal
name: !expr $.input.name + ' -- \"The Noble Workflow Engine\"'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could someone remind me why we need to escape the double quotes inside a string marked with single quotes? That is, the escapes aren't actually needed, right?

(I guess that \" gets replaced with " so we get the right result, but if we want to demonstrate the application of escape characters when they are actually needed, perhaps the string should be marked with double quotes?)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The escaped double quotes are generating a warning (which doesn't seem to adversely affect the operation of the workflow). There also seems to be a warning (which, again, doesn't seem to have any adverse effect) on the use of the single quotes.

If you replace the single quotes with double quotes, it makes both sets of warnings go away (and, it justifies the escapes...).

Comment on lines +6 to +8
documentation](https://arcalot.io/arcaflow/workflows/expressions/). Arcaflow
expressions are a way to reference paths within the workflow or their fields, and they
additionally allow you to manipulate the data.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The phrase "to reference paths" doesn't seem like it will mean anything to a user. That is, expressions allow a user to reference a piece of data via a path, but the path is a means to an end, not a goal in itself. And, the path should pretty much always end at a field (or a list item). So, I propose rewording this to something like,

Arcaflow expressions provide a way to reference individual data items within the workflow, such as lists, objects, list elements, and object properties, for use in specifying inputs to steps and subworkflows or workflow outputs. In addition, expressions can be used to transform input and output items to produce new data items.

Comment on lines +10 to +12
*Note: Arcaflow expressions were inspired by JSONPath, and may look familar, but
expressions have diverged from the JSONPath syntax to enable a rich feature set that is
specific to Arcaflow.*
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps,

Arcaflow expression syntax was inspired by JSONPath, and may look familiar, but
the syntax has diverged from the JSONPath syntax to enable a rich feature set that is
specific to Arcaflow.

(Note the correction of the spelling of "familiar".)

Comment on lines +20 to +23
## Examples

Basic path references are already used across the other example workflows. These
include references in a step to an input from the schema:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment about path references already being used elsewhere is non-productive (unless we expect that the reader has already seen them or is just about to see them). Instead, let's just say what we want to say, here:

A basic path reference can be used to specify a value from the workload input as the input to a step:

Comment on lines +55 to +57
input:
#Expression with concatenation and string literal
name: !expr $.input.name + ' -- \"The Noble Workflow Engine\"'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment to basic-examples/expressions/workflow.yaml.

Comment on lines +59 to +60

As well as type conversions and math operations:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment refers to a new YAML blob, so replace "As well as" with something like "This workflow demonstrates".

Comment on lines +70 to +75
name: >
!expr intToString(floatToInt(intToFloat($.input.int_value) *
$.input.float_value)) + ' User'
```

In this last expression, the plugin requires a string input. The logical steps here are:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this text refers to the preceding text, unlike all the previous text blobs which have each been referring to examples which follow them, it would be good to explicitly establish the context first, by inserting a phrase like "in the example above" before the comma.

@webbnh
Copy link
Copy Markdown

webbnh commented May 21, 2024

I'm not sure what the three "invalid char" messages are referring to

I got rid of the complaints about the escapes by removing the backslashes from in front of the double quotes in the string....

@webbnh
Copy link
Copy Markdown

webbnh commented May 21, 2024

I'm not sure what the three "invalid char" messages are referring to

I got rid of the complaints about the escapes by removing the backslashes from in front of the double quotes in the string....

Leaving the escapes in place and changing the single quotes to double quotes also addresses the complaints....

@webbnh
Copy link
Copy Markdown

webbnh commented May 21, 2024

the expression in step example2 is being passed through as a literal

I was able to fix this by correcting the position of the !expr tag:

    input:
      # Expression with type conversions, math operation, and concatenation
      name: !expr >
        intToString(floatToInt(intToFloat($.input.int_value) *
        $.input.float_value)) + ' User'

Note that the !expr tag goes on the same line before the >. (Take a look at the examples in the old code.)

@dbutenhof
Copy link
Copy Markdown

I'm not sure what the three "invalid char" messages are referring to

I got rid of the complaints about the escapes by removing the backslashes from in front of the double quotes in the string....

Leaving the escapes in place and changing the single quotes to double quotes also addresses the complaints....

I'm kinda confused here on exactly what's "ARCA" and what's "YAML"? YAML claims not to support escape sequences inside single quotes, meaning ' \"' would be either uninterpreted or illegal (possibly the problem)? But this is all on an !expr "argument", so does that move all the lexing into ARCA/Go domain?

@webbnh
Copy link
Copy Markdown

webbnh commented May 21, 2024

workflow.yaml:1:16: invalid char escape
workflow.yaml:1:16: invalid char escape
workflow.yaml:1:16: invalid char literal

I got rid of the first two warnings by changing the single quotes in example1 to double quotes and leaving the escapes in place. And, I got rid of the third warning by changing the single quotes in example2 to double quotes, as well.

Copy link
Copy Markdown

@webbnh webbnh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just attaching my discoveries to the code.

Comment on lines +42 to +46
input:
# Expression with type conversions, math operation, and concatenation
name: >
!expr intToString(floatToInt(intToFloat($.input.int_value) *
$.input.float_value)) + ' User'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The !expr tag is not part of the data, so it needs to precede the >:

      name: !expr >
        intToString(floatToInt(intToFloat($.input.int_value) * 
        $.input.float_value)) + ' User'

And, the use of single quotes is generating a warning during parsing...but it doesn't seem to adversely affect the operation of the workflow.

Comment on lines -14 to +37
- name: !expr '"Here''s an apostrophe and \"embedded quotes\"."'
- name: !expr "'Here\\'s an apostrophe and \"embedded quotes\".'"
- name: !expr |-
'Here\'s an apostrophe and "embedded quotes".'
- name: !expr |-
"Here's an apostrophe and \"embedded quotes\"."
- name: !expr '`Here''s an apostrophe and "embedded quotes".`'
- name: !expr |-
`Here's an apostrophe and "embedded quotes".`
example1:
plugin:
deployment_type: image
src: quay.io/arcalot/arcaflow-plugin-template-python:0.4.0
input:
#Expression with concatenation and string literal
name: !expr $.input.name + ' -- \"The Noble Workflow Engine\"'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The escaped double quotes are generating a warning (which doesn't seem to adversely affect the operation of the workflow). There also seems to be a warning (which, again, doesn't seem to have any adverse effect) on the use of the single quotes.

If you replace the single quotes with double quotes, it makes both sets of warnings go away (and, it justifies the escapes...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants