User defined DTL functions
AnsweredPossibility to write own DTL functions to perform repetitive complex tasks.
- a function should have a name, one ore more parameters and return exactly one value.
- function visibility should be node wide
- function definitions should be exported along with node metadata
- any legal DTL statements should be legal in function body
Why do we need it:
Often we need to perform the same operation in may different pipes in a node and such operations may require many lines of code to be written. When requirements changes we need to rewrite a piece of code in many pipes which is more error prone than reuse the same code snippet each place we need.
As example (from requirements): "It is important to ensure that special characters do not break the import of the data in the receiving system. To avoid this the following characters in the ID is replaced by hypen (-): ` \ / ? ( ) { } [ ] = > * & ' < + ~ " ^ | ."
It require us to write about 45 lines of code in each pipe where this rule need to be applied
It would be much easier to write it only once and use as a function each place we need.
-
Official comment
In general we want the pipe to be self-contained. We do not want to introduce the complexity of maintain external logic outside of the pipe itself at this time. It would require a policy for how to deal with the versioning of such a library of functions.
In this specific it's pretty clear that we could make a change to the replace function to solve the verbosity problem, i.e. function could take a dict as an input parameter. So in general we prefer making our built-in function richer.
Comment actions
Please sign in to leave a comment.
Comments
1 comment