Module: formula

Copyright 2020 Parsable, Inc
API address: /api/formula
Formula contains definitions for the "calculated fields" feature within parsable's template editor. This service contains definitions of operations and expressions; the formulae themselves are on the step.Field object, and calculation results are in the execution stream retrieved via the job service.

ModuleServicesData typesConstants
formulaFormulaService
FieldReference
Formula
FormulaError
FormulaNode
FormulaToken
NodeContent
NumberToken
OpName
OpNotation
OpSignature
Operation
StringToken
Symbol
ValidateResult

Enumerations

Enumeration: OpNotation

Operator Notation defines an operator's lexical classification; often just referred to as a "type" of operator.

None0 no operator for this function; it must be written as a function call eg SUM(x, y, z)
Infix1 the operator appears between two operands; eg X + Y
Prefix2 the operator appears before a single operand; eg -X
Postfix3 the operator appears after its operand; eg X²
Grouping4 the operator groups an expression; eg the parens in (X + Y) * 2
Postcircumfix5 the operator follows a term (presently symbols/function names only) and encloses another term
Separator6 the operator is used to separate arguments in a list

Enumeration: OpName


Add1
Subtract2
Multiply3
Divide4

Type declarations

Typedef: NumberToken

Base type: string

A Number token represents a numeric value input by the user. Depending on what is in this token, it will be an integer or floating point value

Typedef: StringToken

Base type: string

A String token represents a string value in a formula; this can contain any unicode character

Typedef: Symbol

Base type: string

A symbol represents a function name and should match something from the getOperations endpoint

Data structures

Struct: OpSignature

KeyFieldTypeDescriptionRequirednessDefault value
1returnTypefield_data.FieldTypethe return type of the function when called in this way default
2argTypeslist<field_data.FieldType>an acceptable list of argument types default
3varArgsboolthe function can take a variable number of arguments/terms; the final argument can be provided 0 or more times. defaultfalse

An "OpSignature" is one set of valid argument types for a function. eg, for a given set of argument types, it will return the given type. Many functions will have a single signature only. Infix operators will always have two arguments, prefix and postfix always one.

Struct: Operation

KeyFieldTypeDescriptionRequirednessDefault value
1operationNameOpNamedefault
2descriptionstringa short description of the operation eg "add two numbers together" (localized) - intended for tooltips etc default
3notationOpNotationthe "notation" defines where the operator appears in relation to its arguments default
4precedencei32in the absense of parentheses, this indicates the priority of the operator. Lower numbers mean more tightly binding (eg, × has a lower value than +) default-1
5signatureslist<OpSignature>valid types for the arguments and return values of this operation default

An operation is either a function or an operator. An operator may be sent in function style, or it can be sent using its operator name according to its allowable notation. Many facts included here are simple to provide, and while not useful to simple interfaces are invaluable for ones which want to do things like context-aware completion or restriction of arguments to relevant types.

Struct: FieldReference

KeyFieldTypeDescriptionRequirednessDefault value
1fieldTypefield_data.FieldTypethe type of the field, the same as the type on the field.Field default
2fieldClientIdstringin template authoring, this field contains the referenced field using the client Id optional
3fieldIdstringspecifying field by step.Field.id instead. Always set on steps in materialized jobs optional
4fieldTitlestringset on the template version of a formula; this is the title of the input referred to. Broken references retain this value. optional
5stepClientIdstringoptional
6jobBaseStepIdstringoptional
7stepTitlestringset on the template version of a formula with inter-step references; this is the title of the step referred to. Broken references retain this value. optional

Union: FormulaToken

KeyFieldTypeDescriptionRequirednessDefault value
1opOpNamedefault
2numNumberTokendefault
3strStringTokendefault
4refFieldReferencedefault
5symSymboldefault

A formula token is something that can be entered or selected by a user and appear in a formula input box.

Union: NodeContent

KeyFieldTypeDescriptionRequirednessDefault value
1valuefield_data.ExecutionDatathe value is an "immediate" value, and re-uses the type of field execution data default
2fieldRefFieldReferencethe value is a reference to another field's input value default
3operationNameOpNamethe value is a result of calling the named function default

A formula term represents an parameter/argument to a formula function at a particular location.

Struct: FormulaNode

KeyFieldTypeDescriptionRequirednessDefault value
1contentNodeContentthe content of this node - string or reference default
2nodeTypefield_data.FieldTypethe return type of this formula node default
3funcArgslist<FormulaNode>if a function node, the parameters/arguments to the function default

A formula Node is an "Operation Tree" (usually just called OpTree) representation of a formula expression. Valid formulae will have one of these once they are compiled from the list of tokens. Each node represents a single function call or operator, and the result of the entire expression is obtained by recursively evaluating from the deepest node upwards.

Struct: FormulaError

KeyFieldTypeDescriptionRequirednessDefault value
1errorMessagestringlocalized message default
2errorPosi32position in the list of tokens where the error is optional

A formula error contains details of a problem with a formula. It typically indicates the first problem detected, not all possible problems with the formula.

Struct: Formula

KeyFieldTypeDescriptionRequirednessDefault value
1formulaTokenslist<FormulaToken>list of tokens for expression default
2exprFormulaNodecompiled form (set if valid) optional
3errorFormulaErrorlerror description (if not valid) optional

A Formula is the container structure for a formula on a field. You create a formula by sending a list of tokens and attaching it. The response will have expr set if valid, and error set if not valid.

Struct: ValidateResult

KeyFieldTypeDescriptionRequirednessDefault value
1errorFormulaErroroptional


Services

Service: FormulaService

Function: FormulaService.getOperations

list<Operation> getOperations(common.UUID teamId)
    throws common.SystemException
Get a current list of available formula operations. This includes functions and operators. It's generally fixed across all teams, except for functions still in beta testing. You can omit teamId to only get production-ready operations available to everyone.

Function: FormulaService.validateFormula

ValidateResult validateFormula(list<FormulaToken> formulaTokens)
    throws common.SystemException