use of io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.FeatureStoreExpectation in project hopsworks by logicalclocks.
the class FeatureGroupValidationsController method getFeatureGroupExpectation.
public FeatureGroupExpectation getFeatureGroupExpectation(Featuregroup featuregroup, String name) throws FeaturestoreException {
// Find the FeatureStoreExpectation first
FeatureStoreExpectation featureStoreExpectation = getFeatureStoreExpectation(featuregroup.getFeaturestore(), name);
Optional<FeatureGroupExpectation> optional = featureGroupExpectationFacade.findByFeaturegroupAndExpectation(featuregroup, featureStoreExpectation);
if (!optional.isPresent()) {
throw new FeaturestoreException(RESTCodes.FeaturestoreErrorCode.FEATURE_GROUP_EXPECTATION_NOT_FOUND, FINE, "Expectation: " + name);
}
return optional.get();
}
use of io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.FeatureStoreExpectation in project hopsworks by logicalclocks.
the class FeatureGroupValidationsController method detachExpectation.
public void detachExpectation(Featuregroup featuregroup, String name) throws FeaturestoreException {
FeatureStoreExpectation featureStoreExpectation = getFeatureStoreExpectation(featuregroup.getFeaturestore(), name);
Optional<FeatureGroupExpectation> e = featureGroupExpectationFacade.findByFeaturegroupAndExpectation(featuregroup, featureStoreExpectation);
featureGroupExpectationFacade.remove(e.orElseThrow(() -> new FeaturestoreException(RESTCodes.FeaturestoreErrorCode.FEATURE_GROUP_EXPECTATION_NOT_FOUND, FINE, "expectation: " + name)));
}
use of io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.FeatureStoreExpectation in project hopsworks by logicalclocks.
the class FeatureStoreExpectationsBuilder method build.
public ExpectationDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Project project, Featurestore featurestore) {
ExpectationDTO dto = new ExpectationDTO();
uri(dto, uriInfo, project, featurestore);
expand(dto, resourceRequest);
if (dto.isExpand()) {
AbstractFacade.CollectionInfo collectionInfo = featureStoreExpectationFacade.findByFeaturestore(resourceRequest.getOffset(), resourceRequest.getLimit(), resourceRequest.getFilter(), resourceRequest.getSort(), featurestore);
List<FeatureStoreExpectation> featureStoreExpectations = collectionInfo.getItems();
for (FeatureStoreExpectation featureStoreExpectation : featureStoreExpectations) {
dto.addItem(build(uriInfo, resourceRequest, project, featurestore, featureStoreExpectation));
}
}
if (dto.getItems() == null) {
dto.setCount(0L);
} else {
dto.setCount((long) dto.getItems().size());
}
return dto;
}
use of io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.FeatureStoreExpectation in project hopsworks by logicalclocks.
the class FeatureStoreExpectationsResource method createExpectation.
@ApiOperation(value = "Create feature store expectation.", response = ExpectationDTO.class)
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response createExpectation(Expectation expectation, @Context SecurityContext sc, @Context UriInfo uriInfo) throws FeaturestoreException {
// Workaround to ignore the list initialized from a json like {legalValues: null}
if (expectation.getRules() != null && !expectation.getRules().isEmpty()) {
expectation.getRules().stream().filter(rule -> rule.getLegalValues() != null && rule.getLegalValues().size() == 1 && rule.getLegalValues().get(0) == null).forEach(rule -> rule.setLegalValues(null));
}
FeatureStoreExpectation featureStoreExpectation = featureGroupValidationsController.createOrUpdateExpectation(featurestore, new io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.Expectation(expectation.getName(), expectation.getDescription(), expectation.getFeatures(), expectation.getRules()));
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.EXPECTATIONS);
ExpectationDTO dto = featureStoreExpectationsBuilder.build(uriInfo, resourceRequest, project, featurestore, featureStoreExpectation);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.FeatureStoreExpectation in project hopsworks by logicalclocks.
the class FeatureStoreExpectationsResource method get.
@ApiOperation(value = "Fetch a specific data validation rule", response = ExpectationDTO.class)
@GET
@Path("/{name}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response get(@ApiParam(value = "name of the expectation", required = true) @PathParam("name") String name, @BeanParam FeatureStoreExpectationsBeanParam featureStoreExpectationsBeanParam, @Context SecurityContext sc, @Context UriInfo uriInfo) throws FeaturestoreException {
FeatureStoreExpectation featureStoreExpectation = featureGroupValidationsController.getFeatureStoreExpectation(featurestore, name);
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.EXPECTATIONS);
resourceRequest.setExpansions(featureStoreExpectationsBeanParam.getExpansions().getResources());
resourceRequest.setField(featureStoreExpectationsBeanParam.getFieldSet());
ExpectationDTO dto = featureStoreExpectationsBuilder.build(uriInfo, resourceRequest, project, featurestore, featureStoreExpectation);
return Response.ok().entity(dto).build();
}
Aggregations