Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add create in Featurestore, EntityType, Feature; add create_entity_type in Featurestore; add create_feature, batch_create_features in EntityType; add ingest_from_* for bq and gcs in EntityType; add and update delete with force delete nested resources #872

Merged
Merged
757 changes: 753 additions & 4 deletions google/cloud/aiplatform/featurestore/entity_type.py

Large diffs are not rendered by default.

156 changes: 151 additions & 5 deletions google/cloud/aiplatform/featurestore/feature.py
Expand Up @@ -51,7 +51,7 @@ def _resource_id_validator(resource_id: str):
resource_id(str):
The resource id to validate.
"""
featurestore_utils.validate_id(resource_id)
featurestore_utils.validate_feature_id(resource_id)

def __init__(
self,
Expand Down Expand Up @@ -83,9 +83,12 @@ def __init__(
Example: "projects/123/locations/us-central1/featurestores/my_featurestore_id/entityTypes/my_entity_type_id/features/my_feature_id"
or "my_feature_id" when project and location are initialized or passed, with featurestore_id and entity_type_id passed.
featurestore_id (str):
Optional. Featurestore ID to retrieve feature from, when feature_name is passed as Feature ID.
Optional. Featurestore ID of an existing featurestore to retrieve feature from,
when feature_name is passed as Feature ID.
entity_type_id (str):
Optional. EntityType ID to retrieve feature from, when feature_name is passed as Feature ID.
Optional. EntityType ID of an existing entityType to retrieve feature from,
when feature_name is passed as Feature ID.
The EntityType must exist in the Featurestore if provided by the featurestore_id.
project (str):
Optional. Project to retrieve feature from. If not set, project
set in aiplatform.init will be used.
Expand Down Expand Up @@ -261,11 +264,13 @@ def list(

Args:
entity_type_name (str):
Required. A fully-qualified entityType resource name or an entity_type ID to list features in
Required. A fully-qualified entityType resource name or an entity_type ID of an existing entityType
to list features in. The EntityType must exist in the Featurestore if provided by the featurestore_id.
Example: "projects/123/locations/us-central1/featurestores/my_featurestore_id/entityTypes/my_entity_type_id"
or "my_entity_type_id" when project and location are initialized or passed, with featurestore_id passed.
featurestore_id (str):
Optional. Featurestore ID to list features in, when entity_type_name is passed as entity_type ID.
Optional. Featurestore ID of an existing featurestore to list features in,
when entity_type_name is passed as entity_type ID.
filter (str):
Optional. Lists the Features that match the filter expression. The
following filters are supported:
Expand Down Expand Up @@ -472,3 +477,144 @@ def search(
)
for gapic_resource in resource_list
]

@classmethod
@base.optional_sync()
def create(
cls,
feature_id: str,
value_type: str,
entity_type_name: str,
featurestore_id: Optional[str] = None,
description: Optional[str] = None,
labels: Optional[Dict[str, str]] = None,
project: Optional[str] = None,
location: Optional[str] = None,
credentials: Optional[auth_credentials.Credentials] = None,
request_metadata: Optional[Sequence[Tuple[str, str]]] = (),
sync: bool = True,
) -> "Feature":
"""Creates a Feature resource in an EntityType.

Example Usage:

my_feature = aiplatform.Feature.create(
feature_id='my_feature_id',
value_type='INT64',
entity_type_name='projects/123/locations/us-central1/featurestores/my_featurestore_id/\
entityTypes/my_entity_type_id'
)
or
my_feature = aiplatform.Feature.create(
feature_id='my_feature_id',
value_type='INT64',
entity_type_name='my_entity_type_id',
featurestore_id='my_featurestore_id',
)

Args:
feature_id (str):
Required. The ID to use for the Feature, which will become
the final component of the Feature's resource name, which is immutable.

This value may be up to 60 characters, and valid characters
are ``[a-z0-9_]``. The first character cannot be a number.

The value must be unique within an EntityType.
value_type (str):
Required. Immutable. Type of Feature value.
One of BOOL, BOOL_ARRAY, DOUBLE, DOUBLE_ARRAY, INT64, INT64_ARRAY, STRING, STRING_ARRAY, BYTES.
entity_type_name (str):
Required. A fully-qualified entityType resource name or an entity_type ID of an existing entityType
to create Feature in. The EntityType must exist in the Featurestore if provided by the featurestore_id.
Example: "projects/123/locations/us-central1/featurestores/my_featurestore_id/entityTypes/my_entity_type_id"
or "my_entity_type_id" when project and location are initialized or passed, with featurestore_id passed.
featurestore_id (str):
Optional. Featurestore ID of an existing featurestore to create Feature in
if `entity_type_name` is passed an entity_type ID.
description (str):
Optional. Description of the Feature.
labels (Dict[str, str]):
Optional. The labels with user-defined
metadata to organize your Features.
Label keys and values can be no longer than 64
characters (Unicode codepoints), can only
contain lowercase letters, numeric characters,
underscores and dashes. International characters
are allowed.
See https://goo.gl/xmQnxf for more information
on and examples of labels. No more than 64 user
labels can be associated with one Feature
(System labels are excluded)."
System reserved label keys are prefixed with
"aiplatform.googleapis.com/" and are immutable.
project (str):
Optional. Project to create Feature in if `entity_type_name` is passed an entity_type ID.
If not set, project set in aiplatform.init will be used.
location (str):
Optional. Location to create Feature in if `entity_type_name` is passed an entity_type ID.
If not set, location set in aiplatform.init will be used.
credentials (auth_credentials.Credentials):
Optional. Custom credentials to use to create Features. Overrides
credentials set in aiplatform.init.
request_metadata (Sequence[Tuple[str, str]]):
Optional. Strings which should be sent along with the request as metadata.
sync (bool):
Optional. Whether to execute this creation synchronously. If False, this method
will be executed in concurrent Future and any downstream object will
be immediately returned and synced when the Future has completed.

Returns:
Feature - feature resource object

"""
entity_type_name = utils.full_resource_name(
morgandu marked this conversation as resolved.
Show resolved Hide resolved
resource_name=entity_type_name,
resource_noun=featurestore.EntityType._resource_noun,
parse_resource_name_method=featurestore.EntityType._parse_resource_name,
format_resource_name_method=featurestore.EntityType._format_resource_name,
parent_resource_name_fields={
featurestore.Featurestore._resource_noun: featurestore_id
}
if featurestore_id
else featurestore_id,
project=project,
location=location,
resource_id_validator=featurestore.EntityType._resource_id_validator,
)
entity_type_name_components = featurestore.EntityType._parse_resource_name(
entity_type_name
)

feature_config = featurestore_utils._FeatureConfig(
feature_id=feature_id,
value_type=value_type,
description=description,
labels=labels,
)

create_feature_request = feature_config.get_create_feature_request()
create_feature_request.parent = entity_type_name

api_client = cls._instantiate_client(
location=entity_type_name_components["location"], credentials=credentials,
)

created_feature_lro = api_client.create_feature(
request=create_feature_request, metadata=request_metadata,
)

_LOGGER.log_create_with_lro(cls, created_feature_lro)

created_feature = created_feature_lro.result()

_LOGGER.log_create_complete(cls, created_feature, "feature")

feature_obj = cls(
feature_name=created_feature.name,
project=project,
location=location,
credentials=credentials,
)

return feature_obj