This page summarises which variables are available in different contexts, and explains how to create and use $-variables. See also Expression Basics.
Which Variables are Available
The following tables gives some guidelines for the availability of variables, based on the PhixFlow Timing Cycle for evaluating Models.
Location of Expression | Available Variables |
---|---|
Input multiplier | Some internal variables (e.g. _toDate) $-variables (i.e. variables declared locally in the Input Multiplier) |
Database collector SQL script | %USERNAME%, %PASSWORD% $-variables |
Output Multiplier | internal variables (e.g. _toDate) $-variables |
Attribute expression | internal variables (e.g. _toDate) All <pipeName> values (e.g. inpipe.accountVal All _out.value where value is the name of the attribute and it is before the current attribute in the stream All user defined variables created in a prior Attribute expression |
Output filter expression | internal variables (e.g. _toDate) All _out.attribute values All user defined variables created in any Attribute expression |
Pipe index expression on a lookup pipe | internal variables <pipename>.attribute - the name on an input pipe All _out.value where value is the name of the attribute and it is before the current attribute in the stream |
Anchor | ||||
---|---|---|---|---|
|
When writing expressions that reference variables it is important to understand whether PhixFlow has "seen" the variable yet. This is the scope of the variable.
In a stream, output multiplier or output filter, the attributes have a specified order. When you run analysis on a model, PhixFlow processes each attribute in order, evaluating their expressions. This means you cannot reference:
- an attribute name before PhixFlow has processed it. So in the first attribute in a stream, you cannot use a value from the third attribute in the stream.
- a $-variable before PhixFlow has processed the expression where it is set.
You can only reference:
- an attribute name in a subsequent attribute
- a $-variable after it has been set or evaluated.
Internal Variables
PhixFlow has a list of functions you can use in an expression; see Internal Variables.
Some commonly-used internal variables are
PhixFlow processes stream attributes in the specified order. Use _out.<attribute_name>
to reference an attribute in the same stream that has already been processed,
if( _out.AppleHarvestDate < toDate('20210101'), 1, 0) | toDate(converts the string 20210101 into a date 01-01-2021) |
if( _out.AppleHarvestDate < toDate('20210101'), 1, 0). Here we see an expression within an expression. toDate(converts the string 20210101 into a date 01-01-2021)
Internal Variables (eg _out.) _out. signals that AppleHarvestDate is being sourced from the same stream as the attribute on which you are writing an expression for and that it has therefore already been calculated. Also frequently used is the name of a pipe that goes into a stream followed by a . eg in.AppleHarvestDate which signals that AppleHarvestDate is being sourced down a pipe going into the stream called 'in'. The internal variable preceding an attribute name should reflect where the attribute is being source from. There are many other internal variables, see Internal Variables.
Regular Expressions - Regular expressions can be used to match patterns within strings or arrays as arguments within jep expressions, for example replaceAll, replaceFirst and matches. See Regexp ToDelete.
Simple integers or strings. In the above case 1 and 0 are simple integers. They tell PhixFlow to return the number 1 if NumberOfApples > 1 and 0 if it is not. A string could be returned instead eg. if(_out.NumberOfApples > 1, 'True', 'False') would return the string True if NumberOfApples >1 and False if it is not. Note strings need to be wrapped in ' marks.
(To find the correct syntax for an expression - find it in the list below or search in confluence)
Creating and Using $-variables
Defining a $-variable
Insert excerpt | ||||
---|---|---|---|---|
|
PhixFlow assumes that you are declaring a variable and setting its value the first time it occurs in the expression.
$localVar = 'Smith' $GlobalVar = 'St.John-Smith'
Using $-Variables in Expressions
Excerpt | ||||||
---|---|---|---|---|---|---|
In expressions that have complex calculations, you may need a variable to hold the result of a calculation. You can then reference the variable later in the expression, or in other attribute expressions for the same stream. The following expression uses do() function and $-variables for a simple calculation.
When to Use $-variables$-variables are not really needed in simple calculations. They are useful:
|
Variable Typing
Anchor | ||||
---|---|---|---|---|
|
When a variable is first used, PhixFlow makes a best guess about what type of data is stored in that variable; see Parameter Types. For example:
Expression | PhixFlow identifies data type |
---|---|
$thisNumber = 4 | integer |
$thisAddress = '123 Fake St' | string |
When PhixFlow has decided what type of data is stored in a variable, you usually cannot change the type. PhixFlow will reject an expression that equates different types, such as:
$thisNumber = $thisAddress
The cases where you may be able to change a data type are
- integer to a floating point value: PhixFlow may be able to convert between these.
- by using type conversion function, such as toDate. This forces a value of one type into a variable of another type.