1
Literal Expression = PurchaseOrders.pledgedDocuments[valuation.value=62500] 

Purchase Order Structure

PurchaseOrders:

[  
   {
      "productId": "PURCHASE_ORDER_FINANCING",
      "pledgedDocuments" : [{"valuation" : {"value" : "62500"} }]
   }
]

The literal Expression produces null result.

However if

PurchaseOrders.pledgedDocuments[valuation = null]

Return all results !

What am I doing wrong ?

enter image description here

user1428716
  • 2,078
  • 2
  • 18
  • 37

1 Answers1

1

I was able to solve using flatten function - but dont know how it worked :(

In your original question, it is not exactly clear to me what is your end-goal, so I will try to provide some references.

value filtering

First, your PurchaseOrders -> pledgedDocuments -> valuation -> value appears to be a string, so in your original question trying to filter by

QUOTE:

... [valuation.value=62500] 

will not help you.

You'll need to filter to something more ~like: valuation.value="62500"

list projection

In your original question, you are projecting on the PurchaseOrders which is a list and accessing pledgedDocuments which again is a list !

So when you do:

QUOTE:

PurchaseOrders.pledgedDocuments (...)

You don't have a simple list; you have a list of lists, it is a list of all the lists of pledged documents.

final solution

I believe what you wanted is:

flatten(PurchaseOrders.pledgedDocuments)[valuation.value="62500"] 

And let's do the exercise on paper about what is actually happening.

First,

Let's focus on PurchaseOrders.pledgedDocuments.

You supply PurchaseOrders which is a LIST of POs, and you project on pledgedDocuments.

What is that intermediate results? Referencing your original question input value for POs, it is:

[  
   [{"valuation" : {"value" : "62500"} }]
]

notice how it is a list of lists?

With the first part of the expression, PurchaseOrders.pledgedDocuments, you have asked: for each PO, give me the list of pledged documents.

By hypothesis, if you supplied 3 POs, and each having 2 documents, you would have obtained with PurchaseOrders.pledgedDocuments a resulting list of again 3 elements, each element actually being a list of 2 elements.

Now,

With flatten(PurchaseOrders.pledgedDocuments) you achieve:

[{"valuation" : {"value" : "62500"} }]

So at this point you have a list containing all documents, regardless of which PO.

Now,

With flatten(PurchaseOrders.pledgedDocuments)[valuation.value="62500"] the complete expression, you still achieve:

[{"valuation" : {"value" : "62500"} }]

Because you have asked on the flattened list, to keep only those elements containing a valuation.value equal to the "62500" string.

In other words iff you have used this expression, what you achieved is:

From any PO, return me the documents having the valuations' value equals to the string 62500, regardless of the PO the document belongs to.

Dharman
  • 30,962
  • 25
  • 85
  • 135
tarilabs
  • 2,178
  • 2
  • 15
  • 23