Search in sources :

Example 6 with FeatureStoreExpectation

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();
}
Also used : FeatureGroupExpectation(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.FeatureGroupExpectation) FeatureStoreExpectation(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.FeatureStoreExpectation) FeaturestoreException(io.hops.hopsworks.exceptions.FeaturestoreException)

Example 7 with FeatureStoreExpectation

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)));
}
Also used : FeatureGroupExpectation(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.FeatureGroupExpectation) FeatureStoreExpectation(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.FeatureStoreExpectation) FeaturestoreException(io.hops.hopsworks.exceptions.FeaturestoreException)

Example 8 with FeatureStoreExpectation

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;
}
Also used : AbstractFacade(io.hops.hopsworks.common.dao.AbstractFacade) FeatureStoreExpectation(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.FeatureStoreExpectation) ExpectationDTO(io.hops.hopsworks.api.featurestore.datavalidation.expectations.ExpectationDTO)

Example 9 with FeatureStoreExpectation

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();
}
Also used : PathParam(javax.ws.rs.PathParam) Expectation(io.hops.hopsworks.common.featurestore.datavalidation.Expectation) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) ApiParam(io.swagger.annotations.ApiParam) ExpectationDTO(io.hops.hopsworks.api.featurestore.datavalidation.expectations.ExpectationDTO) Project(io.hops.hopsworks.persistence.entity.project.Project) FeatureGroupValidationsController(io.hops.hopsworks.common.featurestore.datavalidation.FeatureGroupValidationsController) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) ApiOperation(io.swagger.annotations.ApiOperation) FeaturestoreException(io.hops.hopsworks.exceptions.FeaturestoreException) MediaType(javax.ws.rs.core.MediaType) TransactionAttributeType(javax.ejb.TransactionAttributeType) Consumes(javax.ws.rs.Consumes) FeaturestoreController(io.hops.hopsworks.common.featurestore.FeaturestoreController) TransactionAttribute(javax.ejb.TransactionAttribute) ApiScope(io.hops.hopsworks.persistence.entity.user.security.apiKey.ApiScope) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) Api(io.swagger.annotations.Api) FeaturestoreDTO(io.hops.hopsworks.common.featurestore.FeaturestoreDTO) EJB(javax.ejb.EJB) DELETE(javax.ws.rs.DELETE) Audience(io.hops.hopsworks.api.filter.Audience) Context(javax.ws.rs.core.Context) Pagination(io.hops.hopsworks.api.util.Pagination) Featurestore(io.hops.hopsworks.persistence.entity.featurestore.Featurestore) BeanParam(javax.ws.rs.BeanParam) Response(javax.ws.rs.core.Response) RequestScoped(javax.enterprise.context.RequestScoped) FeatureStoreExpectation(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.FeatureStoreExpectation) PUT(javax.ws.rs.PUT) UriInfo(javax.ws.rs.core.UriInfo) FeatureStoreExpectation(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.FeatureStoreExpectation) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) ExpectationDTO(io.hops.hopsworks.api.featurestore.datavalidation.expectations.ExpectationDTO) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) PUT(javax.ws.rs.PUT)

Example 10 with FeatureStoreExpectation

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();
}
Also used : FeatureStoreExpectation(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.FeatureStoreExpectation) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) ExpectationDTO(io.hops.hopsworks.api.featurestore.datavalidation.expectations.ExpectationDTO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Aggregations

FeatureStoreExpectation (io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.FeatureStoreExpectation)10 FeaturestoreException (io.hops.hopsworks.exceptions.FeaturestoreException)5 FeatureGroupExpectation (io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.FeatureGroupExpectation)4 ExpectationDTO (io.hops.hopsworks.api.featurestore.datavalidation.expectations.ExpectationDTO)3 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)2 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)2 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)2 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)2 ValidationRule (io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.ValidationRule)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Audience (io.hops.hopsworks.api.filter.Audience)1 Pagination (io.hops.hopsworks.api.util.Pagination)1 AbstractFacade (io.hops.hopsworks.common.dao.AbstractFacade)1 FeaturestoreController (io.hops.hopsworks.common.featurestore.FeaturestoreController)1 FeaturestoreDTO (io.hops.hopsworks.common.featurestore.FeaturestoreDTO)1 Expectation (io.hops.hopsworks.common.featurestore.datavalidation.Expectation)1