Skip to content

Commit ba11c3d

Browse files
authored
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)
- [x] add create method in Featurestore, EntityType, Feature classes; - [x] add create_entity_type in Featurestore; - [x] add create_feature, batch_create_features in EntityType; - [x] add ingest_from_bq and ingest_from_gcs methods in EntityType class - [x] add and update delete methods with force delete nested resources - [x] add unit tests - [x] update integration test
1 parent 3ec620c commit ba11c3d

File tree

9 files changed

+2124
-36
lines changed

9 files changed

+2124
-36
lines changed

Diff for: google/cloud/aiplatform/featurestore/entity_type.py

+753-4
Large diffs are not rendered by default.

Diff for: google/cloud/aiplatform/featurestore/feature.py

+151-5
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _resource_id_validator(resource_id: str):
5151
resource_id(str):
5252
The resource id to validate.
5353
"""
54-
featurestore_utils.validate_id(resource_id)
54+
featurestore_utils.validate_feature_id(resource_id)
5555

5656
def __init__(
5757
self,
@@ -83,9 +83,12 @@ def __init__(
8383
Example: "projects/123/locations/us-central1/featurestores/my_featurestore_id/entityTypes/my_entity_type_id/features/my_feature_id"
8484
or "my_feature_id" when project and location are initialized or passed, with featurestore_id and entity_type_id passed.
8585
featurestore_id (str):
86-
Optional. Featurestore ID to retrieve feature from, when feature_name is passed as Feature ID.
86+
Optional. Featurestore ID of an existing featurestore to retrieve feature from,
87+
when feature_name is passed as Feature ID.
8788
entity_type_id (str):
88-
Optional. EntityType ID to retrieve feature from, when feature_name is passed as Feature ID.
89+
Optional. EntityType ID of an existing entityType to retrieve feature from,
90+
when feature_name is passed as Feature ID.
91+
The EntityType must exist in the Featurestore if provided by the featurestore_id.
8992
project (str):
9093
Optional. Project to retrieve feature from. If not set, project
9194
set in aiplatform.init will be used.
@@ -261,11 +264,13 @@ def list(
261264
262265
Args:
263266
entity_type_name (str):
264-
Required. A fully-qualified entityType resource name or an entity_type ID to list features in
267+
Required. A fully-qualified entityType resource name or an entity_type ID of an existing entityType
268+
to list features in. The EntityType must exist in the Featurestore if provided by the featurestore_id.
265269
Example: "projects/123/locations/us-central1/featurestores/my_featurestore_id/entityTypes/my_entity_type_id"
266270
or "my_entity_type_id" when project and location are initialized or passed, with featurestore_id passed.
267271
featurestore_id (str):
268-
Optional. Featurestore ID to list features in, when entity_type_name is passed as entity_type ID.
272+
Optional. Featurestore ID of an existing featurestore to list features in,
273+
when entity_type_name is passed as entity_type ID.
269274
filter (str):
270275
Optional. Lists the Features that match the filter expression. The
271276
following filters are supported:
@@ -472,3 +477,144 @@ def search(
472477
)
473478
for gapic_resource in resource_list
474479
]
480+
481+
@classmethod
482+
@base.optional_sync()
483+
def create(
484+
cls,
485+
feature_id: str,
486+
value_type: str,
487+
entity_type_name: str,
488+
featurestore_id: Optional[str] = None,
489+
description: Optional[str] = None,
490+
labels: Optional[Dict[str, str]] = None,
491+
project: Optional[str] = None,
492+
location: Optional[str] = None,
493+
credentials: Optional[auth_credentials.Credentials] = None,
494+
request_metadata: Optional[Sequence[Tuple[str, str]]] = (),
495+
sync: bool = True,
496+
) -> "Feature":
497+
"""Creates a Feature resource in an EntityType.
498+
499+
Example Usage:
500+
501+
my_feature = aiplatform.Feature.create(
502+
feature_id='my_feature_id',
503+
value_type='INT64',
504+
entity_type_name='projects/123/locations/us-central1/featurestores/my_featurestore_id/\
505+
entityTypes/my_entity_type_id'
506+
)
507+
or
508+
my_feature = aiplatform.Feature.create(
509+
feature_id='my_feature_id',
510+
value_type='INT64',
511+
entity_type_name='my_entity_type_id',
512+
featurestore_id='my_featurestore_id',
513+
)
514+
515+
Args:
516+
feature_id (str):
517+
Required. The ID to use for the Feature, which will become
518+
the final component of the Feature's resource name, which is immutable.
519+
520+
This value may be up to 60 characters, and valid characters
521+
are ``[a-z0-9_]``. The first character cannot be a number.
522+
523+
The value must be unique within an EntityType.
524+
value_type (str):
525+
Required. Immutable. Type of Feature value.
526+
One of BOOL, BOOL_ARRAY, DOUBLE, DOUBLE_ARRAY, INT64, INT64_ARRAY, STRING, STRING_ARRAY, BYTES.
527+
entity_type_name (str):
528+
Required. A fully-qualified entityType resource name or an entity_type ID of an existing entityType
529+
to create Feature in. The EntityType must exist in the Featurestore if provided by the featurestore_id.
530+
Example: "projects/123/locations/us-central1/featurestores/my_featurestore_id/entityTypes/my_entity_type_id"
531+
or "my_entity_type_id" when project and location are initialized or passed, with featurestore_id passed.
532+
featurestore_id (str):
533+
Optional. Featurestore ID of an existing featurestore to create Feature in
534+
if `entity_type_name` is passed an entity_type ID.
535+
description (str):
536+
Optional. Description of the Feature.
537+
labels (Dict[str, str]):
538+
Optional. The labels with user-defined
539+
metadata to organize your Features.
540+
Label keys and values can be no longer than 64
541+
characters (Unicode codepoints), can only
542+
contain lowercase letters, numeric characters,
543+
underscores and dashes. International characters
544+
are allowed.
545+
See https://goo.gl/xmQnxf for more information
546+
on and examples of labels. No more than 64 user
547+
labels can be associated with one Feature
548+
(System labels are excluded)."
549+
System reserved label keys are prefixed with
550+
"aiplatform.googleapis.com/" and are immutable.
551+
project (str):
552+
Optional. Project to create Feature in if `entity_type_name` is passed an entity_type ID.
553+
If not set, project set in aiplatform.init will be used.
554+
location (str):
555+
Optional. Location to create Feature in if `entity_type_name` is passed an entity_type ID.
556+
If not set, location set in aiplatform.init will be used.
557+
credentials (auth_credentials.Credentials):
558+
Optional. Custom credentials to use to create Features. Overrides
559+
credentials set in aiplatform.init.
560+
request_metadata (Sequence[Tuple[str, str]]):
561+
Optional. Strings which should be sent along with the request as metadata.
562+
sync (bool):
563+
Optional. Whether to execute this creation synchronously. If False, this method
564+
will be executed in concurrent Future and any downstream object will
565+
be immediately returned and synced when the Future has completed.
566+
567+
Returns:
568+
Feature - feature resource object
569+
570+
"""
571+
entity_type_name = utils.full_resource_name(
572+
resource_name=entity_type_name,
573+
resource_noun=featurestore.EntityType._resource_noun,
574+
parse_resource_name_method=featurestore.EntityType._parse_resource_name,
575+
format_resource_name_method=featurestore.EntityType._format_resource_name,
576+
parent_resource_name_fields={
577+
featurestore.Featurestore._resource_noun: featurestore_id
578+
}
579+
if featurestore_id
580+
else featurestore_id,
581+
project=project,
582+
location=location,
583+
resource_id_validator=featurestore.EntityType._resource_id_validator,
584+
)
585+
entity_type_name_components = featurestore.EntityType._parse_resource_name(
586+
entity_type_name
587+
)
588+
589+
feature_config = featurestore_utils._FeatureConfig(
590+
feature_id=feature_id,
591+
value_type=value_type,
592+
description=description,
593+
labels=labels,
594+
)
595+
596+
create_feature_request = feature_config.get_create_feature_request()
597+
create_feature_request.parent = entity_type_name
598+
599+
api_client = cls._instantiate_client(
600+
location=entity_type_name_components["location"], credentials=credentials,
601+
)
602+
603+
created_feature_lro = api_client.create_feature(
604+
request=create_feature_request, metadata=request_metadata,
605+
)
606+
607+
_LOGGER.log_create_with_lro(cls, created_feature_lro)
608+
609+
created_feature = created_feature_lro.result()
610+
611+
_LOGGER.log_create_complete(cls, created_feature, "feature")
612+
613+
feature_obj = cls(
614+
feature_name=created_feature.name,
615+
project=project,
616+
location=location,
617+
credentials=credentials,
618+
)
619+
620+
return feature_obj

0 commit comments

Comments
 (0)