project-flogo / core

Flogo Core is the core flogo library used create and extend Flogo applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

support array mapping

lixingwang opened this issue · comments

Current behavior:
Now we do not have array mapping support.
Expected behavior:
Support array mapping by iterating over a source array

We have a first version after discussing over with @mellistibco @fm-tibco @vijaynalawade

"input" {
    
    "val" : {
        "a" : "=$activity[blah].out",
        "addresses": {
            "@foreach[$activity[blah].out2]":
            {
              "street"  : "=$.street",
              "zipcode" : "=$.zipcode",
              "state"   : "=$.state"
            }
        }
    }
}

addresses is an array node, which iterator over source array $activity[blah].out2.
The mapping "street" : "=$.street", indicate we get street value from source array $activity[blah].out2 and set to target addresses.street Same with zipcode and state.

BTW, the target array feilds value might also comes from literal or upstream activities's output.

"input" {
    
    "val" : {
        "a" : "=$activity[blah].out",
        "addresses": {
            "@foreach[$activity[blah].out2]":
            {
              "street"  : "=$.street",
              "zipcode" : "9999",
              "state"   : "=$activity[test].state"
            }
        }
    }
}

@debovema any thoughts? Please give your inputs.

Hi,

The syntax is quite easy to understand.

Do you plan to support nested loops ? If yes, maybe a system of temporary variable would be useful.

@debovema
Yes we support nested loops and we had another round discussion, here is the example:

"input": {
    
    "val" : {
        "a" : "=$activity[blah].out",
        "addresses": {
            "@foreach($activity[blah].out2, i)":
            {
              "street"  : "=$.street",
              "zipcode" : "9999",
              "state"   : "=$activity[test].state",
              "addresses2": {
                  "@foreach($.addresses2)":{
                        "street2"  : "=$loop[i].street2",
                        "zipcode2" : "=$.zipcode",
                        "state2"   : "=$activity[test].state"
                  }
              }
            }
        }
    }
}

We added second param index where the index variable is as optional, it can be accessed by using loop resolver($loop[index]). Index also can be taken as each loop name.

Where $. references the current scope ( the current loop ), you can access a particular loop using $loop[i]

Take a look and let us know your thoughts?

LGTM. I really like the introduction of a loop resolver.

thanks, @debovema , the ideas from @fm-tibco, thanks @fm-tibco