0
package play


exists(obj, a) {
   obj[a]
}


hello {
     exists(input, "department")
     contains(input["location"], "London")
}

world {        
    contains(input["location"], "London")
    exists(input, "department")    
}

input = { "department": "Eng", "location": "London" }

Above code matches only hello. Why world does not match even when the conditions are same, but order reversed ?

Anoop
  • 1,757
  • 1
  • 19
  • 24

1 Answers1

2

The order of the statements does not matter. You've actually found a bug!

If you change the example slightly so that exists is not called with input as the first argument but instead something like exists(input.user, "department") and then you update the input document to reflect that:

{"user": {"department": "Eng", "location": "London"}}

You'll observe the correct behaviour (e.g., world { contains(input.user["location"], "London"); exists(input.user, "department") }).

tsandall
  • 1,544
  • 8
  • 8
  • Thanks. Any other solutions possible (other than nesting object inside "user") ? When will the bug be addressed ? We can update and retest. – Anoop Feb 10 '20 at 13:47
  • The bug should get resolved in the next few days. Keep an eye out for 0.17.2. – tsandall Feb 12 '20 at 18:45