tecton.declarative.FeatureTable

class tecton.declarative.FeatureTable(*, name, entities, schema, ttl=None, online=False, offline=False, description=None, owner=None, tags=None, offline_store=DeltaConfig(time_partition_size='24h'), online_store=None, batch_compute=None, online_serving_index=None)

Declare a FeatureTable.

The FeatureTable class is used to represent one or many features that are pushed to Tecton from external feature computation systems.

Methods

__init__

Instantiates a new FeatureTable.

with_join_key_map

Used to rebind join keys for a Feature View used in a Feature Service.

with_name

Used to rename a Feature View used in a Feature Service.

__init__(*, name, entities, schema, ttl=None, online=False, offline=False, description=None, owner=None, tags=None, offline_store=DeltaConfig(time_partition_size='24h'), online_store=None, batch_compute=None, online_serving_index=None)

Instantiates a new FeatureTable.

Parameters
  • name (str) – Unique, human friendly name that identifies the FeatureTable.

  • entities (List[Union[BaseEntity, OverriddenEntity]]) – A list of Entity objects, used to organize features.

  • schema (List[Field]) – A Spark schema definition (StructType) for the FeatureTable. Supported types are: LongType, DoubleType, StringType, BooleanType and TimestampType (for inferred timestamp column only).

  • ttl (Optional[timedelta]) – The TTL (or “look back window”) for features defined by this feature table. This parameter determines how long features will live in the online store and how far to “look back” relative to a training example’s timestamp when generating offline training sets. Shorter TTLs improve performance and reduce costs.

  • online (Optional[bool]) – Enable writing to online feature store. (Default: False)

  • offline (Optional[bool]) – Enable writing to offline feature store. (Default: False)

  • description (Optional[str]) – A human readable description.

  • owner (Optional[str]) – Owner name (typically the email of the primary maintainer).

  • tags (Optional[Dict[str, str]]) – Tags associated with this Tecton Object (key-value pairs of arbitrary metadata).

  • offline_store (DeltaConfig) – Configuration for how data is written to the offline feature store.

  • online_store (Union[DynamoConfig, RedisConfig, None]) – Configuration for how data is written to the online feature store.

  • batch_compute (Union[DatabricksClusterConfig, EMRClusterConfig, None]) – Batch materialization cluster configuration. Should be one of: [EMRClusterConfig, DatabricksClusterConfig]

  • online_serving_index (Optional[List[str]]) – (Advanced) Defines the set of join keys that will be indexed and queryable during online serving. Defaults to the complete set of join keys. Up to one join key may be omitted. If one key is omitted, online requests to a Feature Service will return all feature vectors that match the specified join keys.

Returns

A Feature Table

An example declaration of a FeatureTable

from tecton import Entity, FeatureTable
from tecton.types import DataType, Field
import datetime

# Declare your user Entity instance here or import it if defined elsewhere in
# your Tecton repo.
user = ...

schema = [
    Field('user_id', DataType.String),
    Field('timestamp', DataType.Timestamp),
    Field('user_login_count_7d', DataType.Int64),
    Field('user_login_count_30d', DataType.Int64)
]

user_login_counts = FeatureTable(
    name='user_login_counts',
    entities=[user],
    schema=schema,
    online=True,
    offline=True,
    ttl=datetime.timedelta(days=30)
)
with_join_key_map(join_key_map)

Used to rebind join keys for a Feature View used in a Feature Service. The keys in join_key_map should be the feature view join keys, and the values should be the feature service overrides.

from tecton import FeatureService

# The join key for this feature service will be "feature_service_user_id".
feature_service = FeatureService(
    name="feature_service",
    features=[
        my_feature_view.with_join_key_map({"user_id" : "feature_service_user_id"}),
    ],
)

# Here is a more sophisticated example. The join keys for this feature service will be "transaction_id",
# "sender_id", and "recipient_id" and will contain three feature views named "transaction_features",
# "sender_features", and "recipient_features".
transaction_fraud_service = FeatureService(
    name="transaction_fraud_service",
    features=[
        # Select a subset of features from a feature view.
        transaction_features[["amount"]],

        # Rename a feature view and/or rebind its join keys. In this example, we want user features for both the
        # transaction sender and recipient, so include the feature view twice and bind it to two different feature
        # service join keys.
        user_features.with_name("sender_features").with_join_key_map({"user_id" : "sender_id"}),
        user_features.with_name("recipient_features").with_join_key_map({"user_id" : "recipient_id"}),
    ],
)
with_name(namespace)

Used to rename a Feature View used in a Feature Service.

from tecton import FeatureService

# The feature view in this feature service will be named "new_named_feature_view" in training data dataframe
# columns and other metadata.
feature_service = FeatureService(
    name="feature_service",
    features=[
        my_feature_view.with_name("new_named_feature_view")
    ],
)

# Here is a more sophisticated example. The join keys for this feature service will be "transaction_id",
# "sender_id", and "recipient_id" and will contain three feature views named "transaction_features",
# "sender_features", and "recipient_features".
transaction_fraud_service = FeatureService(
    name="transaction_fraud_service",
    features=[
        # Select a subset of features from a feature view.
        transaction_features[["amount"]],

        # Rename a feature view and/or rebind its join keys. In this example, we want user features for both the
        # transaction sender and recipient, so include the feature view twice and bind it to two different feature
        # service join keys.
        user_features.with_name("sender_features").with_join_key_map({"user_id" : "sender_id"}),
        user_features.with_name("recipient_features").with_join_key_map({"user_id" : "recipient_id"}),
    ],
)

Attributes

name

Name of this Tecton Object.