Skip to content

Appendix

Additional Functions

There are several useful functions that are not part of SDK. These functions are documented here.

Functions for Signals and Dynamic Facts

Function Description Example
SendSignal Send a signal to all nodes. This is used for synchronization. Golang: u.SendSignal("ready")
Python: self.hh.SendSignal("set")
WaitSignals Wait for a signal to be sent. This is used for synchronization. Golang: u.WaitSignal("ready")
Python: self.hh.WaitSignal("set")
DynFactSet Send information to other nodes in a process. Golang: global := map[string]float64{"first": 0.005, "second": -0.001 }
u.DynFactSet("myFact", global).
Python: global = {"first": 0.005, "second": -0.001 }
self.hh.DynFactSet({"myFact": global})
DynFactGet Get information from other nodes in a process. Waits for the information to be sent. Golang: global := u.DynFactGet("myFact").
Python: global = self.hh.DynFactGet("myFact")
DynFactGobSet Send information to other Golang nodes in a process in GOB format. Useful if the structure of the data is complex. Remember to capitalize all of the structure elements. x := complexStruct{...}
u.DynFactGobSet("myGob", x)
DynFactGobGet Get information in GOB format from other Golang nodes in a process. Waits for the information to be sent. x := complexStruct{}
u.DynFactGobGet("myGob", &x)

Functions for Dates in Golang

Note that there are numerous other functions available for date and datetime processing built into Golang. These functions fill in gaps in those modules.

Function Description Example
ParseDate Parse a string containing date. Can be any one of the following formats dd/mm/yyyy, dd-mm-yyyy, Q1 yyyy, SAS date, or Excel Date. date, err := types.ParseDate("01mar2020")
date2, err := types.ParseDate("2/1/2006")
DateAdd Add a number of intervals to a date. The number of intervals can be negative. See the SQL dateadd() functions for details on optional arguments. date = u.DateAdd("month", 1, date)
DateDiff Find the number of intervals between two dates. diff := u.DateDiff("month", date1, date2)

Groupkey Functions

Function Description Golang Python
FirstGroupKey A boolean function that returns true if the current observation is the first in the group and false otherwise. u.FirstGroupKey(input,"key") input.FirstGroupKey("key" )
LastGroupKey A boolean function that returns true if the current observation is the last in the group and false otherwise. u.LastGroupKey(input,"key") input.LastGroupKey( "key" )
RewindGroup Rewinds the group so the next observation send to the worker is the first in the group. u.RewindGroup(input,"key") input.RewindGroup("key")
PassGroup Returns the number of times a rewind of the group has occurred. u.PassGroup(input,"key") input.PassGroup("key")
SortGroup Sort the observations in a group by a variable. u.SortGroup(input, "Value", "key") input.SortGroup("date", "key")

All of these functions take the name of the Group Key as an optional argument. If no key argument is specified, then the first Group Key is used.

Miscellaneous Functions

Function Description Example
Coalesce Return the first non-missing argument. Golang : frgutil.Coalesce(NaN, NaN, 3)
ConnectMSSQL Get a connection to an MS SQL database. frgutil.ConnectMSSQL will be deprecated soon. Instead, use handle.ConnectMSSQL that takes a path to a key-value store for the database connection.For more information, see Setting up Database Connections Golang: db, err := u.hh.ConnectMSSQL(<vault_path>)
Deprecated:
db, err := frgutil.ConnectMSSQL(u.hh)
ConnectPSQL Get a connection to a Postgres database. frgutil.ConnectPsql will be deprecated soon. Instead, use handle.ConnectPSQL that takes a path to a key-value store for the database connection. For more information, see Setting up Database Connections Golang: db, err := u.hh.ConnectPSQL(<vault_path>)
Deprecated:
db, err := frgutil.ConnectPsql(u.hh)
ComputeStat Compute statistics for the UI. ComputeStat(, " Golang: u.ComputeStat("mean", "value", input.Value)
Python: self.hh.computeStat( "min", "value", input.Value)
CopyFile Copy a file on the file system. Golang: err = CopyFile(filePath, filePathDest)
EndJob Used to terminate a process run from a node. Usually executed after an error. Golang: frgutil.EndJob(u.hh)
Python: self.hh.EndJob()
EvalExpr Evaluate an expression in Golang code that is stored in a string. Compiling is done at runtime. Golang: ans, err := u.EvalExpr(input, "value1 + sqrt(value2)")
ExpandVars Used to expand substitution variables in strings. Golang: where := frgutil.ExpandVars(u.hh, "${var.myVar} or ${op.cat1.cat2.otherVar}")
FromMap Convert a Golang map[string]interface{} to a structure. Only fills in the provided values from the map. Golang: var myStruct MyStruct
ans, err := frgutil.FromMap(m, myStruct)
finalStruct := ans.(MyStruct)
Python: MyStruct(**myStruct)
FromMapFloat Convert a Golang map[string]float64 to a structure. Only fills in the provided values from the map. Golang: var myStruct MyStruct
ans, err := frgutil.FromMapFloat(mFloat, myStruct)
finalStruct := ans.(MyStruct)
Python: MyStruct(**myStruct)
GetInputDataPath Get the input directory path for the current run. Golang: inputDir := frgutil.GetInputDataPath(u.hh, "myTable")
Python: path = self.hh.options['PlaypenRoot']
GetModelUnitTest Used to get the model for a model unit test. Golang: u.model, err = frgutil.GetModelUnitTest(u.hh)
Python: self.model = framework.ReadModelByID(self.hh.options['JobOptions']['system']['modelunittestid'])
GetNumThreads Get the number of threads set for the node. Golang: threadNum := frgutil.GetNumThreads(u.hh, "")
Python: path = self.hh.GetNumThreads()
GetOutputDataPath Get the output directory path for the current run. Golang: outputDir := frgutil.GetOutputDataPath(u.hh, "", false)
Python: path = self.hh.options['JobOptions']['system']['output']['path']
GetRunID Get the run ID/SK for the current run. Golang: runID := frgutil.GetRunID(u.hh)
Python: runID = self.hh.options["RunID"]
IsNull Test a value for missing. Argument can be character or numeric. Golang : if frgutil.IsNull(input.foo) {
RunModelUnitTest Used to run a model for a model unit test. Golang: err := frgutil.RunModelUnitTest(u.model, input, u.Modeloutput)
Python: obs = input.__dict__
self.model.Model.model( obs )
ToMap Convert a Golang structure to a map[string]interface{}. If converting input queue structures use the "protobuf" value for the second value otherwise use "". Golang: obs, _ := frgutil.ToMap(input, "protobuf")
Python: obs = input.__dict__