tecton.declarative.feature_view.OnDemandFeatureView

class tecton.declarative.feature_view.OnDemandFeatureView(*, schema, transform, name, description, tags, pipeline_function, owner, sources, user_function)

OnDemandFeatureView class to include in Feature Services or to use in unit testing.

Do not instantiate this class directly. Use tecton.declarative.on_demand_feature_view instead.

Methods

__init__

Do not directly use this constructor. Internal constructor for OnDemandFeatureView.

run

Run the OnDemandFeatureView using mock sources.

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__(*, schema, transform, name, description, tags, pipeline_function, owner, sources, user_function)

Do not directly use this constructor. Internal constructor for OnDemandFeatureView.

Parameters
  • schema – Spark schema declaring the expected output.

  • transform – Transformation used to produce the feature values.

  • name (str) – Unique, human friendly name.

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

  • tags (Optional[Dict[str, str]]) – Arbitrary key-value pairs of tagging metadata.

  • pipeline_function – Pipeline definition function.

  • owner (Optional[str]) – Owner name, used to organize features.

  • sources (List[Union[RequestSource, FeatureDefinition, FeaturesConfig]]) – The data source inputs to the feature view.

  • user_function – User-defined function.

run(**mock_sources)

Run the OnDemandFeatureView using mock sources.

Parameters

mock_sources (Union[Dict[str, Any], DataFrame]) – Required. Keyword args with the same expected keys as the OnDemandFeatureView’s inputs parameters. For the “python” mode, each input must be a Dictionary representing a single row. For the “pandas” mode, each input must be a DataFrame with all of them containing the same number of rows and matching row ordering.

Example

@on_demand_feature_view(
    sources=[transaction_request],
    mode='python',
    schema=output_schema,
)
def transaction_amount_is_high(transaction_request):
    return {'transaction_amount_is_high': transaction_request['amount'] > 10000}

# Test using `run` API.
result = transaction_amount_is_high.run(transaction_request={'amount': 100})
Returns

A Dict object for the “python” mode and a pandas.DataFrame object for the “pandas” mode”.

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.