github.com/viant/toolbox@v0.34.5/data/udf/README.md (about) 1 # Expandable Collection User Defined Function 2 3 ### Usage 4 5 6 #### Data substitution 7 8 ```go 9 10 aMap := data.NewMap(); 11 aMap.Put("ts", "2015-02-11") 12 udf.Register(aMap) 13 expanded := aMap.ExpandAsText(`$FormatTime($ts, "yyyy")`) 14 15 ``` 16 #### Data node selection 17 18 19 ```go 20 21 holder := data.NewMap() 22 collection := data.NewCollection() 23 collection.Push(map[string]interface{}{ 24 "amount": 2, 25 "id":2, 26 "name":"p1", 27 "vendor":"v1", 28 }) 29 collection.Push(map[string]interface{}{ 30 "amount": 12, 31 "id":3, 32 "name":"p2", 33 "vendor":"v2", 34 }) 35 holder.SetValue("node1.obj", collection) 36 37 records, err := Select([]interface{}{"node1/obj/*", "id", "name:product"}, holder) 38 39 40 ``` 41 42 #### The list of defined UDFs 43 44 - Length, Len returns length of slice, map or string 45 - AsMap - convert source into a map, it accepts data structure, or JSON, YAML literal 46 - AsCollection - convert source into a slice, it accepts data structure, or JSON, YAML literal 47 - AsData - convert source into a map or slice, it accepts data structure, or JSON, YAML literal 48 - AsInt - convert source into a an int 49 - AsFloat - convert source into a a float 50 - AsBool - convert source into a boolean 51 - AsNumber - converts to either int or float 52 - FormatTime, takes two arguments, date or now, followed by java style date format 53 - Values - returns map values 54 - Keys - return map keys 55 - IndexOf - returns index of matched slice element 56 - Join - join slice element with supplied separator 57 - Split - split text by separator 58 - Sum - sums values for matched Path, i.e. $Sum('node1/obj/*/amount') 59 - Count - counts values for matched Path, i.e. $Sum('node1/obj/*/amount') 60 - Select - selects attribute for matched path, i.e $Select("node1/obj/*", "id", "name:product") 61 - QueryEscape - url escape 62 - QueryUnescape - url unescape 63 - Base64Encode 64 - Base64DecodeText 65 - TrimSpace 66 - Elapsed elapsed time 67 - Rand 68 - Replace 69 - ToLower 70 - ToUpper 71 - AsNewLineDelimitedJSON