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

Introduce Entity as higher-level concept #1014

Merged
merged 15 commits into from
Sep 28, 2020
21 changes: 19 additions & 2 deletions common-test/src/main/java/feast/common/it/DataGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package feast.common.it;

import com.google.common.collect.ImmutableList;
import feast.proto.core.EntityProto;
import feast.proto.core.FeatureSetProto;
import feast.proto.core.SourceProto;
import feast.proto.core.StoreProto;
Expand Down Expand Up @@ -111,11 +112,27 @@ public static FeatureSetProto.FeatureSpec createFeature(
.build();
}

public static FeatureSetProto.EntitySpec createEntity(
public static FeatureSetProto.EntitySpec createEntitySpec(
String name, ValueProto.ValueType.Enum valueType) {
return FeatureSetProto.EntitySpec.newBuilder().setName(name).setValueType(valueType).build();
}

public static EntityProto.Entity createEntity(
String name,
String description,
ValueProto.ValueType.Enum valueType,
Map<String, String> labels) {
return EntityProto.Entity.newBuilder()
.setSpec(
EntityProto.EntitySpecV2.newBuilder()
.setName(name)
.setDescription(description)
.setValueType(valueType)
.putAllLabels(labels)
.build())
.build();
}

public static FeatureSetProto.FeatureSet createFeatureSet(
SourceProto.Source source,
String projectName,
Expand Down Expand Up @@ -152,7 +169,7 @@ public static FeatureSetProto.FeatureSet createFeatureSet(
.putAllLabels(labels)
.addAllEntities(
entities.entrySet().stream()
.map(entry -> createEntity(entry.getKey(), entry.getValue()))
.map(entry -> createEntitySpec(entry.getKey(), entry.getValue()))
.collect(Collectors.toList()))
.addAllFeatures(
features.entrySet().stream()
Expand Down
51 changes: 51 additions & 0 deletions common-test/src/main/java/feast/common/it/SimpleCoreClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,48 @@ public CoreServiceProto.ApplyFeatureSetResponse simpleApplyFeatureSet(
CoreServiceProto.ApplyFeatureSetRequest.newBuilder().setFeatureSet(featureSet).build());
}

public CoreServiceProto.ApplyEntityResponse simpleApplyEntity(
String projectName, EntityProto.Entity entity) {
return stub.applyEntity(
CoreServiceProto.ApplyEntityRequest.newBuilder()
.setProject(projectName)
.setEntity(entity)
.build());
}

public List<EntityProto.Entity> simpleListEntities(String projectName, String entityName) {
return stub.listEntities(
CoreServiceProto.ListEntitiesRequest.newBuilder()
.setFilter(
CoreServiceProto.ListEntitiesRequest.Filter.newBuilder()
.setProject(projectName)
.setEntityName(entityName)
.build())
.build())
.getEntitiesList();
}

public List<EntityProto.Entity> simpleListEntities(
String projectName, String entityName, Map<String, String> labels) {
return stub.listEntities(
CoreServiceProto.ListEntitiesRequest.newBuilder()
.setFilter(
CoreServiceProto.ListEntitiesRequest.Filter.newBuilder()
.setProject(projectName)
.setEntityName(entityName)
.putAllLabels(labels)
.build())
.build())
.getEntitiesList();
}

public List<EntityProto.Entity> simpleListEntities(
CoreServiceProto.ListEntitiesRequest.Filter filter) {
return stub.listEntities(
CoreServiceProto.ListEntitiesRequest.newBuilder().setFilter(filter).build())
.getEntitiesList();
}

public List<FeatureSetProto.FeatureSet> simpleListFeatureSets(
String projectName, String featureSetName, Map<String, String> labels) {
return stub.listFeatureSets(
Expand Down Expand Up @@ -82,6 +124,15 @@ public FeatureSetProto.FeatureSet simpleGetFeatureSet(String projectName, String
.getFeatureSet();
}

public EntityProto.Entity simpleGetEntity(String projectName, String name) {
return stub.getEntity(
CoreServiceProto.GetEntityRequest.newBuilder()
.setName(name)
.setProject(projectName)
.build())
.getEntity();
}

public void updateFeatureSetStatus(
String projectName, String name, FeatureSetProto.FeatureSetStatus status) {
stub.updateFeatureSetStatus(
Expand Down
37 changes: 37 additions & 0 deletions core/src/main/java/feast/core/dao/EntityRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2018-2020 The Feast Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package feast.core.dao;

import feast.core.model.EntityV2;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

/** JPA repository supplying EntityV2 objects keyed by id. */
public interface EntityRepository extends JpaRepository<EntityV2, String> {

long count();

// Find single EntityV2 by project and name
EntityV2 findEntityByNameAndProject_Name(String name, String project);

// Find all EntityV2s matching the given name pattern with a specific project
List<EntityV2> findAllByNameLikeAndProject_NameOrderByNameAsc(String name, String project_name);

// Find all EntityV2s matching the given name pattern and project pattern
List<EntityV2> findAllByNameLikeAndProject_NameLikeOrderByNameAsc(
String name, String project_name);
}
87 changes: 87 additions & 0 deletions core/src/main/java/feast/core/grpc/CoreServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import feast.core.service.StatsService;
import feast.proto.core.CoreServiceGrpc.CoreServiceImplBase;
import feast.proto.core.CoreServiceProto.*;
import feast.proto.core.EntityProto.Entity;
import feast.proto.core.FeatureSetProto.FeatureSet;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
Expand Down Expand Up @@ -95,6 +96,31 @@ public void getFeatureSet(
}
}

@Override
public void getEntity(
GetEntityRequest request, StreamObserver<GetEntityResponse> responseObserver) {
try {
GetEntityResponse response = specService.getEntity(request);
responseObserver.onNext(response);
responseObserver.onCompleted();
} catch (RetrievalException e) {
log.error("Unable to fetch entity requested in GetEntity method: ", e);
responseObserver.onError(
Status.NOT_FOUND.withDescription(e.getMessage()).withCause(e).asRuntimeException());
} catch (IllegalArgumentException e) {
log.error("Illegal arguments provided to GetEntity method: ", e);
responseObserver.onError(
Status.INVALID_ARGUMENT
.withDescription(e.getMessage())
.withCause(e)
.asRuntimeException());
} catch (Exception e) {
log.error("Exception has occurred in GetEntity method: ", e);
responseObserver.onError(
Status.INTERNAL.withDescription(e.getMessage()).withCause(e).asRuntimeException());
}
}

@Override
public void listFeatureSets(
ListFeatureSetsRequest request, StreamObserver<ListFeatureSetsResponse> responseObserver) {
Expand Down Expand Up @@ -135,6 +161,32 @@ public void listFeatures(
}
}

/** Retrieve a list of entities */
@Override
public void listEntities(
ListEntitiesRequest request, StreamObserver<ListEntitiesResponse> responseObserver) {
try {
ListEntitiesResponse response = specService.listEntities(request.getFilter());
responseObserver.onNext(response);
responseObserver.onCompleted();
} catch (IllegalArgumentException e) {
log.error("Illegal arguments provided to ListEntities method: ", e);
responseObserver.onError(
Status.INVALID_ARGUMENT
.withDescription(e.getMessage())
.withCause(e)
.asRuntimeException());
} catch (RetrievalException e) {
log.error("Unable to fetch entities requested in ListEntities method: ", e);
responseObserver.onError(
Status.NOT_FOUND.withDescription(e.getMessage()).withCause(e).asRuntimeException());
} catch (Exception e) {
log.error("Exception has occurred in ListEntities method: ", e);
responseObserver.onError(
Status.INTERNAL.withDescription(e.getMessage()).withCause(e).asRuntimeException());
}
}

@Override
public void getFeatureStatistics(
GetFeatureStatisticsRequest request,
Expand Down Expand Up @@ -191,6 +243,41 @@ public void listStores(
}
}

/* Registers an entity to Feast Core */
@Override
public void applyEntity(
woop marked this conversation as resolved.
Show resolved Hide resolved
ApplyEntityRequest request, StreamObserver<ApplyEntityResponse> responseObserver) {

String projectId = null;

try {
Entity entity = request.getEntity();
projectId = request.getProject();
authorizationService.authorizeRequest(SecurityContextHolder.getContext(), projectId);
ApplyEntityResponse response = specService.applyEntity(entity, projectId);
responseObserver.onNext(response);
responseObserver.onCompleted();
} catch (org.hibernate.exception.ConstraintViolationException e) {
log.error(
"Unable to persist this entity due to a constraint violation. Please ensure that"
+ " field names are unique within the project namespace: ",
e);
responseObserver.onError(
Status.ALREADY_EXISTS.withDescription(e.getMessage()).withCause(e).asRuntimeException());
} catch (AccessDeniedException e) {
log.info(String.format("User prevented from accessing project: %s", projectId));
responseObserver.onError(
Status.PERMISSION_DENIED
.withDescription(e.getMessage())
.withCause(e)
.asRuntimeException());
} catch (Exception e) {
log.error("Exception has occurred in ApplyEntity method: ", e);
responseObserver.onError(
Status.INTERNAL.withDescription(e.getMessage()).withCause(e).asRuntimeException());
}
}

@Override
public void applyFeatureSet(
ApplyFeatureSetRequest request, StreamObserver<ApplyFeatureSetResponse> responseObserver) {
Expand Down
Loading