Skip to main content
Version: Beta 🚧

Calculation

Private Preview

This feature is currently in Private Preview.

This feature has the following limitations:
  • 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!
If you would like to participate in the preview, please file a support ticket.

Summary​

The Calculation class describes a Calculation feature that is applied to a Realtime Feature View via the features param.

Example

from tecton import Calculation, RealtimeFeatureView
transaction_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​

NameData TypeDescription
descriptionOptional[str]A human-readable description of the feature.
tagsOptional[Dict[str, str]]Tags associated with the feature (key-value pairs of user-defined metadata).
namestrThe name of this feature. Must be explicitly defined.
exprstrThe 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, and Bool are supported. For example, you can compare True and 1 (True = 1 returns True).
  • If one of the elements is a String element, it can only be compared against another String 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
info

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, a Float32 value + Int64 value will return a value of type Float32 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 type Float64.
  • Currently, Realtime Feature Views do not support Int32 features. As a workaround for your calculations, you can cast your Int32 value to Int64 using Int32_value + 0.

Was this page helpful?