Skip to content

Commit

Permalink
include nested resorce refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
morgandu committed Dec 17, 2021
1 parent e26a1cb commit 1e1c2fb
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 26 deletions.
16 changes: 9 additions & 7 deletions google/cloud/aiplatform/featurestore/entity_type.py
Expand Up @@ -509,9 +509,16 @@ def create(

featurestore_name = utils.full_resource_name(
resource_name=featurestore_name,
resource_noun="featurestores",
resource_noun=featurestore.Featurestore._resource_noun,
parse_resource_name_method=featurestore.Featurestore._parse_resource_name,
format_resource_name_method=featurestore.Featurestore._format_resource_name,
project=project,
location=location,
resource_id_validator=featurestore.Featurestore._resource_id_validator,
)

featurestore_name_components = featurestore.Featurestore._parse_resource_name(
featurestore_name
)

gapic_entity_type = gca_entity_type.EntityType()
Expand All @@ -524,12 +531,7 @@ def create(
gapic_entity_type.description = description

api_client = cls._instantiate_client(
location=featurestore_utils.CompatFeaturestoreServiceClient.parse_featurestore_path(
path=featurestore_name
)[
"location"
],
credentials=credentials,
location=featurestore_name_components["location"], credentials=credentials,
)

created_entity_type_lro = api_client.create_entity_type(
Expand Down
31 changes: 16 additions & 15 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 @@ -568,24 +568,23 @@ def create(
Feature - feature resource object
"""
(
featurestore_id,
_,
) = featurestore_utils.validate_and_get_entity_type_resource_ids(
entity_type_name=entity_type_name, featurestore_id=featurestore_id,
)

entity_type_name = utils.full_resource_name(
resource_name=entity_type_name,
resource_noun=f"featurestores/{featurestore_id}/entityTypes",
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
)
location = featurestore_utils.CompatFeaturestoreServiceClient.parse_entity_type_path(
path=entity_type_name
)[
"location"
]

feature_config = featurestore_utils._FeatureConfig(
feature_id=feature_id,
Expand All @@ -597,7 +596,9 @@ def create(
create_feature_request = feature_config.get_create_feature_request()
create_feature_request.parent = entity_type_name

api_client = cls._instantiate_client(location=location, credentials=credentials)
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,
Expand Down
14 changes: 11 additions & 3 deletions google/cloud/aiplatform/utils/featurestore_utils.py
Expand Up @@ -16,7 +16,7 @@
#

import re
from typing import Dict, NamedTuple, Optional, Tuple
from typing import Dict, NamedTuple, Optional

from google.cloud.aiplatform.compat.services import featurestore_service_client
from google.cloud.aiplatform.compat.types import (
Expand All @@ -33,8 +33,16 @@
_FEATURE_VALUE_TYPE_UNSPECIFIED = "VALUE_TYPE_UNSPECIFIED"


def validate_id(resource_id: str):
"""Validates feature store resource ID pattern."""
def validate_id(resource_id: str) -> None:
"""Validates feature store resource ID pattern.
Args:
resource_id (str):
Required. Feature Store resource ID.
Raises:
ValueError if resource_id is invalid.
"""
if not re.compile(r"^" + RESOURCE_ID_PATTERN_REGEX + r"$").match(resource_id):
raise ValueError("Resource ID {resource_id} is not a valied resource id.")

Expand Down
4 changes: 3 additions & 1 deletion tests/system/aiplatform/test_featurestore.py
Expand Up @@ -191,7 +191,9 @@ def test_ingest_feature_values(self, shared_state, caplog):

caplog.clear()

def test_ingest_feature_values_with_config(self, shared_state, caplog):
def test_batch_create_features_and_ingest_feature_values(
self, shared_state, caplog
):

assert shared_state["movie_entity_type"]
movie_entity_type = shared_state["movie_entity_type"]
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/aiplatform/test_featurestores.py
Expand Up @@ -28,6 +28,8 @@
from google.cloud import aiplatform
from google.cloud.aiplatform import base
from google.cloud.aiplatform import initializer
from google.cloud.aiplatform import utils

from google.cloud.aiplatform.utils import featurestore_utils
from google.cloud.aiplatform_v1.services.featurestore_service import (
client as featurestore_service_client,
Expand Down

0 comments on commit 1e1c2fb

Please sign in to comment.