Skip to main content
Version: Beta ๐Ÿšง

Calculation Features

Overviewโ€‹

A Calculation is a Feature Type which allows you to define performant SQL-like operations on your source data. By avoiding the overhead of executing a Python function, Calculation features can be an efficient alternative for Feature Views that don't require the expressiveness of a python or pandas mode transformation.

Calculation Features are the recommended path for simple operations such as setting default values, simple arithmetic operations, and DATEDIFFs.

A Basic Exampleโ€‹

transaction_analysis = RealtimeFeatureView(
name="calculations_rtfv",
sources=[user_metrics, req_source],
features=[
Calculation(name="transaction_z_score", expr="(req_source.amount - user_metrics.mean) / user_metrics.stddev"),
Calculation(
name="is_amount_above_threshold",
expr="req_source.amount > user_metrics.threshold",
),
],
)

Calculations Workflowโ€‹

  1. Create a RealtimeFeatureView using the RealtimeFeatureView class. Realtime Feature Views that use Calculation features must be defined this way (not with a decorator).
  2. Specify inputs via the sources parameter, which can include both request and entity-based sources.
  3. Define each feature using the Calculation class, passing a name and SQL-style expr string.
  4. Ensure the expression uses only supported functions and valid type operations. Tecton will validate syntax and types during plan/apply.
  5. Apply the Feature View with tecton apply to register it for real-time serving and make it available to Feature Services.

What's Nextโ€‹

Once you've defined Calculation Features, consider:

How to Use Calculation Featuresโ€‹

Calculation Features are defined using SQL-like expressions in the expr field of a Calculation object. Unlike python and pandas mode Realtime Feature Views which use a decorator pattern, Calculation Features are defined by directly instantiating a RealtimeFeatureView object with one or more Calculation features.

caution

Feature Views using Calculation Features can not use a transformation function.

transaction_analysis = RealtimeFeatureView(
name="calculations_rtfv",
sources=[user_metrics, req_source],
features=[
Calculation(name="transaction_z_score", expr="(req_source.amount - user_metrics.mean) / user_metrics.stddev"),
Calculation(
name="is_amount_above_threshold",
expr="req_source.amount > user_metrics.threshold",
),
],
)

Type Systemโ€‹

Calculation Features use Tecton's native type system for validating inputs and output types. When writing expressions, types are automatically inferred from your input features and operations.

Invalid type combinations will raise errors during feature validation rather than runtime:

# This will fail validation - can't add string and int
Calculation(name="invalid", expr="<string_field> + <int_field>")

SQL Expression Referenceโ€‹

A full list of supported SQL functionality can be found in the SDK Reference.

Was this page helpful?