mstrio > modeling > expression > expression¶
- class mstrio.modeling.expression.expression.Expression(text=None, tokens=None, tree=None)¶
Bases:
Dictable
Class representation of Expression.
A generic specification for a calculation stored within a metadata object. The expression is represented as a tree over nodes. Most internal nodes (called operator nodes) are defined by applying a function to the operator’s child nodes.
Usually an expression must be non-empty. But in a few cases, most notably a filter expression it is valid for an expression to contain no nodes at all. An expression is empty if and only if it does not have a tree property.
Alternatively the client may prefer to handle an expression as a list of tokens. Each token represents part of the raw text of the expression, in some cases annotated with additional information.
- Parameters:
text (str | None) –
tokens (list[Token] | None) –
tree (ExpressionNode | None) –
- text¶
Read only. Human-readable description of the expression. It is generated from the current specification of the expression.
- Type:
str | None
- tokens¶
Optional list, used if the expression is to be presented as a stream of tokens.
- Type:
list[Token] | None
- tree¶
Representation of an expression as a tree of nodes, instance of one of classes inheriting from ExpressionNode class
- Type:
ExpressionNode | None
- classmethod bulk_from_dict(source_list, connection=None, to_snake_case=True, with_missing_value=False)¶
Creates multiple objects from a list of dictionaries. For each dictionary provided the keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in the object’s _FROM_DICT_MAP.
- Parameters:
cls (T) – Class (type) of the objects that should be created.
source_list (List[Dict[str, Any]]) – A list of dictionaries from which the objects will be constructed.
connection (Connection, optional) – A MSTR Connection object. Defaults to None.
to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.
with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.
- Returns:
A list of objects of type T.
- Return type:
T
- classmethod from_dict(source, connection=None, to_snake_case=True, with_missing_value=False)¶
Creates an object from a dictionary. The dictionary’s keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in _FROM_DICT_MAP.
- Parameters:
cls (T) – Class (type) of an object that should be created.
source (Dict[str, Any]) – A dictionary from which an object will be constructed.
connection (Connection, optional) – A MSTR Connection object. Defaults to None.
to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.
with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.
- Returns:
An object of type T.
- Return type:
T
- to_dict(camel_case=True)¶
Converts an object to a dictionary excluding object’s private properties. When converting the object to a dictionary, the object’s attributes become the dictionary’s keys and are in camel case by default Attribute values stored as objects are automatically converted to non-/ primitive data structures.
- Parameters:
camel_case (bool, optional) – Set to True if attribute names should be converted from snake case to camel case. Defaults to True.
- Returns:
- A dictionary representation of object’s attributes and values.
By default, the dictionary keys are in camel case.
- Return type:
dict
- text: str | None = None¶
- tree: ExpressionNode | None = None¶
- class mstrio.modeling.expression.expression.ExpressionNode(*, expression_type=None, dimty_type=None, dependence_type=None)¶
Bases:
Dictable
Base class representing a node of an expression tree.
- Parameters:
expression_type (ExpressionType | None) –
dimty_type (DimtyType | None) –
dependence_type (DependenceType | None) –
- classmethod bulk_from_dict(source_list, connection=None, to_snake_case=True, with_missing_value=False)¶
Creates multiple objects from a list of dictionaries. For each dictionary provided the keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in the object’s _FROM_DICT_MAP.
- Parameters:
cls (T) – Class (type) of the objects that should be created.
source_list (List[Dict[str, Any]]) – A list of dictionaries from which the objects will be constructed.
connection (Connection, optional) – A MSTR Connection object. Defaults to None.
to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.
with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.
- Returns:
A list of objects of type T.
- Return type:
T
- static dispatch(source, connection=None)¶
Method dispatching node data to appropriate class that represents this type of node.
- Parameters:
connection (Connection | None) –
- Return type:
type[’ExpressionNode’]
- classmethod from_dict(source, connection=None, to_snake_case=True, with_missing_value=False)¶
Creates an object from a dictionary. The dictionary’s keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in _FROM_DICT_MAP.
- Parameters:
cls (T) – Class (type) of an object that should be created.
source (Dict[str, Any]) – A dictionary from which an object will be constructed.
connection (Connection, optional) – A MSTR Connection object. Defaults to None.
to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.
with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.
- Returns:
An object of type T.
- Return type:
T
- to_dict(camel_case=True)¶
Converts an object to a dictionary excluding object’s private properties. When converting the object to a dictionary, the object’s attributes become the dictionary’s keys and are in camel case by default Attribute values stored as objects are automatically converted to non-/ primitive data structures.
- Parameters:
camel_case (bool, optional) – Set to True if attribute names should be converted from snake case to camel case. Defaults to True.
- Returns:
- A dictionary representation of object’s attributes and values.
By default, the dictionary keys are in camel case.
- Return type:
dict
- dependence_type: DependenceType | None = None¶
- expression_type: ExpressionType | None = None¶
- class mstrio.modeling.expression.expression.Token(value, type=None, target=None, attribute_form=None, level=None, state=None)¶
Bases:
Dictable
Class representation of a single tokens of an expression.
- Parameters:
value (str) –
type (Type | None) –
target (SchemaObjectReference | None) –
attribute_form (str | None) –
level (Level | None) –
state (State | None) –
- value¶
The raw text represented by a token
- Type:
str
- target¶
If the token represents an object, provide information about the object
- Type:
SchemaObjectReference | None
- attribute_form¶
If the token represents an attribute form in the context of an object (say City@DESC) then provide attribute form id
- Type:
str | None
- enum Level(value)¶
Bases:
AutoName
Enumeration constant describing the amount of processing performed on a parser token
Valid values are as follows:
- CLIENT = Level.CLIENT¶
- LEXED = Level.LEXED¶
- RESOLVED = Level.RESOLVED¶
- PARSED = Level.PARSED¶
- enum State(value)¶
Bases:
AutoName
Enumeration constant describing whether token in an error or not
Valid values are as follows:
- ERROR = State.ERROR¶
- INITIAL = State.INITIAL¶
- OKAY = State.OKAY¶
- enum Type(value)¶
Bases:
AutoName
Enumeration constant that classifies the text within a token
Valid values are as follows:
- END_OF_TEXT = Type.END_OF_TEXT¶
- ERROR = Type.ERROR¶
- UNKNOWN = Type.UNKNOWN¶
- EMPTY = Type.EMPTY¶
- CHARACTER = Type.CHARACTER¶
- LITERAL = Type.LITERAL¶
- IDENTIFIER = Type.IDENTIFIER¶
- STRING_LITERAL = Type.STRING_LITERAL¶
- INTEGER = Type.INTEGER¶
- FLOAT = Type.FLOAT¶
- BOOLEAN = Type.BOOLEAN¶
- GUID = Type.GUID¶
- OBJECT_REFERENCE = Type.OBJECT_REFERENCE¶
- COLUMN_REFERENCE = Type.COLUMN_REFERENCE¶
- OBJECT_AT_FORM = Type.OBJECT_AT_FORM¶
- FUNCTION = Type.FUNCTION¶
- KEYWORD = Type.KEYWORD¶
- OTHER = Type.OTHER¶
- ELEMENTS = Type.ELEMENTS¶
- DATE_TIME = Type.DATE_TIME¶
- classmethod bulk_from_dict(source_list, connection=None, to_snake_case=True, with_missing_value=False)¶
Creates multiple objects from a list of dictionaries. For each dictionary provided the keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in the object’s _FROM_DICT_MAP.
- Parameters:
cls (T) – Class (type) of the objects that should be created.
source_list (List[Dict[str, Any]]) – A list of dictionaries from which the objects will be constructed.
connection (Connection, optional) – A MSTR Connection object. Defaults to None.
to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.
with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.
- Returns:
A list of objects of type T.
- Return type:
T
- classmethod from_dict(source, connection=None, to_snake_case=True)¶
Creates an object from a dictionary. The dictionary’s keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in _FROM_DICT_MAP.
- Parameters:
cls (T) – Class (type) of an object that should be created.
source (Dict[str, Any]) – A dictionary from which an object will be constructed.
connection (Connection, optional) – A MSTR Connection object. Defaults to None.
to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.
with_missing_value – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.
- Returns:
An object of type T.
- Return type:
T
- to_dict(camel_case=True)¶
Converts an object to a dictionary excluding object’s private properties. When converting the object to a dictionary, the object’s attributes become the dictionary’s keys and are in camel case by default Attribute values stored as objects are automatically converted to non-/ primitive data structures.
- Parameters:
camel_case (bool, optional) – Set to True if attribute names should be converted from snake case to camel case. Defaults to True.
- Returns:
- A dictionary representation of object’s attributes and values.
By default, the dictionary keys are in camel case.
- Return type:
dict
- attribute_form: str | None = None¶
- target: SchemaObjectReference | None = None¶
- value: str¶
- mstrio.modeling.expression.expression.list_functions(connection, name=None, to_dictionary=False, search_pattern=SearchPattern.CONTAINS, project_id=None, project_name=None, limit=None, **filters)¶
Get list of SchemaObjectReference objects or dicts representing functions. Optionally filter functions by specifying ‘name’.
When attribute is: function for Operator node is set to Function.CUSTOM or Function.THIRD_PARTY, custom_function attribute is required. This function give list of SchemaObjectReference object that can be used as values for custom_function.
Optionally use to_dictionary to choose output format.
- Wildcards available for ‘name’:
? - any character * - 0 or more of any characters e.g. name_begins = ?onny will return Sonny and Tonny
Specify either project_id or project_name. When project_id is provided (not None), project_name is omitted.
Note
When project_id is None and project_name is None, then its value is overwritten by project_id from connection object.
- Parameters:
connection (Connection) – Strategy One connection object returned by connection.Connection()
name (string, optional) – value the search pattern is set to, which will be applied to the names of functions being searched
to_dictionary (bool, optional) – If True returns dict, by default (False) returns SchemaObjectReference objects
search_pattern (SearchPattern enum or int, optional) – pattern to search for, such as Begin With or Exactly. Possible values are available in ENUM mstrio.object_management.SearchPattern. Default value is CONTAINS (4).
project_id (string, optional) – Project ID
project_name (string, optional) – Project name
limit (integer, optional) – limit the number of elements returned. If None all object are returned.
**filters –
Available filter parameters: id str: Attribute’s id name str: Attribute’s name date_created str: format: 2001-01-02T20:48:05.000+0000 date_modified str: format: 2001-01-02T20:48:05.000+0000 version str: function’s version owner dict: e.g. {‘id’: <user’s id>, ‘name’: <user’s name>},
with one or both of the keys: id, name
acg str | int: access control group
- Returns:
list with SchemaObjectReference objects or list of dictionaries
- Return type:
list[’SchemaObjectReference’] | list[dict]