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

CMA output name changes for an array #82

Open
hailiangzhang opened this issue Jan 4, 2022 · 2 comments
Open

CMA output name changes for an array #82

hailiangzhang opened this issue Jan 4, 2022 · 2 comments

Comments

@hailiangzhang
Copy link

hailiangzhang commented Jan 4, 2022

We ran into a situation where different lambda functions from the same workflow coming from different component versions with different schema.

One solution is to change the names using CMA as following,

"task_config": {
  "cumulus_message": {
      "outputs": [
        {
          "source": "{$.payload.granules[0].files[0].filepath}",
          "destination": "{$.payload.granules[0].files[0].key}}"
        },
        {
          "source": "{$.payload.granules[0].files[1].filepath}",
          "destination": "{$.payload.granules[0].files[1].key}}"
        },
        {
          "source": "{$.payload.granules[1].files[0].filepath}",
          "destination": "{$.payload.granules[1].files[0].key}}"
        },
        {
          "source": "{$.payload.granules[1].files[1].filepath}",
          "destination": "{$.payload.granules[1].files[1].key}}"
        }
      ]
    }
}

However, as shown above, since this name change involves multiple array items, we have to write a long list to iterate through them. More importantly, the array size which can only be determined at run-time, and the above solution will not work.

Regarding this, I noticed that array support is indeed implemented in CMA input:

  "task_config": {
    "inlinestr": "prefix{meta.foo}suffix",
    "array": "{[$.meta.foo]}",
    "object": "{$.meta}"
  },

and by looking into the CMA source code, I found that actually the array is resolved based on jsonpath, and therefore the following will also work:

    "array": "{[$.meta.array[*].foo]}",

however, it's only implemented in the input, but not for output name changes.

So, it will be nice (and symmetric) if the jsonpath-based name changes can be implemented in output, so that the above long task config can be written as following to make it short and dynamic:

"task_config": {
  "cumulus_message": {
      "outputs": [
        {
          "source": "{[$.payload.granules[*].files[*].filepath]}",
          "destination": "{[$.payload.granules[*].files[*].key}]}"
        }
      ]
    }
}
@hailiangzhang
Copy link
Author

hailiangzhang commented Jan 4, 2022

I have implemented this in my fork from CMA, and will send a PR soon.

@hailiangzhang
Copy link
Author

Sorry forgot to mention that PR was sent out.

etcart added a commit that referenced this issue Jul 5, 2023
* feat: initial commit from an ad-hoc fix

* feat: seperate list and single value assignment

* feat: assign_json_path_values method parameter changed

* feat: function parameter change

* feat: lint util.py

* feat: comments added

* fix: remove unused print

* feat: Collect array info from jspath

* fix: change condition when assign_json_path_values is invoked

* feat: assign_json_path_values further implemented

* feat: further implemented assign_json_path_value

* feat: assign_json_path_values further implemented

* feat: assign_json_path_values further implemented

* feat: assign_json_path_values cleaned

* feat: assign_json_path_values cleaned

* feat: assign_json_path_values cleaned

* feat: assign_json_path_values cleaned

* feat: more comments added

* feat: more comments added

* feat: more comments added

* fix: bug fix

* feat: Update implemented in assign_json_path_values

* feat: code cleaning

* feat: method parameter changes

* feat: black util.py

* feat: clean up Split source and destination jsonpath by their array components

* feat: clean up Split source and destination jsonpath by their array components

* feat: further code minor cleaning

* feat: further code minor cleaning

* feat: further code minor cleaning

* feat: further code cleaning

* feat: further code cleaning

* doc: method comments added

* fix: lint the code

* test: jsonpath_array test added

* fix: +jsonpath-ng upgraded to 1.5.3

* test: fix test cases for array mapping

* test: test case polished

* doc: comments polished

* doc: lint

---------

Co-authored-by: Hailiang Zhang <[email protected]>
Co-authored-by: Jonathan Kovarik <[email protected]>
Co-authored-by: etcart <[email protected]>
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