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;
}
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;
}
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();
}
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();
}
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;
}
Aggregations