Skip to content
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

Clarify how to handle a nested array with inputBinding for all levels #177

Open
tom-tan opened this issue May 16, 2022 · 1 comment
Open

Comments

@tom-tan
Copy link
Member

tom-tan commented May 16, 2022

Related: common-workflow-language/common-workflow-language#783

The spec of CommandLineBinding says:

array: If itemSeparator is specified, add prefix and the join the array into a single string with itemSeparator separating the items. Otherwise first add prefix, then recursively process individual elements.

However, it does not mention how to behave in the case of the combination of itemSeparator and prefix in the different levels.

Current behavior:

  • tests/nested-array-inputBinding.cwl

    cwlVersion: v1.2
    class: CommandLineTool
    
    hints:
        - class: DockerRequirement
          dockerPull: docker.io/python:3-slim
    
    baseCommand: python
    inputs:
        script:
            type: File
            default:
                class: File
                location: args.py # use args.py in the conformance tests
            inputBinding:
                position: -1
        inp1:
            type:
                type: array
                items:
                    type: array
                    items: string
                    inputBinding:
                        prefix: "-p"
            inputBinding:
                itemSeparator: ","
    outputs:
        args: string[]
  • tests/nested-array-inputBinding-job.yml

    inp1: [["foo", "bar", "buzz"], ["hoge", "fuga"]]
  • Result

    $ cwl-runner --quiet tests/nested-array-inputBinding.cwl tests/nested-array-inputBinding-job.yml
    INFO /home/vscode/.local/bin/cwl-runner 3.1.20220502060230
    ...
    {
        "args": [
            "['foo', 'bar', 'buzz'],['hoge', 'fuga']",
            "-p",
            "foo",
            "-p",
            "hoge",
            "-p",
            "bar",
            "-p",
            "fuga",
            "-p",
            "buzz"
        ]
    }

Note: I guess few users write such CWL document but platform developers have to care such cases. I hope we can define this corner case not to make difficult to implement platforms.

@tom-tan
Copy link
Member Author

tom-tan commented May 16, 2022

  • Expected types and its resulted types
    • prefix

      • expected: string or string[]
        • e.g., "str", ["elem1", "elem2", "elem3"]
      • result: string[]
        • e.g., ["-pre", "str"], ["-pre", "elem1", "elem2", "elem3"]
    • itemSeparator

      • expected: string[]
        • e.g., ["elem1", "elem2", "elem3"]
      • result: string
        • e.g., "elem1,elem2,elem3"
    • separate: true

      • expected: string
        • e.g., "str"
      • result: string[]
        • e.g., ["-pre", "str"]
    • separate: false

      • expected: string
        • e.g., "str"
      • result: string
        • e.g., "-prestr"

Points to be clarified

1. (not limited to nested arrays) How to behave prefix and separate: false for array?

For example: ["elem1", "elem2", "elem3"]

Possible behavior

  • prefix is added only to the first element: "-preelem1 elem2 elem3"
    • It causes another problem: how to interpret string[] as string?
  • Same as itemSeparator: "": "-preelem1elem2elem3"
  • Reject when prefix and separate: false are specified at the same time

2. How to behave itemSeparator and prefix for nested array?

For example: [["elem1", "elem2", "elem3"], ["elem"]] with the following declaration:

inp1:
  type:
    type: array
    items:
      type: array
      items: string
      inputBinding:
        prefix: -pre
  inputBinding:
    itemSeparator: ","

By processing inputBinding in the leaf level in the above example, we obtain [["-pre", "elem1", "elem2", "elem3"], ["-pre", "elem"]].

Possible behavior

  • itemSeparator is applied for all the elements. that is: "-pre,elem1,elem2,elem3,-pre,elem"
  • itemSeparator is applied for the first element? "-pre elem1 elem2 elem3,-pre elem"?
    • It causes another problem: how to interpret string[] as string?
  • Reject when inputBinding has itemSeparator and any leaves (including their sub-leaves) specify the case of:
    • separate: true if prefix is specified, and
    • itemSeparator is not specified for arrays

I prefer the last choice for both cases, that is, rejecting such corner cases.
It makes easier to implement platforms and also enables to delay the decision until we know the real use cases for them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant