Search in sources :

Example 1 with FeatureView

use of io.hops.hopsworks.persistence.entity.featurestore.featureview.FeatureView in project hopsworks by logicalclocks.

the class TrainingDatasetController method collectFeatures.

// Here we need to pass the list of training dataset joins so that we can rebuild the aliases.
// and handle correctly the case in which a feature group is joined with itself.
public List<TrainingDatasetFeature> collectFeatures(Query query, List<TrainingDatasetFeatureDTO> featureDTOs, TrainingDataset trainingDataset, FeatureView featureView, int featureIndex, List<TrainingDatasetJoin> tdJoins, int joinIndex) throws FeaturestoreException {
    List<TrainingDatasetFeature> features = new ArrayList<>();
    boolean isLabel = false;
    TransformationFunction transformationFunction = null;
    for (Feature f : query.getFeatures()) {
        if (featureDTOs != null && !featureDTOs.isEmpty()) {
            // identify if feature is label
            isLabel = featureDTOs.stream().anyMatch(dto -> f.getName().equals(dto.getName()) && dto.getLabel());
            // get transformation function for this feature
            transformationFunction = getTransformationFunction(f, featureDTOs);
        }
        features.add(trainingDataset != null ? new TrainingDatasetFeature(trainingDataset, tdJoins.get(joinIndex), query.getFeaturegroup(), f.getName(), f.getType(), featureIndex++, isLabel, transformationFunction) : new TrainingDatasetFeature(featureView, tdJoins.get(joinIndex), query.getFeaturegroup(), f.getName(), f.getType(), featureIndex++, isLabel, transformationFunction));
    }
    if (query.getJoins() != null) {
        for (Join join : query.getJoins()) {
            joinIndex++;
            List<TrainingDatasetFeature> joinFeatures = collectFeatures(join.getRightQuery(), featureDTOs, trainingDataset, featureView, featureIndex, tdJoins, joinIndex);
            features.addAll(joinFeatures);
            featureIndex += joinFeatures.size();
        }
    }
    return features;
}
Also used : TrainingDatasetFilter(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDatasetFilter) FeaturegroupType(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.FeaturegroupType) Date(java.util.Date) Feature(io.hops.hopsworks.common.featurestore.query.Feature) HopsfsTrainingDatasetController(io.hops.hopsworks.common.featurestore.trainingdatasets.hopsfs.HopsfsTrainingDatasetController) HopsFSProvenanceController(io.hops.hopsworks.common.provenance.core.HopsFSProvenanceController) Settings(io.hops.hopsworks.common.util.Settings) TransactionAttributeType(javax.ejb.TransactionAttributeType) Map(java.util.Map) FilterValue(io.hops.hopsworks.common.featurestore.query.filter.FilterValue) FeatureView(io.hops.hopsworks.persistence.entity.featurestore.featureview.FeatureView) TrainingDataset(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDataset) TrainingDatasetSplit(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.split.TrainingDatasetSplit) Utils(io.hops.hopsworks.common.hdfs.Utils) StatisticsConfig(io.hops.hopsworks.persistence.entity.featurestore.statistics.StatisticsConfig) JoinType(org.apache.calcite.sql.JoinType) Stateless(javax.ejb.Stateless) TransformationFunctionFacade(io.hops.hopsworks.common.featurestore.transformationFunction.TransformationFunctionFacade) HopsfsTrainingDatasetFacade(io.hops.hopsworks.common.featurestore.trainingdatasets.hopsfs.HopsfsTrainingDatasetFacade) Collection(java.util.Collection) TrainingDatasetFeatureDTO(io.hops.hopsworks.common.featurestore.feature.TrainingDatasetFeatureDTO) Featuregroup(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.Featuregroup) RESTCodes(io.hops.hopsworks.restutils.RESTCodes) Join(io.hops.hopsworks.common.featurestore.query.join.Join) StatisticColumnController(io.hops.hopsworks.common.featurestore.statistics.columns.StatisticColumnController) FeaturestoreConnectorFacade(io.hops.hopsworks.common.featurestore.storageconnectors.FeaturestoreConnectorFacade) Collectors(java.util.stream.Collectors) QueryController(io.hops.hopsworks.common.featurestore.query.QueryController) SqlFilterLogic(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.SqlFilterLogic) TransformationFunction(io.hops.hopsworks.persistence.entity.featurestore.transformationFunction.TransformationFunction) List(java.util.List) FeaturestoreFacade(io.hops.hopsworks.common.featurestore.FeaturestoreFacade) ExternalTrainingDatasetController(io.hops.hopsworks.common.featurestore.trainingdatasets.external.ExternalTrainingDatasetController) FeaturestoreUtils(io.hops.hopsworks.common.featurestore.utils.FeaturestoreUtils) Optional(java.util.Optional) FeaturestoreConnector(io.hops.hopsworks.persistence.entity.featurestore.storageconnector.FeaturestoreConnector) DistributedFsService(io.hops.hopsworks.common.hdfs.DistributedFsService) InodeController(io.hops.hopsworks.common.hdfs.inode.InodeController) DistributedFileSystemOps(io.hops.hopsworks.common.hdfs.DistributedFileSystemOps) TrainingDatasetJoinCondition(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDatasetJoinCondition) FeaturestoreConnectorType(io.hops.hopsworks.persistence.entity.featurestore.storageconnector.FeaturestoreConnectorType) HashMap(java.util.HashMap) FeaturestoreActivityMeta(io.hops.hopsworks.persistence.entity.featurestore.activity.FeaturestoreActivityMeta) Streams(com.logicalclocks.shaded.com.google.common.collect.Streams) OnlineFeaturestoreController(io.hops.hopsworks.common.featurestore.online.OnlineFeaturestoreController) Project(io.hops.hopsworks.persistence.entity.project.Project) TrainingDatasetFilterCondition(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDatasetFilterCondition) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HopsfsTrainingDataset(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.hopsfs.HopsfsTrainingDataset) FeaturestoreException(io.hops.hopsworks.exceptions.FeaturestoreException) FeaturestoreActivityFacade(io.hops.hopsworks.common.featurestore.activity.FeaturestoreActivityFacade) PitJoinController(io.hops.hopsworks.common.featurestore.query.pit.PitJoinController) TransactionAttribute(javax.ejb.TransactionAttribute) HdfsUsersController(io.hops.hopsworks.common.hdfs.HdfsUsersController) OnlineFeaturegroupController(io.hops.hopsworks.common.featurestore.featuregroup.online.OnlineFeaturegroupController) Query(io.hops.hopsworks.common.featurestore.query.Query) Filter(io.hops.hopsworks.common.featurestore.query.filter.Filter) TrainingDatasetType(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDatasetType) Inode(io.hops.hopsworks.persistence.entity.hdfs.inode.Inode) ProvenanceException(io.hops.hopsworks.exceptions.ProvenanceException) EJB(javax.ejb.EJB) TrainingDatasetFeature(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDatasetFeature) StatisticsController(io.hops.hopsworks.common.featurestore.statistics.StatisticsController) ExternalTrainingDataset(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.external.ExternalTrainingDataset) IOException(java.io.IOException) Featurestore(io.hops.hopsworks.persistence.entity.featurestore.Featurestore) FeaturegroupController(io.hops.hopsworks.common.featurestore.featuregroup.FeaturegroupController) ServiceException(io.hops.hopsworks.exceptions.ServiceException) TimeTravelFormat(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.cached.TimeTravelFormat) TrainingDatasetJoin(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDatasetJoin) QueryDTO(io.hops.hopsworks.common.featurestore.query.QueryDTO) StatisticColumn(io.hops.hopsworks.persistence.entity.featurestore.statistics.StatisticColumn) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) FilterLogic(io.hops.hopsworks.common.featurestore.query.filter.FilterLogic) Users(io.hops.hopsworks.persistence.entity.user.Users) Comparator(java.util.Comparator) FeaturegroupDTO(io.hops.hopsworks.common.featurestore.featuregroup.FeaturegroupDTO) TrainingDatasetFeature(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDatasetFeature) ArrayList(java.util.ArrayList) Join(io.hops.hopsworks.common.featurestore.query.join.Join) TrainingDatasetJoin(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDatasetJoin) TransformationFunction(io.hops.hopsworks.persistence.entity.featurestore.transformationFunction.TransformationFunction) Feature(io.hops.hopsworks.common.featurestore.query.Feature) TrainingDatasetFeature(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDatasetFeature)

Example 2 with FeatureView

use of io.hops.hopsworks.persistence.entity.featurestore.featureview.FeatureView in project hopsworks by logicalclocks.

the class FeatureViewBuilder method build.

public FeatureViewDTO build(List<FeatureView> featureViews, ResourceRequest resourceRequest, Project project, Users user, UriInfo uriInfo) throws FeaturestoreException, ServiceException, IOException, MetadataException, DatasetException, SchematizedTagException {
    FeatureViewDTO featureViewDTO = new FeatureViewDTO();
    featureViewDTO.setHref(uriInfo.getRequestUri());
    if (featureViews.size() == 1) {
        return buildSingle(featureViews.get(0), resourceRequest, project, user, uriInfo);
    }
    for (FeatureView featureView : featureViews) {
        FeatureViewDTO featureViewItem = buildSingle(featureView, resourceRequest, project, user, uriInfo);
        featureViewItem.setHref(uriInfo.getRequestUriBuilder().path("version").path(featureView.getVersion().toString()).build());
        featureViewDTO.addItem(featureViewItem);
    }
    if (featureViews.size() > 1) {
        featureViewDTO.setCount(Long.valueOf(featureViews.size()));
    }
    return featureViewDTO;
}
Also used : FeatureViewDTO(io.hops.hopsworks.common.featurestore.featureview.FeatureViewDTO) FeatureView(io.hops.hopsworks.persistence.entity.featurestore.featureview.FeatureView)

