Skip to content

featurebyte.ViewColumn.as_target

as_target(
target_name: str,
offset: Optional[str]=None,
target_type: Optional[TargetType]=None,
fill_value: Union[bool, int, float, str, NoneType, Unset]=UNSET
) -> Target

Description

Create a lookup target directly from the column in the View. For SCD views, lookup targets are materialized through point-in-time joins, and the resulting value represents the active row for the natural key at the point-in-time indicated in the target request.

To obtain a target value at a specific time after the request's point-in-time, an offset can be specified.

Parameters

  • target_name: str
    Name of the target to create.

  • offset: Optional[str]
    When specified, retrieve target value as of this offset after the point-in-time.

  • target_type: Optional[TargetType]
    Type of the target

  • fill_value: Union[bool, int, float, str, NoneType, Unset]
    default: UNSET
    Value to fill if the value in the column is empty

Returns

  • Target

Raises

  • TargetFillValueNotProvidedError
    If fill_value is not provided.

Examples

>>> customer_view = catalog.get_view("GROCERYCUSTOMER")
>>> # Extract operating system from BrowserUserAgent column
>>> customer_view["OperatingSystemIsWindows"] = customer_view.BrowserUserAgent.str.contains(
...     "Windows"
... )
>>> # Create a target from the OperatingSystemIsWindows column
>>> uses_windows = customer_view.OperatingSystemIsWindows.as_target(
...     "UsesWindows", fill_value=None
... )

If the view is a Slowly Changing Dimension View, you may also consider creating a target that retrieves the entity's attribute at a specific time after the point-in-time specified in the target request by specifying an offset.

>>> uses_windows_next_12w = customer_view.OperatingSystemIsWindows.as_target(
...     "UsesWindows_next_12w", offset="12w", fill_value=None
... )