Skip to content

Transformation Function#

You can create a TransformationFunction via FeatureStore.create_transformation_function and obtain an existing one via FeatureStore.get_transformation_function or FeatureStore.get_transformation_functions.

TransformationFunction #

NOT_FOUND_ERROR_CODE class-attribute instance-attribute #

NOT_FOUND_ERROR_CODE = 270160

DTO class for transformation functions.

PARAMETER DESCRIPTION
featurestore_id

int. Id of the feature store in which the transformation function is saved.

hopsworks_udf

HopsworksUDF. The meta data object for UDF in Hopsworks, which can be created using the @udf decorator.

version

int. The version of the transformation function.

id

int. The id of the transformation function in the feature store.

transformation_type

UDFType. The type of the transformation function. Can be "on-demand" or "model-dependent"

hopsworks_udf property #

hopsworks_udf: HopsworksUdf

Meta data class for the user defined transformation function.

id property writable #

id: id

Transformation function id.

output_column_names property #

output_column_names: list[str]

Names of the output columns generated by the transformation functions.

transformation_statistics property writable #

transformation_statistics: TransformationStatistics | None

Feature statistics required for the defined UDF.

transformation_type property writable #

transformation_type: TransformationType

Type of the Transformation: can be model dependent or on-demand.

version property writable #

version: int

Version of the transformation function.

__call__ #

__call__(*features: list[str]) -> TransformationFunction

Update the feature to be using in the transformation function.

PARAMETER DESCRIPTION
features

List[str]. Name of features to be passed to the User Defined function.

TYPE: list[str] DEFAULT: ()

RETURNS DESCRIPTION
TransformationFunction

HopsworksUdf: Meta data class for the user defined function.

RAISES DESCRIPTION
`hopsworks.client.exceptions.FeatureStoreException`

If the provided number of features do not match the number of arguments in the defined UDF or if the provided feature names are not strings.

alias #

alias(*args: str)

Set the names of the transformed features output by the transformation function.

delete #

delete() -> None

Delete transformation function from backend.

Example
# import hopsworks udf decorator
from hopworks import udf

# define function
@udf(int)
def plus_one(value):
    return value + 1

# create transformation function
plus_one_meta = fs.create_transformation_function(
        transformation_function=plus_one,
        version=1
    )
# persist transformation function in backend
plus_one_meta.save()

# retrieve transformation function
plus_one_fn = fs.get_transformation_function(name="plus_one")

# delete transformation function from backend
plus_one_fn.delete()

from_response_json classmethod #

from_response_json(
    json_dict: dict[str, Any],
) -> TransformationFunction | list[TransformationFunction]

Function that constructs the class object from its json serialization.

PARAMETER DESCRIPTION
json_dict

Dict[str, Any]. Json serialized dictionary for the class.

TYPE: dict[str, Any]

RETURNS DESCRIPTION
TransformationFunction | list[TransformationFunction]

TransformationFunction: Json deserialized class object.

json #

json() -> str

Convert class into its json serialized form.

RETURNS DESCRIPTION
str

str: Json serialized object.

save #

save() -> None

Save a transformation function into the backend.

Example
# import hopsworks udf decorator
from hopworks import udf

# define function
@udf(int)
def plus_one(value):
    return value + 1

# create transformation function
plus_one_meta = fs.create_transformation_function(
        transformation_function=plus_one,
        version=1
    )

# persist transformation function in backend
plus_one_meta.save()

to_dict #

to_dict() -> dict[str, Any]

Convert class into a dictionary.

RETURNS DESCRIPTION
dict[str, Any]

Dict: Dictionary that contains all data required to json serialize the object.

update_from_response_json #

update_from_response_json(
    json_dict: dict[str, Any],
) -> TransformationFunction

Function that updates the class object from its json serialization.

PARAMETER DESCRIPTION
json_dict

Dict[str, Any]. Json serialized dictionary for the class.

TYPE: dict[str, Any]

RETURNS DESCRIPTION
TransformationFunction

TransformationFunction: Json deserialized class object.