Example 3 with FeatureView

use of io.hops.hopsworks.persistence.entity.featurestore.featureview.FeatureView in project hopsworks by logicalclocks.

the class FeatureViewResource method create.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.FEATURESTORE }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiOperation(value = "Create Feature View metadata.", response = FeatureViewDTO.class)
public Response create(@Context SecurityContext sc, @Context HttpServletRequest req, FeatureViewDTO featureViewDTO) throws FeaturestoreException {
    Users user = jWTHelper.getUserPrincipal(sc);
    FeatureView featureView = featureViewController.convertFromDTO(project, featurestore, user, featureViewDTO);
    featureView = featureViewController.createFeatureView(featureView, featurestore);
    activityFacade.persistActivity(ActivityFacade.CREATED_FEATURE_VIEW + featureView.getName(), project, user, ActivityFlag.SERVICE);
    return Response.ok().entity(featureViewBuilder.convertToDTO(featureView)).build();
}
Also used : FeatureView(io.hops.hopsworks.persistence.entity.featurestore.featureview.FeatureView) Users(io.hops.hopsworks.persistence.entity.user.Users) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) 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)

Example 4 with FeatureView

use of io.hops.hopsworks.persistence.entity.featurestore.featureview.FeatureView in project hopsworks by logicalclocks.

the class FeatureViewResource method getByName.

@GET
@Path("/{name: [a-z0-9_]*(?=[a-z])[a-z0-9_]+}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.FEATURESTORE }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiOperation(value = "Get Feature View metadata by name.", response = FeatureViewDTO.class)
public Response getByName(@Context SecurityContext sc, @Context HttpServletRequest req, @Context UriInfo uriInfo, @BeanParam FeatureViewBeanParam param, @ApiParam(value = "Name of the feature view", required = true) @PathParam("name") String name) throws FeaturestoreException, ServiceException, IOException, MetadataException, DatasetException, SchematizedTagException {
    Users user = jWTHelper.getUserPrincipal(sc);
    ResourceRequest resourceRequest = makeResourceRequest(param);
    List<FeatureView> featureViews = featureViewController.getByNameAndFeatureStore(name, featurestore, resourceRequest);
    return Response.ok().entity(featureViewBuilder.build(featureViews, resourceRequest, project, user, uriInfo)).build();
}
Also used : FeatureView(io.hops.hopsworks.persistence.entity.featurestore.featureview.FeatureView) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) 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)

Example 5 with FeatureView

use of io.hops.hopsworks.persistence.entity.featurestore.featureview.FeatureView in project hopsworks by logicalclocks.

the class FeatureViewController method convertFromDTO.

public FeatureView convertFromDTO(Project project, Featurestore featurestore, Users user, FeatureViewDTO featureViewDTO) throws FeaturestoreException {
    featureViewInputValidator.validate(featureViewDTO, project, user);
    FeatureView featureView = new FeatureView();
    featureView.setName(featureViewDTO.getName());
    featureView.setFeaturestore(featurestore);
    featureView.setCreated(featureViewDTO.getCreated() == null ? new Date() : featureViewDTO.getCreated());
    featureView.setCreator(user);
    featureView.setVersion(featureViewDTO.getVersion());
    featureView.setDescription(featureViewDTO.getDescription());
    setQuery(project, user, featureViewDTO.getQuery(), featureView, featureViewDTO.getFeatures());
    return featureView;
}
Also used : FeatureView(io.hops.hopsworks.persistence.entity.featurestore.featureview.FeatureView) Date(java.util.Date)

Aggregations

FeatureView (io.hops.hopsworks.persistence.entity.featurestore.featureview.FeatureView)11 Users (io.hops.hopsworks.persistence.entity.user.Users)6 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)4 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)4 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)4 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)4 ApiOperation (io.swagger.annotations.ApiOperation)4 Produces (javax.ws.rs.Produces)4 Date (java.util.Date)3 TrainingDatasetFeatureDTO (io.hops.hopsworks.common.featurestore.feature.TrainingDatasetFeatureDTO)2 FeaturegroupController (io.hops.hopsworks.common.featurestore.featuregroup.FeaturegroupController)2 FeatureViewDTO (io.hops.hopsworks.common.featurestore.featureview.FeatureViewDTO)2 OnlineFeaturestoreController (io.hops.hopsworks.common.featurestore.online.OnlineFeaturestoreController)2 Feature (io.hops.hopsworks.common.featurestore.query.Feature)2 Query (io.hops.hopsworks.common.featurestore.query.Query)2 QueryController (io.hops.hopsworks.common.featurestore.query.QueryController)2 QueryDTO (io.hops.hopsworks.common.featurestore.query.QueryDTO)2 Join (io.hops.hopsworks.common.featurestore.query.join.Join)2 PitJoinController (io.hops.hopsworks.common.featurestore.query.pit.PitJoinController)2 TransformationFunctionFacade (io.hops.hopsworks.common.featurestore.transformationFunction.TransformationFunctionFacade)2