Calculation
This feature is currently in Private Preview.
- Only available for Realtime Feature Views.
- Set of supported SQL functions is limited and is actively being expanded. See SQL Expression Reference below for details.
- Please reach out to Tecton Support for questions and feedback!
Summary​
TheCalculation
class describes a Calculation feature that is applied to a Realtime Feature View via the features
param.Example
from tecton import Calculation, RealtimeFeatureViewtransaction_counts_fv = RealtimeFeatureView(name="transaction_counts_features",sources=[request_ds, user_transaction_metrics],# mode=None implied...features = [Calculation(name="transaction_count_fill_na",expr="COALESCE(user_transaction_metrics.transaction_count, request_ds.default_count)",),Calculation(name="transaction_count_add_1",expr="user_transaction_metrics.transaction_count + 1",description="a test calculation utilizing addition",tags={"tag": "value"}),],)
Attributes​
Name | Data Type | Description |
---|---|---|
description | Optional[str] | A human-readable description of the feature. |
tags | Optional[Dict[str, str]] | Tags associated with the feature (key-value pairs of user-defined metadata). |
name | str | The name of this feature. Must be explicitly defined. |
expr | str | The calculation string expressing the operations and input operands. |
__init__(...)​
Parameters
description
(Optional
[str
]) - A human-readable description of the feature. Default:None
tags
(Optional
[Dict
[str
,str
]]) - Tags associated with the feature (key-value pairs of user-defined metadata). Default:None
name
(str
) - The name of this feature. Must be explicitly defined. Default:None
expr
(str
) - The calculation string expressing the operations and input operands. Default:None
SQL Expression Reference​
The following SQL functions are currently supported in Calculation
Features:
COALESCE​
COALESCE(value, default_value)
Returns the first non-null value in a list of expressions.
COALESCE(amount, 0)
Comparison Operators​
Standard SQL comparisons are supported.
- Comparisons between
Float32
,Int32
,Float64
,Int64
, andBool
are supported. For example, you can compareTrue
and 1 (True
= 1 returnsTrue
). - If one of the elements is a
String
element, it can only be compared against anotherString
element. Strings are compared using lexicographical order.
amount > threshold
value >= 0
3 != 2
DATEDIFF​
DATEDIFF(datepart, start_date, end_date)
Returns the count of the specified datepart boundaries crossed between two timestamps. All datetimes provided are converted to UTC and all datediffs are performed on the UTC equivalent.
DATEDIFF('minutes', start_time, end_time)
Arithmetic​
Standard SQL arithmetic operations are supported.
amount + 1
amount - value
value * 2
3 / 2
Please note the following:
- For addition, subtraction, and multiplication: the result of arithmetic operation will be the type required to preserve the precision of the inputs. The precision hierarchy is
Float64
->Float32
->Int64
->Int32
. For example, aFloat32
value +Int64
value will return a value of typeFloat32
to preserve the float input's precision. - For division: the result will always be a
Float64
. If division by zero occurs, the result will be+Infinity
as typeFloat64
. - Currently, Realtime Feature Views do not support
Int32
features. As a workaround for your calculations, you can cast yourInt32
value toInt64
usingInt32_value + 0
.